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