9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.javac.code;
27
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.Map;
31 import java.util.Set;
32
33 import javax.lang.model.element.ElementVisitor;
34 import javax.tools.JavaFileObject;
35
36
37 import com.sun.tools.javac.code.Scope.WriteableScope;
38 import com.sun.tools.javac.code.Symbol.ClassSymbol;
39 import com.sun.tools.javac.code.Symbol.Completer;
40 import com.sun.tools.javac.code.Symbol.CompletionFailure;
41 import com.sun.tools.javac.code.Symbol.MethodSymbol;
42 import com.sun.tools.javac.code.Symbol.OperatorSymbol;
43 import com.sun.tools.javac.code.Symbol.PackageSymbol;
44 import com.sun.tools.javac.code.Symbol.TypeSymbol;
45 import com.sun.tools.javac.code.Symbol.VarSymbol;
46 import com.sun.tools.javac.code.Type.BottomType;
47 import com.sun.tools.javac.code.Type.ClassType;
48 import com.sun.tools.javac.code.Type.ErrorType;
49 import com.sun.tools.javac.code.Type.JCPrimitiveType;
50 import com.sun.tools.javac.code.Type.JCVoidType;
51 import com.sun.tools.javac.code.Type.MethodType;
52 import com.sun.tools.javac.code.Type.UnknownType;
53 import com.sun.tools.javac.jvm.ByteCodes;
54 import com.sun.tools.javac.jvm.Target;
55 import com.sun.tools.javac.util.Assert;
56 import com.sun.tools.javac.util.Context;
57 import com.sun.tools.javac.util.Convert;
58 import com.sun.tools.javac.util.DefinedBy;
59 import com.sun.tools.javac.util.DefinedBy.Api;
60 import com.sun.tools.javac.util.JavacMessages;
61 import com.sun.tools.javac.util.List;
62 import com.sun.tools.javac.util.Log;
63 import com.sun.tools.javac.util.Name;
64 import com.sun.tools.javac.util.Names;
65
66 import static com.sun.tools.javac.code.Flags.*;
67 import static com.sun.tools.javac.code.Kinds.Kind.*;
68 import static com.sun.tools.javac.jvm.ByteCodes.*;
69 import static com.sun.tools.javac.code.TypeTag.*;
70
71 /** A class that defines all predefined constants and operators
72 * as well as special classes such as java.lang.Object, which need
73 * to be known to the compiler. All symbols are held in instance
74 * fields. This makes it possible to work in multiple concurrent
75 * projects, which might use different class files for library classes.
76 *
77 * <p><b>This is NOT part of any supported API.
78 * If you write code that depends on this, you do so at your own risk.
79 * This code and its internal interfaces are subject to change or
80 * deletion without notice.</b>
81 */
82 public class Symtab {
83 /** The context key for the symbol table. */
84 protected static final Context.Key<Symtab> symtabKey = new Context.Key<>();
85
86 /** Get the symbol table instance. */
87 public static Symtab instance(Context context) {
88 Symtab instance = context.get(symtabKey);
176 public final Type listType;
177 public final Type collectionsType;
178 public final Type comparableType;
179 public final Type comparatorType;
180 public final Type arraysType;
181 public final Type iterableType;
182 public final Type iteratorType;
183 public final Type annotationTargetType;
184 public final Type overrideType;
185 public final Type retentionType;
186 public final Type deprecatedType;
187 public final Type suppressWarningsType;
188 public final Type supplierType;
189 public final Type inheritedType;
190 public final Type profileType;
191 public final Type proprietaryType;
192 public final Type systemType;
193 public final Type autoCloseableType;
194 public final Type trustMeType;
195 public final Type lambdaMetafactory;
196 public final Type repeatableType;
197 public final Type documentedType;
198 public final Type elementTypeType;
199 public final Type functionalInterfaceType;
200
201 /** The symbol representing the length field of an array.
202 */
203 public final VarSymbol lengthVar;
204
205 /** The symbol representing the final finalize method on enums */
206 public final MethodSymbol enumFinalFinalize;
207
208 /** The symbol representing the close method on TWR AutoCloseable type */
209 public final MethodSymbol autoCloseableClose;
210
211 /** The predefined type that belongs to a tag.
212 */
213 public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
214
215 /** The name of the class that belongs to a basix type tag.
455 annotationTargetType = enterClass("java.lang.annotation.Target");
456 overrideType = enterClass("java.lang.Override");
457 retentionType = enterClass("java.lang.annotation.Retention");
458 deprecatedType = enterClass("java.lang.Deprecated");
459 suppressWarningsType = enterClass("java.lang.SuppressWarnings");
460 supplierType = enterClass("java.util.function.Supplier");
461 inheritedType = enterClass("java.lang.annotation.Inherited");
462 repeatableType = enterClass("java.lang.annotation.Repeatable");
463 documentedType = enterClass("java.lang.annotation.Documented");
464 elementTypeType = enterClass("java.lang.annotation.ElementType");
465 systemType = enterClass("java.lang.System");
466 autoCloseableType = enterClass("java.lang.AutoCloseable");
467 autoCloseableClose = new MethodSymbol(PUBLIC,
468 names.close,
469 new MethodType(List.<Type>nil(), voidType,
470 List.of(exceptionType), methodClass),
471 autoCloseableType.tsym);
472 trustMeType = enterClass("java.lang.SafeVarargs");
473 nativeHeaderType = enterClass("java.lang.annotation.Native");
474 lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
475 functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
476
477 synthesizeEmptyInterfaceIfMissing(autoCloseableType);
478 synthesizeEmptyInterfaceIfMissing(cloneableType);
479 synthesizeEmptyInterfaceIfMissing(serializableType);
480 synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
481 synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
482 synthesizeBoxTypeIfMissing(doubleType);
483 synthesizeBoxTypeIfMissing(floatType);
484 synthesizeBoxTypeIfMissing(voidType);
485
486 // Enter a synthetic class that is used to mark internal
487 // proprietary classes in ct.sym. This class does not have a
488 // class file.
489 proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
490
491 // Enter a synthetic class that is used to provide profile info for
492 // classes in ct.sym. This class does not have a class file.
493 profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
494 MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
495 profileType.tsym.members().enter(m);
496
497 // Enter a class for arrays.
498 // The class implements java.lang.Cloneable and java.io.Serializable.
499 // It has a final length field and a clone method.
500 ClassType arrayClassType = (ClassType)arrayClass.type;
501 arrayClassType.supertype_field = objectType;
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.javac.code;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import javax.lang.model.element.ElementVisitor;
32 import javax.tools.JavaFileObject;
33
34
35 import com.sun.tools.javac.code.Scope.WriteableScope;
36 import com.sun.tools.javac.code.Symbol.ClassSymbol;
37 import com.sun.tools.javac.code.Symbol.Completer;
38 import com.sun.tools.javac.code.Symbol.CompletionFailure;
39 import com.sun.tools.javac.code.Symbol.MethodSymbol;
40 import com.sun.tools.javac.code.Symbol.PackageSymbol;
41 import com.sun.tools.javac.code.Symbol.TypeSymbol;
42 import com.sun.tools.javac.code.Symbol.VarSymbol;
43 import com.sun.tools.javac.code.Type.BottomType;
44 import com.sun.tools.javac.code.Type.ClassType;
45 import com.sun.tools.javac.code.Type.ErrorType;
46 import com.sun.tools.javac.code.Type.JCPrimitiveType;
47 import com.sun.tools.javac.code.Type.JCVoidType;
48 import com.sun.tools.javac.code.Type.MethodType;
49 import com.sun.tools.javac.code.Type.UnknownType;
50 import com.sun.tools.javac.jvm.Target;
51 import com.sun.tools.javac.util.Assert;
52 import com.sun.tools.javac.util.Context;
53 import com.sun.tools.javac.util.Convert;
54 import com.sun.tools.javac.util.DefinedBy;
55 import com.sun.tools.javac.util.DefinedBy.Api;
56 import com.sun.tools.javac.util.JavacMessages;
57 import com.sun.tools.javac.util.List;
58 import com.sun.tools.javac.util.Log;
59 import com.sun.tools.javac.util.Name;
60 import com.sun.tools.javac.util.Names;
61
62 import static com.sun.tools.javac.code.Flags.*;
63 import static com.sun.tools.javac.code.Kinds.Kind.*;
64 import static com.sun.tools.javac.code.TypeTag.*;
65
66 /** A class that defines all predefined constants and operators
67 * as well as special classes such as java.lang.Object, which need
68 * to be known to the compiler. All symbols are held in instance
69 * fields. This makes it possible to work in multiple concurrent
70 * projects, which might use different class files for library classes.
71 *
72 * <p><b>This is NOT part of any supported API.
73 * If you write code that depends on this, you do so at your own risk.
74 * This code and its internal interfaces are subject to change or
75 * deletion without notice.</b>
76 */
77 public class Symtab {
78 /** The context key for the symbol table. */
79 protected static final Context.Key<Symtab> symtabKey = new Context.Key<>();
80
81 /** Get the symbol table instance. */
82 public static Symtab instance(Context context) {
83 Symtab instance = context.get(symtabKey);
171 public final Type listType;
172 public final Type collectionsType;
173 public final Type comparableType;
174 public final Type comparatorType;
175 public final Type arraysType;
176 public final Type iterableType;
177 public final Type iteratorType;
178 public final Type annotationTargetType;
179 public final Type overrideType;
180 public final Type retentionType;
181 public final Type deprecatedType;
182 public final Type suppressWarningsType;
183 public final Type supplierType;
184 public final Type inheritedType;
185 public final Type profileType;
186 public final Type proprietaryType;
187 public final Type systemType;
188 public final Type autoCloseableType;
189 public final Type trustMeType;
190 public final Type lambdaMetafactory;
191 public final Type stringConcatFactory;
192 public final Type repeatableType;
193 public final Type documentedType;
194 public final Type elementTypeType;
195 public final Type functionalInterfaceType;
196
197 /** The symbol representing the length field of an array.
198 */
199 public final VarSymbol lengthVar;
200
201 /** The symbol representing the final finalize method on enums */
202 public final MethodSymbol enumFinalFinalize;
203
204 /** The symbol representing the close method on TWR AutoCloseable type */
205 public final MethodSymbol autoCloseableClose;
206
207 /** The predefined type that belongs to a tag.
208 */
209 public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
210
211 /** The name of the class that belongs to a basix type tag.
451 annotationTargetType = enterClass("java.lang.annotation.Target");
452 overrideType = enterClass("java.lang.Override");
453 retentionType = enterClass("java.lang.annotation.Retention");
454 deprecatedType = enterClass("java.lang.Deprecated");
455 suppressWarningsType = enterClass("java.lang.SuppressWarnings");
456 supplierType = enterClass("java.util.function.Supplier");
457 inheritedType = enterClass("java.lang.annotation.Inherited");
458 repeatableType = enterClass("java.lang.annotation.Repeatable");
459 documentedType = enterClass("java.lang.annotation.Documented");
460 elementTypeType = enterClass("java.lang.annotation.ElementType");
461 systemType = enterClass("java.lang.System");
462 autoCloseableType = enterClass("java.lang.AutoCloseable");
463 autoCloseableClose = new MethodSymbol(PUBLIC,
464 names.close,
465 new MethodType(List.<Type>nil(), voidType,
466 List.of(exceptionType), methodClass),
467 autoCloseableType.tsym);
468 trustMeType = enterClass("java.lang.SafeVarargs");
469 nativeHeaderType = enterClass("java.lang.annotation.Native");
470 lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
471 stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
472 functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
473
474 synthesizeEmptyInterfaceIfMissing(autoCloseableType);
475 synthesizeEmptyInterfaceIfMissing(cloneableType);
476 synthesizeEmptyInterfaceIfMissing(serializableType);
477 synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
478 synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
479 synthesizeEmptyInterfaceIfMissing(stringConcatFactory);
480 synthesizeBoxTypeIfMissing(doubleType);
481 synthesizeBoxTypeIfMissing(floatType);
482 synthesizeBoxTypeIfMissing(voidType);
483
484 // Enter a synthetic class that is used to mark internal
485 // proprietary classes in ct.sym. This class does not have a
486 // class file.
487 proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
488
489 // Enter a synthetic class that is used to provide profile info for
490 // classes in ct.sym. This class does not have a class file.
491 profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
492 MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
493 profileType.tsym.members().enter(m);
494
495 // Enter a class for arrays.
496 // The class implements java.lang.Cloneable and java.io.Serializable.
497 // It has a final length field and a clone method.
498 ClassType arrayClassType = (ClassType)arrayClass.type;
499 arrayClassType.supertype_field = objectType;
|