View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
5    */
6   package mockit.asm.jvmConstants;
7   
8   import static mockit.asm.jvmConstants.ClassVersion.V5;
9   
10  /**
11   * Defines the JVM and ASM-specific access flags for classes, fields, methods, and method parameters.
12   */
13  public final class Access {
14      // Constants for standard JVM access flags.
15      public static final int PUBLIC = 0x0001; // class, field, method
16      @SuppressWarnings("unused")
17      public static final int PRIVATE = 0x0002; // class, field, method
18      public static final int PROTECTED = 0x0004; // class, field, method
19      public static final int STATIC = 0x0008; // field, method
20      public static final int FINAL = 0x0010; // class, field, method, parameter
21      public static final int SUPER = 0x0020; // class (also, a SYNCHRONIZED method)
22      public static final int BRIDGE = 0x0040; // method (also, a VOLATILE field)
23      public static final int VARARGS = 0x0080; // method (also, a TRANSIENT field)
24      public static final int NATIVE = 0x0100; // method
25      public static final int INTERFACE = 0x0200; // class
26      public static final int ABSTRACT = 0x0400; // class, method
27      public static final int SYNTHETIC = 0x1000; // class, field, method, parameter
28      public static final int ANNOTATION = 0x2000; // class
29      public static final int ENUM = 0x4000; // class(?) field inner
30  
31      // Constants for pseudo access flags.
32      private static final int DEPRECATED = 0x20000; // class, field, method
33      public static final int CONSTRUCTOR = 0x80000; // method
34  
35      // Other constants /////////////////////////////////////////////////////////////////////////////////////////////////
36  
37      /**
38       * To distinguish between the synthetic attribute and the synthetic access flag.
39       */
40      private static final int SYNTHETIC_ATTRIBUTE = 0x40000; // class, field, method
41  
42      /**
43       * Factor to convert from SYNTHETIC_ATTRIBUTE to SYNTHETIC.
44       */
45      private static final int TO_SYNTHETIC = SYNTHETIC_ATTRIBUTE / SYNTHETIC;
46  
47      // Helper methods //////////////////////////////////////////////////////////////////////////////////////////////////
48  
49      private Access() {
50      }
51  
52      public static boolean isDeprecated(int access) {
53          return (access & DEPRECATED) != 0;
54      }
55  
56      public static boolean isSynthetic(int access) {
57          return (access & SYNTHETIC) != 0;
58      }
59  
60      public static boolean isSynthetic(int access, int classVersion) {
61          return isSynthetic(access) && ((access & SYNTHETIC_ATTRIBUTE) != 0 || classVersion < V5);
62      }
63  
64      public static boolean isConstructor(int access) {
65          return (access & CONSTRUCTOR) != 0;
66      }
67  
68      public static int computeFlag(int access, int baseMask) {
69          int mask = baseMask | DEPRECATED | SYNTHETIC_ATTRIBUTE | (access & SYNTHETIC_ATTRIBUTE) / TO_SYNTHETIC;
70          return access & ~mask;
71      }
72  
73      public static int asDeprecated(int access) {
74          return access | DEPRECATED;
75      }
76  
77      public static int asSynthetic(int access) {
78          return access | SYNTHETIC | SYNTHETIC_ATTRIBUTE;
79      }
80  }