< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java

Print this page




 217 
 218     /** Set this to false every time we start reading a method
 219      * and are saving parameter names.  Set it to true when we see
 220      * MethodParameters, if it's set when we see a LocalVariableTable,
 221      * then we ignore the parameter names from the LVT.
 222      */
 223     boolean sawMethodParameters;
 224 
 225     /**
 226      * The set of attribute names for which warnings have been generated for the current class
 227      */
 228     Set<Name> warnedAttrs = new HashSet<>();
 229 
 230     /**
 231      * The prototype @Target Attribute.Compound if this class is an annotation annotated with
 232      * @Target
 233      */
 234     CompoundAnnotationProxy target;
 235 
 236     /**
 237      * The prototype @Repetable Attribute.Compound if this class is an annotation annotated with
 238      * @Repeatable
 239      */
 240     CompoundAnnotationProxy repeatable;
 241 
 242     /** Get the ClassReader instance for this invocation. */
 243     public static ClassReader instance(Context context) {
 244         ClassReader instance = context.get(classReaderKey);
 245         if (instance == null)
 246             instance = new ClassReader(context);
 247         return instance;
 248     }
 249 
 250     /** Construct a new class reader. */
 251     protected ClassReader(Context context) {
 252         context.put(classReaderKey, this);
 253         annotate = Annotate.instance(context);
 254         names = Names.instance(context);
 255         syms = Symtab.instance(context);
 256         types = Types.instance(context);
 257         fileManager = context.get(JavaFileManager.class);


 859             new AttributeReader(names.InnerClasses, V45_3, CLASS_ATTRIBUTE) {
 860                 protected void read(Symbol sym, int attrLen) {
 861                     ClassSymbol c = (ClassSymbol) sym;
 862                     if (currentModule.module_info == c) {
 863                         //prevent entering the classes too soon:
 864                         skipInnerClasses();
 865                     } else {
 866                         readInnerClasses(c);
 867                     }
 868                 }
 869             },
 870 
 871             new AttributeReader(names.LocalVariableTable, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
 872                 protected void read(Symbol sym, int attrLen) {
 873                     int newbp = bp + attrLen;
 874                     if (saveParameterNames && !sawMethodParameters) {
 875                         // Pick up parameter names from the variable table.
 876                         // Parameter names are not explicitly identified as such,
 877                         // but all parameter name entries in the LocalVariableTable
 878                         // have a start_pc of 0.  Therefore, we record the name
 879                         // indicies of all slots with a start_pc of zero in the
 880                         // parameterNameIndicies array.
 881                         // Note that this implicitly honors the JVMS spec that
 882                         // there may be more than one LocalVariableTable, and that
 883                         // there is no specified ordering for the entries.
 884                         int numEntries = nextChar();
 885                         for (int i = 0; i < numEntries; i++) {
 886                             int start_pc = nextChar();
 887                             int length = nextChar();
 888                             int nameIndex = nextChar();
 889                             int sigIndex = nextChar();
 890                             int register = nextChar();
 891                             if (start_pc == 0) {
 892                                 // ensure array large enough
 893                                 if (register >= parameterNameIndices.length) {
 894                                     int newSize =
 895                                             Math.max(register + 1, parameterNameIndices.length + 8);
 896                                     parameterNameIndices =
 897                                             Arrays.copyOf(parameterNameIndices, newSize);
 898                                 }
 899                                 parameterNameIndices[register] = nameIndex;
 900                                 haveParameterNameIndices = true;


 981             },
 982 
 983             new AttributeReader(names.RuntimeInvisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 984                 protected void read(Symbol sym, int attrLen) {
 985                     readParameterAnnotations(sym);
 986                 }
 987             },
 988 
 989             new AttributeReader(names.RuntimeVisibleAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 990                 protected void read(Symbol sym, int attrLen) {
 991                     attachAnnotations(sym);
 992                 }
 993             },
 994 
 995             new AttributeReader(names.RuntimeVisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 996                 protected void read(Symbol sym, int attrLen) {
 997                     readParameterAnnotations(sym);
 998                 }
 999             },
1000 
1001             // additional "legacy" v49 attributes, superceded by flags
1002 
1003             new AttributeReader(names.Annotation, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1004                 protected void read(Symbol sym, int attrLen) {
1005                     sym.flags_field |= ANNOTATION;
1006                 }
1007             },
1008 
1009             new AttributeReader(names.Bridge, V49, MEMBER_ATTRIBUTE) {
1010                 protected void read(Symbol sym, int attrLen) {
1011                     sym.flags_field |= BRIDGE;
1012                 }
1013             },
1014 
1015             new AttributeReader(names.Enum, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1016                 protected void read(Symbol sym, int attrLen) {
1017                     sym.flags_field |= ENUM;
1018                 }
1019             },
1020 
1021             new AttributeReader(names.Varargs, V49, CLASS_OR_MEMBER_ATTRIBUTE) {




 217 
 218     /** Set this to false every time we start reading a method
 219      * and are saving parameter names.  Set it to true when we see
 220      * MethodParameters, if it's set when we see a LocalVariableTable,
 221      * then we ignore the parameter names from the LVT.
 222      */
 223     boolean sawMethodParameters;
 224 
 225     /**
 226      * The set of attribute names for which warnings have been generated for the current class
 227      */
 228     Set<Name> warnedAttrs = new HashSet<>();
 229 
 230     /**
 231      * The prototype @Target Attribute.Compound if this class is an annotation annotated with
 232      * @Target
 233      */
 234     CompoundAnnotationProxy target;
 235 
 236     /**
 237      * The prototype @Repeatable Attribute.Compound if this class is an annotation annotated with
 238      * @Repeatable
 239      */
 240     CompoundAnnotationProxy repeatable;
 241 
 242     /** Get the ClassReader instance for this invocation. */
 243     public static ClassReader instance(Context context) {
 244         ClassReader instance = context.get(classReaderKey);
 245         if (instance == null)
 246             instance = new ClassReader(context);
 247         return instance;
 248     }
 249 
 250     /** Construct a new class reader. */
 251     protected ClassReader(Context context) {
 252         context.put(classReaderKey, this);
 253         annotate = Annotate.instance(context);
 254         names = Names.instance(context);
 255         syms = Symtab.instance(context);
 256         types = Types.instance(context);
 257         fileManager = context.get(JavaFileManager.class);


 859             new AttributeReader(names.InnerClasses, V45_3, CLASS_ATTRIBUTE) {
 860                 protected void read(Symbol sym, int attrLen) {
 861                     ClassSymbol c = (ClassSymbol) sym;
 862                     if (currentModule.module_info == c) {
 863                         //prevent entering the classes too soon:
 864                         skipInnerClasses();
 865                     } else {
 866                         readInnerClasses(c);
 867                     }
 868                 }
 869             },
 870 
 871             new AttributeReader(names.LocalVariableTable, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
 872                 protected void read(Symbol sym, int attrLen) {
 873                     int newbp = bp + attrLen;
 874                     if (saveParameterNames && !sawMethodParameters) {
 875                         // Pick up parameter names from the variable table.
 876                         // Parameter names are not explicitly identified as such,
 877                         // but all parameter name entries in the LocalVariableTable
 878                         // have a start_pc of 0.  Therefore, we record the name
 879                         // indices of all slots with a start_pc of zero in the
 880                         // parameterNameIndices array.
 881                         // Note that this implicitly honors the JVMS spec that
 882                         // there may be more than one LocalVariableTable, and that
 883                         // there is no specified ordering for the entries.
 884                         int numEntries = nextChar();
 885                         for (int i = 0; i < numEntries; i++) {
 886                             int start_pc = nextChar();
 887                             int length = nextChar();
 888                             int nameIndex = nextChar();
 889                             int sigIndex = nextChar();
 890                             int register = nextChar();
 891                             if (start_pc == 0) {
 892                                 // ensure array large enough
 893                                 if (register >= parameterNameIndices.length) {
 894                                     int newSize =
 895                                             Math.max(register + 1, parameterNameIndices.length + 8);
 896                                     parameterNameIndices =
 897                                             Arrays.copyOf(parameterNameIndices, newSize);
 898                                 }
 899                                 parameterNameIndices[register] = nameIndex;
 900                                 haveParameterNameIndices = true;


 981             },
 982 
 983             new AttributeReader(names.RuntimeInvisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 984                 protected void read(Symbol sym, int attrLen) {
 985                     readParameterAnnotations(sym);
 986                 }
 987             },
 988 
 989             new AttributeReader(names.RuntimeVisibleAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 990                 protected void read(Symbol sym, int attrLen) {
 991                     attachAnnotations(sym);
 992                 }
 993             },
 994 
 995             new AttributeReader(names.RuntimeVisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 996                 protected void read(Symbol sym, int attrLen) {
 997                     readParameterAnnotations(sym);
 998                 }
 999             },
1000 
1001             // additional "legacy" v49 attributes, superseded by flags
1002 
1003             new AttributeReader(names.Annotation, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1004                 protected void read(Symbol sym, int attrLen) {
1005                     sym.flags_field |= ANNOTATION;
1006                 }
1007             },
1008 
1009             new AttributeReader(names.Bridge, V49, MEMBER_ATTRIBUTE) {
1010                 protected void read(Symbol sym, int attrLen) {
1011                     sym.flags_field |= BRIDGE;
1012                 }
1013             },
1014 
1015             new AttributeReader(names.Enum, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1016                 protected void read(Symbol sym, int attrLen) {
1017                     sym.flags_field |= ENUM;
1018                 }
1019             },
1020 
1021             new AttributeReader(names.Varargs, V49, CLASS_OR_MEMBER_ATTRIBUTE) {


< prev index next >