< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java

Print this page




  32 /**
  33  * See JVMS, sections 4.2, 4.6, 4.7.
  34  *
  35  *  <p><b>This is NOT part of any supported API.
  36  *  If you write code that depends on this, you do so at your own risk.
  37  *  This code and its internal interfaces are subject to change or
  38  *  deletion without notice.</b>
  39  */
  40 public class AccessFlags {
  41     public static final int ACC_PUBLIC        = 0x0001; // class, inner, field, method
  42     public static final int ACC_PRIVATE       = 0x0002; //        inner, field, method
  43     public static final int ACC_PROTECTED     = 0x0004; //        inner, field, method
  44     public static final int ACC_STATIC        = 0x0008; //        inner, field, method
  45     public static final int ACC_FINAL         = 0x0010; // class, inner, field, method
  46     public static final int ACC_SUPER         = 0x0020; // class
  47     public static final int ACC_SYNCHRONIZED  = 0x0020; //                      method
  48     public static final int ACC_VOLATILE      = 0x0040; //               field
  49     public static final int ACC_BRIDGE        = 0x0040; //                      method
  50     public static final int ACC_TRANSIENT     = 0x0080; //               field
  51     public static final int ACC_VARARGS       = 0x0080; //                      method

  52     public static final int ACC_NATIVE        = 0x0100; //                      method
  53     public static final int ACC_INTERFACE     = 0x0200; // class, inner
  54     public static final int ACC_ABSTRACT      = 0x0400; // class, inner,        method
  55     public static final int ACC_STRICT        = 0x0800; //                      method
  56     public static final int ACC_SYNTHETIC     = 0x1000; // class, inner, field, method
  57     public static final int ACC_ANNOTATION    = 0x2000; // class, inner
  58     public static final int ACC_ENUM          = 0x4000; // class, inner, field
  59     public static final int ACC_MANDATED      = 0x8000; //                          method parameter
  60     public static final int ACC_MODULE        = 0x8000; // class
  61 
  62     public static enum Kind { Class, InnerClass, Field, Method}
  63 
  64     AccessFlags(ClassReader cr) throws IOException {
  65         this(cr.readUnsignedShort());
  66     }
  67 
  68     public AccessFlags(int flags) {
  69         this.flags = flags;
  70     }
  71 
  72     public AccessFlags ignore(int mask) {
  73         return new AccessFlags(flags & ~mask);
  74     }
  75 
  76     public boolean is(int mask) {
  77         return (flags & mask) != 0;
  78     }
  79 
  80     public int byteLength() {
  81         return 2;
  82     }
  83 
  84     private static final int[] classModifiers = {
  85         ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT
  86     };
  87 
  88     private static final int[] classFlags = {
  89         ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, ACC_ABSTRACT,
  90         ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE
  91     };
  92 
  93     public Set<String> getClassModifiers() {
  94         int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
  95         return getModifiers(f, classModifiers, Kind.Class);
  96     }
  97 
  98     public Set<String> getClassFlags() {
  99         return getFlags(classFlags, Kind.Class);
 100     }
 101 
 102     private static final int[] innerClassModifiers = {
 103         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
 104         ACC_ABSTRACT
 105     };
 106 
 107     private static final int[] innerClassFlags = {
 108         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER,
 109         ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM
 110     };
 111 
 112     public Set<String> getInnerClassModifiers() {
 113         int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
 114         return getModifiers(f, innerClassModifiers, Kind.InnerClass);
 115     }
 116 
 117     public Set<String> getInnerClassFlags() {
 118         return getFlags(innerClassFlags, Kind.InnerClass);
 119     }
 120 
 121     private static final int[] fieldModifiers = {
 122         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
 123         ACC_VOLATILE, ACC_TRANSIENT
 124     };
 125 
 126     private static final int[] fieldFlags = {
 127         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
 128         ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM
 129     };


 186     }
 187 
 188     private static String flagToModifier(int flag, Kind t) {
 189         switch (flag) {
 190             case ACC_PUBLIC:
 191                 return "public";
 192             case ACC_PRIVATE:
 193                 return "private";
 194             case ACC_PROTECTED:
 195                 return "protected";
 196             case ACC_STATIC:
 197                 return "static";
 198             case ACC_FINAL:
 199                 return "final";
 200             case ACC_SYNCHRONIZED:
 201                 return "synchronized";
 202             case 0x80:
 203                 return (t == Kind.Field ? "transient" : null);
 204             case ACC_VOLATILE:
 205                 return "volatile";
 206             case ACC_NATIVE:
 207                 return "native";
 208             case ACC_ABSTRACT:
 209                 return "abstract";
 210             case ACC_STRICT:
 211                 return "strictfp";
 212             case ACC_MANDATED:
 213                 return "mandated";
 214             default:
 215                 return null;
 216         }
 217     }
 218 
 219     private static String flagToName(int flag, Kind t) {
 220         switch (flag) {
 221         case ACC_PUBLIC:
 222             return "ACC_PUBLIC";
 223         case ACC_PRIVATE:
 224             return "ACC_PRIVATE";
 225         case ACC_PROTECTED:
 226             return "ACC_PROTECTED";
 227         case ACC_STATIC:
 228             return "ACC_STATIC";
 229         case ACC_FINAL:
 230             return "ACC_FINAL";
 231         case 0x20:
 232             return (t == Kind.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED");
 233         case 0x40:
 234             return (t == Kind.Field ? "ACC_VOLATILE" : "ACC_BRIDGE");
 235         case 0x80:
 236             return (t == Kind.Field ? "ACC_TRANSIENT" : "ACC_VARARGS");
 237         case ACC_NATIVE:
 238             return "ACC_NATIVE";
 239         case ACC_INTERFACE:
 240             return "ACC_INTERFACE";
 241         case ACC_ABSTRACT:
 242             return "ACC_ABSTRACT";
 243         case ACC_STRICT:
 244             return "ACC_STRICT";
 245         case ACC_SYNTHETIC:
 246             return "ACC_SYNTHETIC";
 247         case ACC_ANNOTATION:
 248             return "ACC_ANNOTATION";
 249         case ACC_ENUM:
 250             return "ACC_ENUM";
 251         case 0x8000:
 252             return (t == Kind.Class ? "ACC_MODULE" : "ACC_MANDATED");
 253         default:
 254             return null;
 255         }
 256     }
 257 
 258     public final int flags;


  32 /**
  33  * See JVMS, sections 4.2, 4.6, 4.7.
  34  *
  35  *  <p><b>This is NOT part of any supported API.
  36  *  If you write code that depends on this, you do so at your own risk.
  37  *  This code and its internal interfaces are subject to change or
  38  *  deletion without notice.</b>
  39  */
  40 public class AccessFlags {
  41     public static final int ACC_PUBLIC        = 0x0001; // class, inner, field, method
  42     public static final int ACC_PRIVATE       = 0x0002; //        inner, field, method
  43     public static final int ACC_PROTECTED     = 0x0004; //        inner, field, method
  44     public static final int ACC_STATIC        = 0x0008; //        inner, field, method
  45     public static final int ACC_FINAL         = 0x0010; // class, inner, field, method
  46     public static final int ACC_SUPER         = 0x0020; // class
  47     public static final int ACC_SYNCHRONIZED  = 0x0020; //                      method
  48     public static final int ACC_VOLATILE      = 0x0040; //               field
  49     public static final int ACC_BRIDGE        = 0x0040; //                      method
  50     public static final int ACC_TRANSIENT     = 0x0080; //               field
  51     public static final int ACC_VARARGS       = 0x0080; //                      method
  52     public static final int ACC_VALUE         = 0x0100; // class
  53     public static final int ACC_NATIVE        = 0x0100; //                      method
  54     public static final int ACC_INTERFACE     = 0x0200; // class, inner
  55     public static final int ACC_ABSTRACT      = 0x0400; // class, inner,        method
  56     public static final int ACC_STRICT        = 0x0800; //                      method
  57     public static final int ACC_SYNTHETIC     = 0x1000; // class, inner, field, method
  58     public static final int ACC_ANNOTATION    = 0x2000; // class, inner
  59     public static final int ACC_ENUM          = 0x4000; // class, inner, field
  60     public static final int ACC_MANDATED      = 0x8000; //                          method parameter
  61     public static final int ACC_MODULE        = 0x8000; // class
  62 
  63     public static enum Kind { Class, InnerClass, Field, Method}
  64 
  65     AccessFlags(ClassReader cr) throws IOException {
  66         this(cr.readUnsignedShort());
  67     }
  68 
  69     public AccessFlags(int flags) {
  70         this.flags = flags;
  71     }
  72 
  73     public AccessFlags ignore(int mask) {
  74         return new AccessFlags(flags & ~mask);
  75     }
  76 
  77     public boolean is(int mask) {
  78         return (flags & mask) != 0;
  79     }
  80 
  81     public int byteLength() {
  82         return 2;
  83     }
  84 
  85     private static final int[] classModifiers = {
  86         ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT, ACC_VALUE
  87     };
  88 
  89     private static final int[] classFlags = {
  90         ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, ACC_ABSTRACT,
  91         ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE, ACC_VALUE
  92     };
  93 
  94     public Set<String> getClassModifiers() {
  95         int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
  96         return getModifiers(f, classModifiers, Kind.Class);
  97     }
  98 
  99     public Set<String> getClassFlags() {
 100         return getFlags(classFlags, Kind.Class);
 101     }
 102 
 103     private static final int[] innerClassModifiers = {
 104         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
 105         ACC_ABSTRACT, ACC_VALUE
 106     };
 107 
 108     private static final int[] innerClassFlags = {
 109         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER,
 110         ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_VALUE
 111     };
 112 
 113     public Set<String> getInnerClassModifiers() {
 114         int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
 115         return getModifiers(f, innerClassModifiers, Kind.InnerClass);
 116     }
 117 
 118     public Set<String> getInnerClassFlags() {
 119         return getFlags(innerClassFlags, Kind.InnerClass);
 120     }
 121 
 122     private static final int[] fieldModifiers = {
 123         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
 124         ACC_VOLATILE, ACC_TRANSIENT
 125     };
 126 
 127     private static final int[] fieldFlags = {
 128         ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
 129         ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM
 130     };


 187     }
 188 
 189     private static String flagToModifier(int flag, Kind t) {
 190         switch (flag) {
 191             case ACC_PUBLIC:
 192                 return "public";
 193             case ACC_PRIVATE:
 194                 return "private";
 195             case ACC_PROTECTED:
 196                 return "protected";
 197             case ACC_STATIC:
 198                 return "static";
 199             case ACC_FINAL:
 200                 return "final";
 201             case ACC_SYNCHRONIZED:
 202                 return "synchronized";
 203             case 0x80:
 204                 return (t == Kind.Field ? "transient" : null);
 205             case ACC_VOLATILE:
 206                 return "volatile";
 207             case 0x100:
 208                 return (t == Kind.Class || t == Kind.InnerClass) ? "value" : t == Kind.Field ? "__Flattenable" : "native";
 209             case ACC_ABSTRACT:
 210                 return "abstract";
 211             case ACC_STRICT:
 212                 return "strictfp";
 213             case ACC_MANDATED:
 214                 return "mandated";
 215             default:
 216                 return null;
 217         }
 218     }
 219 
 220     private static String flagToName(int flag, Kind t) {
 221         switch (flag) {
 222         case ACC_PUBLIC:
 223             return "ACC_PUBLIC";
 224         case ACC_PRIVATE:
 225             return "ACC_PRIVATE";
 226         case ACC_PROTECTED:
 227             return "ACC_PROTECTED";
 228         case ACC_STATIC:
 229             return "ACC_STATIC";
 230         case ACC_FINAL:
 231             return "ACC_FINAL";
 232         case 0x20:
 233             return (t == Kind.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED");
 234         case 0x40:
 235             return (t == Kind.Field ? "ACC_VOLATILE" : "ACC_BRIDGE");
 236         case 0x80:
 237             return (t == Kind.Field ? "ACC_TRANSIENT" : "ACC_VARARGS");
 238         case 0x100:
 239             return (t == Kind.Class || t == Kind.InnerClass) ? "ACC_VALUE" : "ACC_NATIVE";
 240         case ACC_INTERFACE:
 241             return "ACC_INTERFACE";
 242         case ACC_ABSTRACT:
 243             return "ACC_ABSTRACT";
 244         case ACC_STRICT:
 245             return "ACC_STRICT";
 246         case ACC_SYNTHETIC:
 247             return "ACC_SYNTHETIC";
 248         case ACC_ANNOTATION:
 249             return "ACC_ANNOTATION";
 250         case ACC_ENUM:
 251             return "ACC_ENUM";
 252         case 0x8000:
 253             return (t == Kind.Class ? "ACC_MODULE" : "ACC_MANDATED");
 254         default:
 255             return null;
 256         }
 257     }
 258 
 259     public final int flags;
< prev index next >