< prev index next >

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

Print this page
rev 53252 : imported patch 8217047


 127     final Log log;
 128 
 129     /** The symbol table. */
 130     Symtab syms;
 131 
 132     Types types;
 133 
 134     /** The name table. */
 135     final Names names;
 136 
 137     /** Access to files
 138      */
 139     private final JavaFileManager fileManager;
 140 
 141     /** Factory for diagnostics
 142      */
 143     JCDiagnostic.Factory diagFactory;
 144 
 145     DeferredCompletionFailureHandler dcfh;
 146 


 147     /**
 148      * Support for preview language features.
 149      */
 150     Preview preview;
 151 
 152     /** The current scope where type variables are entered.
 153      */
 154     protected WriteableScope typevars;
 155 
 156     private List<InterimUsesDirective> interimUses = List.nil();
 157     private List<InterimProvidesDirective> interimProvides = List.nil();
 158 
 159     /** The path name of the class file currently being read.
 160      */
 161     protected JavaFileObject currentClassFile = null;
 162 
 163     /** The class or method currently being read.
 164      */
 165     protected Symbol currentOwner = null;
 166 


 247     /** Get the ClassReader instance for this invocation. */
 248     public static ClassReader instance(Context context) {
 249         ClassReader instance = context.get(classReaderKey);
 250         if (instance == null)
 251             instance = new ClassReader(context);
 252         return instance;
 253     }
 254 
 255     /** Construct a new class reader. */
 256     protected ClassReader(Context context) {
 257         context.put(classReaderKey, this);
 258         annotate = Annotate.instance(context);
 259         names = Names.instance(context);
 260         syms = Symtab.instance(context);
 261         types = Types.instance(context);
 262         fileManager = context.get(JavaFileManager.class);
 263         if (fileManager == null)
 264             throw new AssertionError("FileManager initialization error");
 265         diagFactory = JCDiagnostic.Factory.instance(context);
 266         dcfh = DeferredCompletionFailureHandler.instance(context);

 267 
 268         log = Log.instance(context);
 269 
 270         Options options = Options.instance(context);
 271         verbose         = options.isSet(Option.VERBOSE);
 272 
 273         Source source = Source.instance(context);
 274         preview = Preview.instance(context);
 275         allowModules     = Feature.MODULES.allowedInSource(source);
 276 
 277         saveParameterNames = options.isSet(PARAMETERS);
 278 
 279         profile = Profile.instance(context);
 280 
 281         typevars = WriteableScope.create(syms.noSymbol);
 282 
 283         lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
 284 
 285         initAttributeReaders();
 286     }


