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

changeset 2007
a76c663a9cac
parent 2001
2bf4c132bf90
child 2040
2375ce96e80d
equal deleted inserted replaced
2006:044721d4d359 2007:a76c663a9cac
70 * <p><b>This is NOT part of any supported API. 70 * <p><b>This is NOT part of any supported API.
71 * If you write code that depends on this, you do so at your own risk. 71 * If you write code that depends on this, you do so at your own risk.
72 * This code and its internal interfaces are subject to change or 72 * This code and its internal interfaces are subject to change or
73 * deletion without notice.</b> 73 * deletion without notice.</b>
74 */ 74 */
75 public class ClassReader implements Completer { 75 public class ClassReader {
76 /** The context key for the class reader. */ 76 /** The context key for the class reader. */
77 protected static final Context.Key<ClassReader> classReaderKey = 77 protected static final Context.Key<ClassReader> classReaderKey =
78 new Context.Key<ClassReader>(); 78 new Context.Key<ClassReader>();
79 79
80 public static final int INITIAL_BUFFER_SIZE = 0x0fff0; 80 public static final int INITIAL_BUFFER_SIZE = 0x0fff0;
231 231
232 /** 232 /**
233 * The set of attribute names for which warnings have been generated for the current class 233 * The set of attribute names for which warnings have been generated for the current class
234 */ 234 */
235 Set<Name> warnedAttrs = new HashSet<Name>(); 235 Set<Name> warnedAttrs = new HashSet<Name>();
236
237 /**
238 * Completer that delegates to the complete-method of this class.
239 */
240 private final Completer thisCompleter = new Completer() {
241 @Override
242 public void complete(Symbol sym) throws CompletionFailure {
243 ClassReader.this.complete(sym);
244 }
245 };
246
236 247
237 /** Get the ClassReader instance for this invocation. */ 248 /** Get the ClassReader instance for this invocation. */
238 public static ClassReader instance(Context context) { 249 public static ClassReader instance(Context context) {
239 ClassReader instance = context.get(classReaderKey); 250 ClassReader instance = context.get(classReaderKey);
240 if (instance == null) 251 if (instance == null)
262 packages = new HashMap<Name, PackageSymbol>(); 273 packages = new HashMap<Name, PackageSymbol>();
263 classes = new HashMap<Name, ClassSymbol>(); 274 classes = new HashMap<Name, ClassSymbol>();
264 } 275 }
265 276
266 packages.put(names.empty, syms.rootPackage); 277 packages.put(names.empty, syms.rootPackage);
267 syms.rootPackage.completer = this; 278 syms.rootPackage.completer = thisCompleter;
268 syms.unnamedPackage.completer = this; 279 syms.unnamedPackage.completer = thisCompleter;
269 } 280 }
270 281
271 /** Construct a new class reader, optionally treated as the 282 /** Construct a new class reader, optionally treated as the
272 * definitive classreader for this invocation. 283 * definitive classreader for this invocation.
273 */ 284 */
2317 */ 2328 */
2318 public ClassSymbol defineClass(Name name, Symbol owner) { 2329 public ClassSymbol defineClass(Name name, Symbol owner) {
2319 ClassSymbol c = new ClassSymbol(0, name, owner); 2330 ClassSymbol c = new ClassSymbol(0, name, owner);
2320 if (owner.kind == PCK) 2331 if (owner.kind == PCK)
2321 Assert.checkNull(classes.get(c.flatname), c); 2332 Assert.checkNull(classes.get(c.flatname), c);
2322 c.completer = this; 2333 c.completer = thisCompleter;
2323 return c; 2334 return c;
2324 } 2335 }
2325 2336
2326 /** Create a new toplevel or member class symbol with given name 2337 /** Create a new toplevel or member class symbol with given name
2327 * and owner and enter in `classes' unless already there. 2338 * and owner and enter in `classes' unless already there.
2387 private boolean suppressFlush = false; 2398 private boolean suppressFlush = false;
2388 2399
2389 /** Completion for classes to be loaded. Before a class is loaded 2400 /** Completion for classes to be loaded. Before a class is loaded
2390 * we make sure its enclosing class (if any) is loaded. 2401 * we make sure its enclosing class (if any) is loaded.
2391 */ 2402 */
2392 public void complete(Symbol sym) throws CompletionFailure { 2403 private void complete(Symbol sym) throws CompletionFailure {
2393 if (sym.kind == TYP) { 2404 if (sym.kind == TYP) {
2394 ClassSymbol c = (ClassSymbol)sym; 2405 ClassSymbol c = (ClassSymbol)sym;
2395 c.members_field = new Scope.ErrorScope(c); // make sure it's always defined 2406 c.members_field = new Scope.ErrorScope(c); // make sure it's always defined
2396 boolean saveSuppressFlush = suppressFlush; 2407 boolean saveSuppressFlush = suppressFlush;
2397 suppressFlush = true; 2408 suppressFlush = true;
2608 if (p == null) { 2619 if (p == null) {
2609 Assert.check(!fullname.isEmpty(), "rootPackage missing!"); 2620 Assert.check(!fullname.isEmpty(), "rootPackage missing!");
2610 p = new PackageSymbol( 2621 p = new PackageSymbol(
2611 Convert.shortName(fullname), 2622 Convert.shortName(fullname),
2612 enterPackage(Convert.packagePart(fullname))); 2623 enterPackage(Convert.packagePart(fullname)));
2613 p.completer = this; 2624 p.completer = thisCompleter;
2614 packages.put(fullname, p); 2625 packages.put(fullname, p);
2615 } 2626 }
2616 return p; 2627 return p;
2617 } 2628 }
2618 2629

mercurial