< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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


  25 
  26 package com.sun.tools.javac.code;
  27 
  28 import java.util.Collection;
  29 import java.util.Collections;
  30 import java.util.EnumSet;
  31 import java.util.HashMap;
  32 import java.util.LinkedHashMap;
  33 import java.util.Map;
  34 
  35 import javax.lang.model.element.ElementVisitor;
  36 
  37 import com.sun.tools.javac.code.Scope.WriteableScope;
  38 import com.sun.tools.javac.code.Source.Feature;
  39 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  40 import com.sun.tools.javac.code.Symbol.Completer;
  41 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  42 import com.sun.tools.javac.code.Symbol.MethodSymbol;
  43 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
  44 import com.sun.tools.javac.code.Symbol.PackageSymbol;
  45 import com.sun.tools.javac.code.Symbol.RootPackageSymbol;
  46 import com.sun.tools.javac.code.Symbol.TypeSymbol;
  47 import com.sun.tools.javac.code.Symbol.VarSymbol;
  48 import com.sun.tools.javac.code.Type.BottomType;
  49 import com.sun.tools.javac.code.Type.ClassType;
  50 import com.sun.tools.javac.code.Type.ErrorType;
  51 import com.sun.tools.javac.code.Type.JCPrimitiveType;
  52 import com.sun.tools.javac.code.Type.JCVoidType;
  53 import com.sun.tools.javac.code.Type.MethodType;
  54 import com.sun.tools.javac.code.Type.UnknownType;
  55 import com.sun.tools.javac.code.Types.UniqueType;
  56 import com.sun.tools.javac.comp.Modules;
  57 import com.sun.tools.javac.util.Assert;
  58 import com.sun.tools.javac.util.Context;
  59 import com.sun.tools.javac.util.Convert;
  60 import com.sun.tools.javac.util.DefinedBy;
  61 import com.sun.tools.javac.util.DefinedBy.Api;
  62 import com.sun.tools.javac.util.Iterators;
  63 import com.sun.tools.javac.util.JavacMessages;
  64 import com.sun.tools.javac.util.List;
  65 import com.sun.tools.javac.util.Name;


 155     public final ClassSymbol methodClass;
 156 
 157     /** A symbol for the java.base module.
 158      */
 159     public final ModuleSymbol java_base;
 160 
 161     /** Predefined types.
 162      */
 163     public final Type objectType;
 164     public final Type objectsType;
 165     public final Type classType;
 166     public final Type classLoaderType;
 167     public final Type stringType;
 168     public final Type stringBufferType;
 169     public final Type stringBuilderType;
 170     public final Type cloneableType;
 171     public final Type serializableType;
 172     public final Type serializedLambdaType;
 173     public final Type varHandleType;
 174     public final Type methodHandleType;
 175     public final Type methodHandleLookupType;

 176     public final Type methodTypeType;

 177     public final Type nativeHeaderType;
 178     public final Type throwableType;
 179     public final Type errorType;
 180     public final Type interruptedExceptionType;
 181     public final Type illegalArgumentExceptionType;
 182     public final Type exceptionType;
 183     public final Type runtimeExceptionType;
 184     public final Type classNotFoundExceptionType;
 185     public final Type noClassDefFoundErrorType;
 186     public final Type noSuchFieldErrorType;
 187     public final Type assertionErrorType;
 188     public final Type incompatibleClassChangeErrorType;
 189     public final Type cloneNotSupportedExceptionType;
 190     public final Type annotationType;
 191     public final TypeSymbol enumSym;
 192     public final Type listType;
 193     public final Type collectionsType;
 194     public final Type comparableType;
 195     public final Type comparatorType;
 196     public final Type arraysType;


 366         type.typarams_field = List.nil();
 367         type.allparams_field = List.nil();
 368         type.supertype_field = annotationType;
 369         type.interfaces_field = List.nil();
 370         return type;
 371     }
 372 
 373     /** Constructor; enters all predefined identifiers and operators
 374      *  into symbol table.
 375      */
 376     protected Symtab(Context context) throws CompletionFailure {
 377         context.put(symtabKey, this);
 378 
 379         names = Names.instance(context);
 380 
 381         // Create the unknown type
 382         unknownType = new UnknownType();
 383 
 384         messages = JavacMessages.instance(context);
 385 
 386         MissingInfoHandler missingInfoHandler = MissingInfoHandler.instance(context);
 387 
 388         rootPackage = new RootPackageSymbol(names.empty, null, missingInfoHandler);
 389 
 390         // create the basic builtin symbols
 391         unnamedModule = new ModuleSymbol(names.empty, null) {
 392                 {
 393                     directives = List.nil();
 394                     exports = List.nil();
 395                     provides = List.nil();
 396                     uses = List.nil();
 397                     ModuleSymbol java_base = enterModule(names.java_base);
 398                     com.sun.tools.javac.code.Directive.RequiresDirective d =
 399                             new com.sun.tools.javac.code.Directive.RequiresDirective(java_base,
 400                                     EnumSet.of(com.sun.tools.javac.code.Directive.RequiresFlag.MANDATED));
 401                     requires = List.of(d);
 402                 }
 403                 @Override
 404                 public String toString() {
 405                     return messages.getLocalizedString("compiler.misc.unnamed.module");
 406                 }
 407             };
 408         addRootPackageFor(unnamedModule);


 502         } else {
 503             java_base = noModule;
 504         }
 505 
 506         // Get the initial completer for ModuleSymbols from Modules
 507         moduleCompleter = Modules.instance(context).getCompleter();
 508 
 509         // Enter predefined classes. All are assumed to be in the java.base module.
 510         objectType = enterClass("java.lang.Object");
 511         objectsType = enterClass("java.util.Objects");
 512         classType = enterClass("java.lang.Class");
 513         stringType = enterClass("java.lang.String");
 514         stringBufferType = enterClass("java.lang.StringBuffer");
 515         stringBuilderType = enterClass("java.lang.StringBuilder");
 516         cloneableType = enterClass("java.lang.Cloneable");
 517         throwableType = enterClass("java.lang.Throwable");
 518         serializableType = enterClass("java.io.Serializable");
 519         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
 520         varHandleType = enterClass("java.lang.invoke.VarHandle");
 521         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
 522         methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");

 523         methodTypeType = enterClass("java.lang.invoke.MethodType");

 524         errorType = enterClass("java.lang.Error");
 525         illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
 526         interruptedExceptionType = enterClass("java.lang.InterruptedException");
 527         exceptionType = enterClass("java.lang.Exception");
 528         runtimeExceptionType = enterClass("java.lang.RuntimeException");
 529         classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
 530         noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
 531         noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
 532         assertionErrorType = enterClass("java.lang.AssertionError");
 533         incompatibleClassChangeErrorType = enterClass("java.lang.IncompatibleClassChangeError");
 534         cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
 535         annotationType = enterClass("java.lang.annotation.Annotation");
 536         classLoaderType = enterClass("java.lang.ClassLoader");
 537         enumSym = enterClass(java_base, names.java_lang_Enum);
 538         enumFinalFinalize =
 539             new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
 540                              names.finalize,
 541                              new MethodType(List.nil(), voidType,
 542                                             List.nil(), methodClass),
 543                              enumSym);


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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


  25 
  26 package com.sun.tools.javac.code;
  27 
  28 import java.util.Collection;
  29 import java.util.Collections;
  30 import java.util.EnumSet;
  31 import java.util.HashMap;
  32 import java.util.LinkedHashMap;
  33 import java.util.Map;
  34 
  35 import javax.lang.model.element.ElementVisitor;
  36 
  37 import com.sun.tools.javac.code.Scope.WriteableScope;
  38 import com.sun.tools.javac.code.Source.Feature;
  39 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  40 import com.sun.tools.javac.code.Symbol.Completer;
  41 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  42 import com.sun.tools.javac.code.Symbol.MethodSymbol;
  43 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
  44 import com.sun.tools.javac.code.Symbol.PackageSymbol;

  45 import com.sun.tools.javac.code.Symbol.TypeSymbol;
  46 import com.sun.tools.javac.code.Symbol.VarSymbol;
  47 import com.sun.tools.javac.code.Type.BottomType;
  48 import com.sun.tools.javac.code.Type.ClassType;
  49 import com.sun.tools.javac.code.Type.ErrorType;
  50 import com.sun.tools.javac.code.Type.JCPrimitiveType;
  51 import com.sun.tools.javac.code.Type.JCVoidType;
  52 import com.sun.tools.javac.code.Type.MethodType;
  53 import com.sun.tools.javac.code.Type.UnknownType;
  54 import com.sun.tools.javac.code.Types.UniqueType;
  55 import com.sun.tools.javac.comp.Modules;
  56 import com.sun.tools.javac.util.Assert;
  57 import com.sun.tools.javac.util.Context;
  58 import com.sun.tools.javac.util.Convert;
  59 import com.sun.tools.javac.util.DefinedBy;
  60 import com.sun.tools.javac.util.DefinedBy.Api;
  61 import com.sun.tools.javac.util.Iterators;
  62 import com.sun.tools.javac.util.JavacMessages;
  63 import com.sun.tools.javac.util.List;
  64 import com.sun.tools.javac.util.Name;


 154     public final ClassSymbol methodClass;
 155 
 156     /** A symbol for the java.base module.
 157      */
 158     public final ModuleSymbol java_base;
 159 
 160     /** Predefined types.
 161      */
 162     public final Type objectType;
 163     public final Type objectsType;
 164     public final Type classType;
 165     public final Type classLoaderType;
 166     public final Type stringType;
 167     public final Type stringBufferType;
 168     public final Type stringBuilderType;
 169     public final Type cloneableType;
 170     public final Type serializableType;
 171     public final Type serializedLambdaType;
 172     public final Type varHandleType;
 173     public final Type methodHandleType;
 174     public final Type methodHandlesLookupType;
 175     public final Type intrinsicsType;
 176     public final Type methodTypeType;
 177     public final Type foldableType;
 178     public final Type nativeHeaderType;
 179     public final Type throwableType;
 180     public final Type errorType;
 181     public final Type interruptedExceptionType;
 182     public final Type illegalArgumentExceptionType;
 183     public final Type exceptionType;
 184     public final Type runtimeExceptionType;
 185     public final Type classNotFoundExceptionType;
 186     public final Type noClassDefFoundErrorType;
 187     public final Type noSuchFieldErrorType;
 188     public final Type assertionErrorType;
 189     public final Type incompatibleClassChangeErrorType;
 190     public final Type cloneNotSupportedExceptionType;
 191     public final Type annotationType;
 192     public final TypeSymbol enumSym;
 193     public final Type listType;
 194     public final Type collectionsType;
 195     public final Type comparableType;
 196     public final Type comparatorType;
 197     public final Type arraysType;


 367         type.typarams_field = List.nil();
 368         type.allparams_field = List.nil();
 369         type.supertype_field = annotationType;
 370         type.interfaces_field = List.nil();
 371         return type;
 372     }
 373 
 374     /** Constructor; enters all predefined identifiers and operators
 375      *  into symbol table.
 376      */
 377     protected Symtab(Context context) throws CompletionFailure {
 378         context.put(symtabKey, this);
 379 
 380         names = Names.instance(context);
 381 
 382         // Create the unknown type
 383         unknownType = new UnknownType();
 384 
 385         messages = JavacMessages.instance(context);
 386 
 387         rootPackage = new PackageSymbol(names.empty, null);


 388 
 389         // create the basic builtin symbols
 390         unnamedModule = new ModuleSymbol(names.empty, null) {
 391                 {
 392                     directives = List.nil();
 393                     exports = List.nil();
 394                     provides = List.nil();
 395                     uses = List.nil();
 396                     ModuleSymbol java_base = enterModule(names.java_base);
 397                     com.sun.tools.javac.code.Directive.RequiresDirective d =
 398                             new com.sun.tools.javac.code.Directive.RequiresDirective(java_base,
 399                                     EnumSet.of(com.sun.tools.javac.code.Directive.RequiresFlag.MANDATED));
 400                     requires = List.of(d);
 401                 }
 402                 @Override
 403                 public String toString() {
 404                     return messages.getLocalizedString("compiler.misc.unnamed.module");
 405                 }
 406             };
 407         addRootPackageFor(unnamedModule);


 501         } else {
 502             java_base = noModule;
 503         }
 504 
 505         // Get the initial completer for ModuleSymbols from Modules
 506         moduleCompleter = Modules.instance(context).getCompleter();
 507 
 508         // Enter predefined classes. All are assumed to be in the java.base module.
 509         objectType = enterClass("java.lang.Object");
 510         objectsType = enterClass("java.util.Objects");
 511         classType = enterClass("java.lang.Class");
 512         stringType = enterClass("java.lang.String");
 513         stringBufferType = enterClass("java.lang.StringBuffer");
 514         stringBuilderType = enterClass("java.lang.StringBuilder");
 515         cloneableType = enterClass("java.lang.Cloneable");
 516         throwableType = enterClass("java.lang.Throwable");
 517         serializableType = enterClass("java.io.Serializable");
 518         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
 519         varHandleType = enterClass("java.lang.invoke.VarHandle");
 520         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
 521         methodHandlesLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
 522         intrinsicsType = enterClass("java.lang.invoke.Intrinsics");
 523         methodTypeType = enterClass("java.lang.invoke.MethodType");
 524         foldableType = enterClass("jdk.internal.lang.annotation.Foldable");
 525         errorType = enterClass("java.lang.Error");
 526         illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
 527         interruptedExceptionType = enterClass("java.lang.InterruptedException");
 528         exceptionType = enterClass("java.lang.Exception");
 529         runtimeExceptionType = enterClass("java.lang.RuntimeException");
 530         classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
 531         noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
 532         noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
 533         assertionErrorType = enterClass("java.lang.AssertionError");
 534         incompatibleClassChangeErrorType = enterClass("java.lang.IncompatibleClassChangeError");
 535         cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
 536         annotationType = enterClass("java.lang.annotation.Annotation");
 537         classLoaderType = enterClass("java.lang.ClassLoader");
 538         enumSym = enterClass(java_base, names.java_lang_Enum);
 539         enumFinalFinalize =
 540             new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
 541                              names.finalize,
 542                              new MethodType(List.nil(), voidType,
 543                                             List.nil(), methodClass),
 544                              enumSym);


< prev index next >