73 public final Type botType = new BottomType(); |
73 public final Type botType = new BottomType(); |
74 public final JCNoType voidType = new JCNoType(TypeTags.VOID); |
74 public final JCNoType voidType = new JCNoType(TypeTags.VOID); |
75 |
75 |
76 private final Name.Table names; |
76 private final Name.Table names; |
77 private final ClassReader reader; |
77 private final ClassReader reader; |
|
78 private final Target target; |
78 |
79 |
79 /** A symbol for the root package. |
80 /** A symbol for the root package. |
80 */ |
81 */ |
81 public final PackageSymbol rootPackage; |
82 public final PackageSymbol rootPackage; |
82 |
83 |
142 public final Type retentionType; |
143 public final Type retentionType; |
143 public final Type deprecatedType; |
144 public final Type deprecatedType; |
144 public final Type suppressWarningsType; |
145 public final Type suppressWarningsType; |
145 public final Type inheritedType; |
146 public final Type inheritedType; |
146 public final Type proprietaryType; |
147 public final Type proprietaryType; |
|
148 public final Type systemType; |
147 |
149 |
148 /** The symbol representing the length field of an array. |
150 /** The symbol representing the length field of an array. |
149 */ |
151 */ |
150 public final VarSymbol lengthVar; |
152 public final VarSymbol lengthVar; |
151 |
153 |
270 */ |
272 */ |
271 private Type enterClass(String s) { |
273 private Type enterClass(String s) { |
272 return reader.enterClass(names.fromString(s)).type; |
274 return reader.enterClass(names.fromString(s)).type; |
273 } |
275 } |
274 |
276 |
|
277 public void synthesizeEmptyInterfaceIfMissing(final Type type) { |
|
278 final Completer completer = type.tsym.completer; |
|
279 if (completer != null) { |
|
280 type.tsym.completer = new Completer() { |
|
281 public void complete(Symbol sym) throws CompletionFailure { |
|
282 try { |
|
283 completer.complete(sym); |
|
284 } catch (CompletionFailure e) { |
|
285 sym.flags_field |= (PUBLIC | INTERFACE); |
|
286 ((ClassType) sym.type).supertype_field = objectType; |
|
287 } |
|
288 } |
|
289 }; |
|
290 } |
|
291 } |
|
292 |
|
293 public void synthesizeBoxTypeIfMissing(final Type type) { |
|
294 ClassSymbol sym = reader.enterClass(boxedName[type.tag]); |
|
295 final Completer completer = sym.completer; |
|
296 if (completer != null) { |
|
297 sym.completer = new Completer() { |
|
298 public void complete(Symbol sym) throws CompletionFailure { |
|
299 try { |
|
300 completer.complete(sym); |
|
301 } catch (CompletionFailure e) { |
|
302 sym.flags_field |= PUBLIC; |
|
303 ((ClassType) sym.type).supertype_field = objectType; |
|
304 Name n = target.boxWithConstructors() ? names.init : names.valueOf; |
|
305 MethodSymbol boxMethod = |
|
306 new MethodSymbol(PUBLIC | STATIC, |
|
307 n, |
|
308 new MethodType(List.of(type), sym.type, |
|
309 List.<Type>nil(), methodClass), |
|
310 sym); |
|
311 sym.members().enter(boxMethod); |
|
312 MethodSymbol unboxMethod = |
|
313 new MethodSymbol(PUBLIC, |
|
314 type.tsym.name.append(names.Value), // x.intValue() |
|
315 new MethodType(List.<Type>nil(), type, |
|
316 List.<Type>nil(), methodClass), |
|
317 sym); |
|
318 sym.members().enter(unboxMethod); |
|
319 } |
|
320 } |
|
321 }; |
|
322 } |
|
323 |
|
324 } |
|
325 |
275 /** Constructor; enters all predefined identifiers and operators |
326 /** Constructor; enters all predefined identifiers and operators |
276 * into symbol table. |
327 * into symbol table. |
277 */ |
328 */ |
278 protected Symtab(Context context) throws CompletionFailure { |
329 protected Symtab(Context context) throws CompletionFailure { |
279 context.put(symtabKey, this); |
330 context.put(symtabKey, this); |
280 |
331 |
281 names = Name.Table.instance(context); |
332 names = Name.Table.instance(context); |
|
333 target = Target.instance(context); |
282 |
334 |
283 // Create the unknown type |
335 // Create the unknown type |
284 unknownType = new Type(TypeTags.UNKNOWN, null); |
336 unknownType = new Type(TypeTags.UNKNOWN, null); |
285 |
337 |
286 // create the basic builtin symbols |
338 // create the basic builtin symbols |
371 enumSym); |
423 enumSym); |
372 listType = enterClass("java.util.List"); |
424 listType = enterClass("java.util.List"); |
373 collectionsType = enterClass("java.util.Collections"); |
425 collectionsType = enterClass("java.util.Collections"); |
374 comparableType = enterClass("java.lang.Comparable"); |
426 comparableType = enterClass("java.lang.Comparable"); |
375 arraysType = enterClass("java.util.Arrays"); |
427 arraysType = enterClass("java.util.Arrays"); |
376 iterableType = Target.instance(context).hasIterable() |
428 iterableType = target.hasIterable() |
377 ? enterClass("java.lang.Iterable") |
429 ? enterClass("java.lang.Iterable") |
378 : enterClass("java.util.Collection"); |
430 : enterClass("java.util.Collection"); |
379 iteratorType = enterClass("java.util.Iterator"); |
431 iteratorType = enterClass("java.util.Iterator"); |
380 annotationTargetType = enterClass("java.lang.annotation.Target"); |
432 annotationTargetType = enterClass("java.lang.annotation.Target"); |
381 overrideType = enterClass("java.lang.Override"); |
433 overrideType = enterClass("java.lang.Override"); |
382 retentionType = enterClass("java.lang.annotation.Retention"); |
434 retentionType = enterClass("java.lang.annotation.Retention"); |
383 deprecatedType = enterClass("java.lang.Deprecated"); |
435 deprecatedType = enterClass("java.lang.Deprecated"); |
384 suppressWarningsType = enterClass("java.lang.SuppressWarnings"); |
436 suppressWarningsType = enterClass("java.lang.SuppressWarnings"); |
385 inheritedType = enterClass("java.lang.annotation.Inherited"); |
437 inheritedType = enterClass("java.lang.annotation.Inherited"); |
|
438 systemType = enterClass("java.lang.System"); |
|
439 |
|
440 synthesizeEmptyInterfaceIfMissing(cloneableType); |
|
441 synthesizeEmptyInterfaceIfMissing(serializableType); |
|
442 synthesizeBoxTypeIfMissing(doubleType); |
|
443 synthesizeBoxTypeIfMissing(floatType); |
386 |
444 |
387 // Enter a synthetic class that is used to mark Sun |
445 // Enter a synthetic class that is used to mark Sun |
388 // proprietary classes in ct.sym. This class does not have a |
446 // proprietary classes in ct.sym. This class does not have a |
389 // class file. |
447 // class file. |
390 ClassType proprietaryType = (ClassType)enterClass("sun.Proprietary+Annotation"); |
448 ClassType proprietaryType = (ClassType)enterClass("sun.Proprietary+Annotation"); |