2536                 // we never strip this$n
2537                 if (!currentOwner.name.isEmpty())
2538                     firstParam += 1;
2539             }
2540 
2541             if (sym.type != jvmType) {
2542                 // reading the method attributes has caused the
2543                 // symbol's type to be changed. (i.e. the Signature
2544                 // attribute.)  This may happen if there are hidden
2545                 // (synthetic) parameters in the descriptor, but not
2546                 // in the Signature.  The position of these hidden
2547                 // parameters is unspecified; for now, assume they are
2548                 // at the beginning, and so skip over them. The
2549                 // primary case for this is two hidden parameters
2550                 // passed into Enum constructors.
2551                 int skip = Code.width(jvmType.getParameterTypes())
2552                         - Code.width(sym.type.getParameterTypes());
2553                 firstParam += skip;
2554             }
2555         }
2556         List<Name> paramNames = List.nil();
2557         ListBuffer<VarSymbol> params = new ListBuffer<>();
2558         int nameIndex = firstParam;
2559         int annotationIndex = 0;
2560         for (Type t: sym.type.getParameterTypes()) {
2561             Name name = parameterName(nameIndex, paramNames);
2562             paramNames = paramNames.prepend(name);
2563             VarSymbol param = new VarSymbol(PARAMETER, name, t, sym);
2564             params.append(param);
2565             if (parameterAnnotations != null) {
2566                 ParameterAnnotations annotations = parameterAnnotations[annotationIndex];
2567                 if (annotations != null && annotations.proxies != null
2568                         && !annotations.proxies.isEmpty()) {
2569                     annotate.normal(new AnnotationCompleter(param, annotations.proxies));
2570                 }
2571             }
2572             nameIndex += sawMethodParameters ? 1 : Code.width(t);
2573             annotationIndex++;
2574         }
2575         if (parameterAnnotations != null && parameterAnnotations.length != annotationIndex) {
2576             throw badClassFile("bad.runtime.invisible.param.annotations", sym);
2577         }
2578         Assert.checkNull(sym.params);
2579         sym.params = params.toList();
2580         parameterAnnotations = null;
2581         parameterNameIndices = null;
2582     }
2583 
2584 
2585     // Returns the name for the parameter at position 'index', either using
2586     // names read from the MethodParameters, or by synthesizing a name that
2587     // is not on the 'exclude' list.
2588     private Name parameterName(int index, List<Name> exclude) {


2589         if (parameterNameIndices != null && index < parameterNameIndices.length
2590                 && parameterNameIndices[index] != 0) {
2591             return readName(parameterNameIndices[index]);
2592         }

2593         String prefix = "arg";
2594         while (true) {
2595             Name argName = names.fromString(prefix + exclude.size());
2596             if (!exclude.contains(argName))
2597                 return argName;
2598             prefix += "$";
2599         }



2600     }
2601 
2602     /**
2603      * skip n bytes
2604      */
2605     void skipBytes(int n) {
2606         bp = bp + n;
2607     }
2608 
2609     /** Skip a field or method
2610      */
2611     void skipMember() {
2612         bp = bp + 6;
2613         char ac = nextChar();
2614         for (int i = 0; i < ac; i++) {
2615             bp = bp + 2;
2616             int attrLen = nextInt();
2617             bp = bp + attrLen;
2618         }
2619     }




 127     final Log log;
 128 
 129     /** The symbol table. */
 130     Symtab syms;
 131 
 132     Types types;
 133 
 134     /** The name table. */
 135     final Names names;
 136 
 137     /** Access to files
 138      */
 139     private final JavaFileManager fileManager;
 140 
 141     /** Factory for diagnostics
 142      */
 143     JCDiagnostic.Factory diagFactory;
 144 
 145     DeferredCompletionFailureHandler dcfh;
 146 
 147     MissingInfoHandler missingInfoHandler;
 148 
 149     /**
 150      * Support for preview language features.
 151      */
 152     Preview preview;
 153 
 154     /** The current scope where type variables are entered.
 155      */
 156     protected WriteableScope typevars;
 157 
 158     private List<InterimUsesDirective> interimUses = List.nil();
 159     private List<InterimProvidesDirective> interimProvides = List.nil();
 160 
 161     /** The path name of the class file currently being read.
 162      */
 163     protected JavaFileObject currentClassFile = null;
 164 
 165     /** The class or method currently being read.
 166      */
 167     protected Symbol currentOwner = null;
 168 


 249     /** Get the ClassReader instance for this invocation. */
 250     public static ClassReader instance(Context context) {
 251         ClassReader instance = context.get(classReaderKey);
 252         if (instance == null)
 253             instance = new ClassReader(context);
 254         return instance;
 255     }
 256 
 257     /** Construct a new class reader. */
 258     protected ClassReader(Context context) {
 259         context.put(classReaderKey, this);
 260         annotate = Annotate.instance(context);
 261         names = Names.instance(context);
 262         syms = Symtab.instance(context);
 263         types = Types.instance(context);
 264         fileManager = context.get(JavaFileManager.class);
 265         if (fileManager == null)
 266             throw new AssertionError("FileManager initialization error");
 267         diagFactory = JCDiagnostic.Factory.instance(context);
 268         dcfh = DeferredCompletionFailureHandler.instance(context);
 269         missingInfoHandler = MissingInfoHandler.instance(context);
 270 
 271         log = Log.instance(context);
 272 
 273         Options options = Options.instance(context);
 274         verbose         = options.isSet(Option.VERBOSE);
 275 
 276         Source source = Source.instance(context);
 277         preview = Preview.instance(context);
 278         allowModules     = Feature.MODULES.allowedInSource(source);
 279 
 280         saveParameterNames = options.isSet(PARAMETERS);
 281 
 282         profile = Profile.instance(context);
 283 
 284         typevars = WriteableScope.create(syms.noSymbol);
 285 
 286         lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
 287 
 288         initAttributeReaders();
 289     }


