129 /** The log to use for verbose output
130 */
131 final Log log;
132
133 /** The symbol table. */
134 Symtab syms;
135
136 Types types;
137
138 /** The name table. */
139 final Names names;
140
141 /** Access to files
142 */
143 private final JavaFileManager fileManager;
144
145 /** Factory for diagnostics
146 */
147 JCDiagnostic.Factory diagFactory;
148
149 /** The current scope where type variables are entered.
150 */
151 protected WriteableScope typevars;
152
153 private List<InterimUsesDirective> interimUses = List.nil();
154 private List<InterimProvidesDirective> interimProvides = List.nil();
155
156 /** The path name of the class file currently being read.
157 */
158 protected JavaFileObject currentClassFile = null;
159
160 /** The class or method currently being read.
161 */
162 protected Symbol currentOwner = null;
163
164 /** The module containing the class currently being read.
165 */
166 protected ModuleSymbol currentModule = null;
167
168 /** The buffer containing the currently read class file.
243
244 /** Get the ClassReader instance for this invocation. */
245 public static ClassReader instance(Context context) {
246 ClassReader instance = context.get(classReaderKey);
247 if (instance == null)
248 instance = new ClassReader(context);
249 return instance;
250 }
251
252 /** Construct a new class reader. */
253 protected ClassReader(Context context) {
254 context.put(classReaderKey, this);
255 annotate = Annotate.instance(context);
256 names = Names.instance(context);
257 syms = Symtab.instance(context);
258 types = Types.instance(context);
259 fileManager = context.get(JavaFileManager.class);
260 if (fileManager == null)
261 throw new AssertionError("FileManager initialization error");
262 diagFactory = JCDiagnostic.Factory.instance(context);
263
264 log = Log.instance(context);
265
266 Options options = Options.instance(context);
267 verbose = options.isSet(Option.VERBOSE);
268
269 Source source = Source.instance(context);
270 allowSimplifiedVarargs = Feature.SIMPLIFIED_VARARGS.allowedInSource(source);
271 allowModules = Feature.MODULES.allowedInSource(source);
272
273 saveParameterNames = options.isSet(PARAMETERS);
274
275 profile = Profile.instance(context);
276
277 typevars = WriteableScope.create(syms.noSymbol);
278
279 lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
280
281 initAttributeReaders();
282 }
283
284 /** Add member to class unless it is synthetic.
285 */
286 private void enterMember(ClassSymbol c, Symbol sym) {
287 // Synthetic members are not entered -- reason lost to history (optimization?).
288 // Lambda methods must be entered because they may have inner classes (which reference them)
289 if ((sym.flags_field & (SYNTHETIC|BRIDGE)) != SYNTHETIC || sym.name.startsWith(names.lambda))
290 c.members_field.enter(sym);
291 }
292
293 /************************************************************************
294 * Error Diagnoses
295 ***********************************************************************/
296
297 public ClassFinder.BadClassFile badClassFile(String key, Object... args) {
298 return new ClassFinder.BadClassFile (
299 currentOwner.enclClass(),
300 currentClassFile,
301 diagFactory.fragment(key, args),
302 diagFactory);
303 }
304
305 public ClassFinder.BadEnclosingMethodAttr badEnclosingMethod(Symbol sym) {
306 return new ClassFinder.BadEnclosingMethodAttr (
307 currentOwner.enclClass(),
308 currentClassFile,
309 diagFactory.fragment(Fragments.BadEnclosingMethod(sym)),
310 diagFactory);
311 }
312
313 /************************************************************************
314 * Buffer Access
315 ***********************************************************************/
316
317 /** Read a character.
318 */
319 char nextChar() {
320 return (char)(((buf[bp++] & 0xFF) << 8) + (buf[bp++] & 0xFF));
321 }
322
323 /** Read a byte.
324 */
325 int nextByte() {
326 return buf[bp++] & 0xFF;
327 }
328
329 /** Read an integer.
330 */
2646 }
2647
2648 /** Read contents of a given class symbol `c'. Both external and internal
2649 * versions of an inner class are read.
2650 */
2651 void readClass(ClassSymbol c) {
2652 ClassType ct = (ClassType)c.type;
2653
2654 // allocate scope for members
2655 c.members_field = WriteableScope.create(c);
2656
2657 // prepare type variable table
2658 typevars = typevars.dup(currentOwner);
2659 if (ct.getEnclosingType().hasTag(CLASS))
2660 enterTypevars(c.owner, ct.getEnclosingType());
2661
2662 // read flags, or skip if this is an inner class
2663 long f = nextChar();
2664 long flags = adjustClassFlags(f);
2665 if ((flags & MODULE) == 0) {
2666 if (c.owner.kind == PCK) c.flags_field = flags;
2667 // read own class name and check that it matches
2668 currentModule = c.packge().modle;
2669 ClassSymbol self = readClassSymbol(nextChar());
2670 if (c != self) {
2671 throw badClassFile("class.file.wrong.class",
2672 self.flatname);
2673 }
2674 } else {
2675 if (majorVersion < Version.V53.major) {
2676 throw badClassFile("anachronistic.module.info",
2677 Integer.toString(majorVersion),
2678 Integer.toString(minorVersion));
2679 }
2680 c.flags_field = flags;
2681 currentModule = (ModuleSymbol) c.owner;
2682 int this_class = nextChar();
2683 // temp, no check on this_class
2684 }
2685
2686 // class attributes must be read before class
3048 this.repeatable = repeatable;
3049 }
3050
3051 @Override
3052 public void complete(ClassSymbol sym) {
3053 Assert.check(proxyOn == sym);
3054 Attribute.Compound theTarget = null, theRepeatable = null;
3055 AnnotationDeproxy deproxy;
3056
3057 try {
3058 if (target != null) {
3059 deproxy = new AnnotationDeproxy(proxyOn);
3060 theTarget = deproxy.deproxyCompound(target);
3061 }
3062
3063 if (repeatable != null) {
3064 deproxy = new AnnotationDeproxy(proxyOn);
3065 theRepeatable = deproxy.deproxyCompound(repeatable);
3066 }
3067 } catch (Exception e) {
3068 throw new CompletionFailure(sym, ClassReader.this.diagFactory.fragment(Fragments.ExceptionMessage(e.getMessage())));
3069 }
3070
3071 sym.getAnnotationTypeMetadata().setTarget(theTarget);
3072 sym.getAnnotationTypeMetadata().setRepeatable(theRepeatable);
3073 }
3074 }
3075
3076 private class ProxyType extends Type {
3077
3078 private final byte[] content;
3079
3080 public ProxyType(byte[] content) {
3081 super(syms.noSymbol, TypeMetadata.EMPTY);
3082 this.content = content;
3083 }
3084
3085 @Override
3086 public TypeTag getTag() {
3087 return TypeTag.NONE;
3088 }
|
129 /** The log to use for verbose output
130 */
131 final Log log;
132
133 /** The symbol table. */
134 Symtab syms;
135
136 Types types;
137
138 /** The name table. */
139 final Names names;
140
141 /** Access to files
142 */
143 private final JavaFileManager fileManager;
144
145 /** Factory for diagnostics
146 */
147 JCDiagnostic.Factory diagFactory;
148
149 DeferredCompletionFailureHandler dcfh;
150
151 /** The current scope where type variables are entered.
152 */
153 protected WriteableScope typevars;
154
155 private List<InterimUsesDirective> interimUses = List.nil();
156 private List<InterimProvidesDirective> interimProvides = List.nil();
157
158 /** The path name of the class file currently being read.
159 */
160 protected JavaFileObject currentClassFile = null;
161
162 /** The class or method currently being read.
163 */
164 protected Symbol currentOwner = null;
165
166 /** The module containing the class currently being read.
167 */
168 protected ModuleSymbol currentModule = null;
169
170 /** The buffer containing the currently read class file.
245
246 /** Get the ClassReader instance for this invocation. */
247 public static ClassReader instance(Context context) {
248 ClassReader instance = context.get(classReaderKey);
249 if (instance == null)
250 instance = new ClassReader(context);
251 return instance;
252 }
253
254 /** Construct a new class reader. */
255 protected ClassReader(Context context) {
256 context.put(classReaderKey, this);
257 annotate = Annotate.instance(context);
258 names = Names.instance(context);
259 syms = Symtab.instance(context);
260 types = Types.instance(context);
261 fileManager = context.get(JavaFileManager.class);
262 if (fileManager == null)
263 throw new AssertionError("FileManager initialization error");
264 diagFactory = JCDiagnostic.Factory.instance(context);
265 dcfh = DeferredCompletionFailureHandler.instance(context);
266
267 log = Log.instance(context);
268
269 Options options = Options.instance(context);
270 verbose = options.isSet(Option.VERBOSE);
271
272 Source source = Source.instance(context);
273 allowSimplifiedVarargs = Feature.SIMPLIFIED_VARARGS.allowedInSource(source);
274 allowModules = Feature.MODULES.allowedInSource(source);
275
276 saveParameterNames = options.isSet(PARAMETERS);
277
278 profile = Profile.instance(context);
279
280 typevars = WriteableScope.create(syms.noSymbol);
281
282 lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
283
284 initAttributeReaders();
285 }
286
287 /** Add member to class unless it is synthetic.
288 */
289 private void enterMember(ClassSymbol c, Symbol sym) {
290 // Synthetic members are not entered -- reason lost to history (optimization?).
291 // Lambda methods must be entered because they may have inner classes (which reference them)
292 if ((sym.flags_field & (SYNTHETIC|BRIDGE)) != SYNTHETIC || sym.name.startsWith(names.lambda))
293 c.members_field.enter(sym);
294 }
295
296 /************************************************************************
297 * Error Diagnoses
298 ***********************************************************************/
299
300 public ClassFinder.BadClassFile badClassFile(String key, Object... args) {
301 return new ClassFinder.BadClassFile (
302 currentOwner.enclClass(),
303 currentClassFile,
304 diagFactory.fragment(key, args),
305 diagFactory,
306 dcfh);
307 }
308
309 public ClassFinder.BadEnclosingMethodAttr badEnclosingMethod(Symbol sym) {
310 return new ClassFinder.BadEnclosingMethodAttr (
311 currentOwner.enclClass(),
312 currentClassFile,
313 diagFactory.fragment(Fragments.BadEnclosingMethod(sym)),
314 diagFactory,
315 dcfh);
316 }
317
318 /************************************************************************
319 * Buffer Access
320 ***********************************************************************/
321
322 /** Read a character.
323 */
324 char nextChar() {
325 return (char)(((buf[bp++] & 0xFF) << 8) + (buf[bp++] & 0xFF));
326 }
327
328 /** Read a byte.
329 */
330 int nextByte() {
331 return buf[bp++] & 0xFF;
332 }
333
334 /** Read an integer.
335 */
2651 }
2652
2653 /** Read contents of a given class symbol `c'. Both external and internal
2654 * versions of an inner class are read.
2655 */
2656 void readClass(ClassSymbol c) {
2657 ClassType ct = (ClassType)c.type;
2658
2659 // allocate scope for members
2660 c.members_field = WriteableScope.create(c);
2661
2662 // prepare type variable table
2663 typevars = typevars.dup(currentOwner);
2664 if (ct.getEnclosingType().hasTag(CLASS))
2665 enterTypevars(c.owner, ct.getEnclosingType());
2666
2667 // read flags, or skip if this is an inner class
2668 long f = nextChar();
2669 long flags = adjustClassFlags(f);
2670 if ((flags & MODULE) == 0) {
2671 if (c.owner.kind == PCK || c.owner.kind == ERR) c.flags_field = flags;
2672 // read own class name and check that it matches
2673 currentModule = c.packge().modle;
2674 ClassSymbol self = readClassSymbol(nextChar());
2675 if (c != self) {
2676 throw badClassFile("class.file.wrong.class",
2677 self.flatname);
2678 }
2679 } else {
2680 if (majorVersion < Version.V53.major) {
2681 throw badClassFile("anachronistic.module.info",
2682 Integer.toString(majorVersion),
2683 Integer.toString(minorVersion));
2684 }
2685 c.flags_field = flags;
2686 currentModule = (ModuleSymbol) c.owner;
2687 int this_class = nextChar();
2688 // temp, no check on this_class
2689 }
2690
2691 // class attributes must be read before class
3053 this.repeatable = repeatable;
3054 }
3055
3056 @Override
3057 public void complete(ClassSymbol sym) {
3058 Assert.check(proxyOn == sym);
3059 Attribute.Compound theTarget = null, theRepeatable = null;
3060 AnnotationDeproxy deproxy;
3061
3062 try {
3063 if (target != null) {
3064 deproxy = new AnnotationDeproxy(proxyOn);
3065 theTarget = deproxy.deproxyCompound(target);
3066 }
3067
3068 if (repeatable != null) {
3069 deproxy = new AnnotationDeproxy(proxyOn);
3070 theRepeatable = deproxy.deproxyCompound(repeatable);
3071 }
3072 } catch (Exception e) {
3073 throw new CompletionFailure(sym,
3074 ClassReader.this.diagFactory.fragment(Fragments.ExceptionMessage(e.getMessage())),
3075 dcfh);
3076 }
3077
3078 sym.getAnnotationTypeMetadata().setTarget(theTarget);
3079 sym.getAnnotationTypeMetadata().setRepeatable(theRepeatable);
3080 }
3081 }
3082
3083 private class ProxyType extends Type {
3084
3085 private final byte[] content;
3086
3087 public ProxyType(byte[] content) {
3088 super(syms.noSymbol, TypeMetadata.EMPTY);
3089 this.content = content;
3090 }
3091
3092 @Override
3093 public TypeTag getTag() {
3094 return TypeTag.NONE;
3095 }
|