2539                 // we never strip this$n
2540                 if (!currentOwner.name.isEmpty())
2541                     firstParam += 1;
2542             }
2543 
2544             if (sym.type != jvmType) {
2545                 // reading the method attributes has caused the
2546                 // symbol's type to be changed. (i.e. the Signature
2547                 // attribute.)  This may happen if there are hidden
2548                 // (synthetic) parameters in the descriptor, but not
2549                 // in the Signature.  The position of these hidden
2550                 // parameters is unspecified; for now, assume they are
2551                 // at the beginning, and so skip over them. The
2552                 // primary case for this is two hidden parameters
2553                 // passed into Enum constructors.
2554                 int skip = Code.width(jvmType.getParameterTypes())
2555                         - Code.width(sym.type.getParameterTypes());
2556                 firstParam += skip;
2557             }
2558         }
2559         Set<Name> paramNames = new HashSet<>();
2560         ListBuffer<VarSymbol> params = new ListBuffer<>();
2561         int nameIndex = firstParam;
2562         int annotationIndex = 0;
2563         for (Type t: sym.type.getParameterTypes()) {
2564             VarSymbol param = parameter(nameIndex, t, sym, paramNames);


2565             params.append(param);
2566             if (parameterAnnotations != null) {
2567                 ParameterAnnotations annotations = parameterAnnotations[annotationIndex];
2568                 if (annotations != null && annotations.proxies != null
2569                         && !annotations.proxies.isEmpty()) {
2570                     annotate.normal(new AnnotationCompleter(param, annotations.proxies));
2571                 }
2572             }
2573             nameIndex += sawMethodParameters ? 1 : Code.width(t);
2574             annotationIndex++;
2575         }
2576         if (parameterAnnotations != null && parameterAnnotations.length != annotationIndex) {
2577             throw badClassFile("bad.runtime.invisible.param.annotations", sym);
2578         }
2579         Assert.checkNull(sym.params);
2580         sym.params = params.toList();
2581         parameterAnnotations = null;
2582         parameterNameIndices = null;
2583     }
2584 
2585 
2586     // Returns the name for the parameter at position 'index', either using
2587     // names read from the MethodParameters, or by synthesizing a name that
2588     // is not on the 'exclude' list.
2589     private VarSymbol parameter(int index, Type t, MethodSymbol owner, Set<Name> exclude) {
2590         long flags = PARAMETER;
2591         Name argName;
2592         if (parameterNameIndices != null && index < parameterNameIndices.length
2593                 && parameterNameIndices[index] != 0) {
2594             argName = readName(parameterNameIndices[index]);
2595             flags |= NAME_FILLED;
2596         } else {
2597             String prefix = "arg";
2598             while (true) {
2599                 argName = names.fromString(prefix + exclude.size());
2600                 if (!exclude.contains(argName))
2601                     break;
2602                 prefix += "$";
2603             }
2604         }
2605         exclude.add(argName);
2606         return new ParamSymbol(flags, argName, t, owner);
2607     }
2608 
2609     /**
2610      * skip n bytes
2611      */
2612     void skipBytes(int n) {
2613         bp = bp + n;
2614     }
2615 
2616     /** Skip a field or method
2617      */
2618     void skipMember() {
2619         bp = bp + 6;
2620         char ac = nextChar();
2621         for (int i = 0; i < ac; i++) {
2622             bp = bp + 2;
2623             int attrLen = nextInt();
2624             bp = bp + attrLen;
2625         }
2626     }


< prev index next >