src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java
author jjg
Wed, 13 Nov 2019 10:33:00 -0800
changeset 59058 3f57daa2d6eb
parent 58713 ad69fd32778e
permissions -rw-r--r--
8234025: Elements.getPackageElement(ModuleElement,CharSequence) returns null for unnamed package Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
54514
b0651dcc8d98 8217047: Provide a way to inject missing parameter names
jlahoda
parents: 51563
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    28
import java.util.Collection;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    29
import java.util.Collections;
40774
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
    30
import java.util.EnumSet;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    31
import java.util.HashMap;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    32
import java.util.LinkedHashMap;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    33
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    35
import javax.lang.model.element.ElementVisitor;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    36
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
    37
import com.sun.tools.javac.code.Scope.WriteableScope;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47216
diff changeset
    38
import com.sun.tools.javac.code.Source.Feature;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    39
import com.sun.tools.javac.code.Symbol.ClassSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    40
import com.sun.tools.javac.code.Symbol.Completer;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    41
import com.sun.tools.javac.code.Symbol.CompletionFailure;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    42
import com.sun.tools.javac.code.Symbol.MethodSymbol;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    43
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    44
import com.sun.tools.javac.code.Symbol.PackageSymbol;
54514
b0651dcc8d98 8217047: Provide a way to inject missing parameter names
jlahoda
parents: 51563
diff changeset
    45
import com.sun.tools.javac.code.Symbol.RootPackageSymbol;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    46
import com.sun.tools.javac.code.Symbol.TypeSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    47
import com.sun.tools.javac.code.Symbol.VarSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    48
import com.sun.tools.javac.code.Type.BottomType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    49
import com.sun.tools.javac.code.Type.ClassType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    50
import com.sun.tools.javac.code.Type.ErrorType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    51
import com.sun.tools.javac.code.Type.JCPrimitiveType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    52
import com.sun.tools.javac.code.Type.JCVoidType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    53
import com.sun.tools.javac.code.Type.MethodType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    54
import com.sun.tools.javac.code.Type.UnknownType;
49887
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
    55
import com.sun.tools.javac.code.Types.UniqueType;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    56
import com.sun.tools.javac.comp.Modules;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    57
import com.sun.tools.javac.util.Assert;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    58
import com.sun.tools.javac.util.Context;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    59
import com.sun.tools.javac.util.Convert;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    60
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    61
import com.sun.tools.javac.util.DefinedBy.Api;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    62
import com.sun.tools.javac.util.Iterators;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    63
import com.sun.tools.javac.util.JavacMessages;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    64
import com.sun.tools.javac.util.List;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    65
import com.sun.tools.javac.util.Name;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    66
import com.sun.tools.javac.util.Names;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    67
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    68
import static com.sun.tools.javac.code.Flags.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
    69
import static com.sun.tools.javac.code.Kinds.Kind.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    70
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
/** A class that defines all predefined constants and operators
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *  as well as special classes such as java.lang.Object, which need
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *  to be known to the compiler. All symbols are held in instance
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *  fields. This makes it possible to work in multiple concurrent
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *  projects, which might use different class files for library classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    78
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    79
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
public class Symtab {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /** The context key for the symbol table. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18646
diff changeset
    85
    protected static final Context.Key<Symtab> symtabKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /** Get the symbol table instance. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    public static Symtab instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        Symtab instance = context.get(symtabKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            instance = new Symtab(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /** Builtin types.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    97
    public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    98
    public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    99
    public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   100
    public final JCPrimitiveType intType = new JCPrimitiveType(INT, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   101
    public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   102
    public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   103
    public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   104
    public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    public final Type botType = new BottomType();
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   106
    public final JCVoidType voidType = new JCVoidType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   108
    private final Names names;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   109
    private final JavacMessages messages;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   110
    private final Completer initialCompleter;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   111
    private final Completer moduleCompleter;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   112
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   113
    /** A symbol for the unnamed module.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   114
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   115
    public final ModuleSymbol unnamedModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   117
    /** The error module.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   118
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   119
    public final ModuleSymbol errModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   120
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   121
    /** A symbol for no module, for use with -source 8 or less
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   122
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   123
    public final ModuleSymbol noModule;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /** A symbol for the root package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public final PackageSymbol rootPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    /** A symbol that stands for a missing symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public final TypeSymbol noSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    /** The error symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    public final ClassSymbol errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   137
    /** The unknown symbol.
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   138
     */
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   139
    public final ClassSymbol unknownSymbol;
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   140
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   141
    /** A value for the errType, with a originalType of noType */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    public final Type errType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /** A value for the unknown type. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    public final Type unknownType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    /** The builtin type of all arrays. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    public final ClassSymbol arrayClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    public final MethodSymbol arrayCloneMethod;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /** VGJ: The (singleton) type of all bound types. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public final ClassSymbol boundClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /** The builtin type of all methods. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public final ClassSymbol methodClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   157
    /** A symbol for the java.base module.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   158
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   159
    public final ModuleSymbol java_base;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   160
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /** Predefined types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    public final Type objectType;
29295
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents: 29294
diff changeset
   164
    public final Type objectsType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public final Type classType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    public final Type classLoaderType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    public final Type stringType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public final Type stringBufferType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public final Type stringBuilderType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    public final Type cloneableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    public final Type serializableType;
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15361
diff changeset
   172
    public final Type serializedLambdaType;
36995
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 35424
diff changeset
   173
    public final Type varHandleType;
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1471
diff changeset
   174
    public final Type methodHandleType;
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   175
    public final Type methodHandleLookupType;
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
   176
    public final Type methodTypeType;
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 9082
diff changeset
   177
    public final Type nativeHeaderType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    public final Type throwableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    public final Type errorType;
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents: 8621
diff changeset
   180
    public final Type interruptedExceptionType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public final Type illegalArgumentExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    public final Type exceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public final Type runtimeExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public final Type classNotFoundExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    public final Type noClassDefFoundErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    public final Type noSuchFieldErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public final Type assertionErrorType;
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 49887
diff changeset
   188
    public final Type incompatibleClassChangeErrorType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    public final Type cloneNotSupportedExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public final Type annotationType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    public final TypeSymbol enumSym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    public final Type listType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    public final Type collectionsType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    public final Type comparableType;
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16316
diff changeset
   195
    public final Type comparatorType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    public final Type arraysType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    public final Type iterableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    public final Type iteratorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    public final Type annotationTargetType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    public final Type overrideType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    public final Type retentionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    public final Type deprecatedType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    public final Type suppressWarningsType;
29294
376a915b4ff0 8073645: Add lambda-based lazy eval versions of Assert.check methods
mcimadamore
parents: 29051
diff changeset
   204
    public final Type supplierType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    public final Type inheritedType;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   206
    public final Type profileType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    public final Type proprietaryType;
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   208
    public final Type systemType;
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   209
    public final Type autoCloseableType;
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 6709
diff changeset
   210
    public final Type trustMeType;
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   211
    public final Type lambdaMetafactory;
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 30066
diff changeset
   212
    public final Type stringConcatFactory;
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14539
diff changeset
   213
    public final Type repeatableType;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   214
    public final Type documentedType;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   215
    public final Type elementTypeType;
15361
01f1828683e6 8005299: Add FunctionalInterface checking to javac
mcimadamore
parents: 15356
diff changeset
   216
    public final Type functionalInterfaceType;
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 54514
diff changeset
   217
    public final Type previewFeatureType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    /** The symbol representing the length field of an array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    public final VarSymbol lengthVar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    /** The symbol representing the final finalize method on enums */
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    public final MethodSymbol enumFinalFinalize;
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   226
    /** The symbol representing the close method on TWR AutoCloseable type */
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   227
    public final MethodSymbol autoCloseableClose;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   228
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    /** The predefined type that belongs to a tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
   231
    public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   233
    /** The name of the class that belongs to a basic type tag.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
   235
    public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    /** A hashtable containing the encountered top-level and member classes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     *  indexed by flat names. The table does not contain local classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     *  It should be updated from the outside to reflect classes defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     *  by compiled source files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   242
    private final Map<Name, Map<ModuleSymbol,ClassSymbol>> classes = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    /** A hashtable containing the encountered packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     *  the table should be updated from outside to reflect packages defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     *  by compiled source files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   248
    private final Map<Name, Map<ModuleSymbol,PackageSymbol>> packages = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   249
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   250
    /** A hashtable giving the encountered modules.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   251
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   252
    private final Map<Name, ModuleSymbol> modules = new LinkedHashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
49887
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   254
    private final Map<Types.UniqueType, VarSymbol> classFields = new HashMap<>();
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   255
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   256
    public VarSymbol getClassField(Type type, Types types) {
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   257
        return classFields.computeIfAbsent(
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   258
            new UniqueType(type, types), k -> {
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   259
                Type arg = null;
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   260
                if (type.getTag() == ARRAY || type.getTag() == CLASS)
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   261
                    arg = types.erasure(type);
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   262
                else if (type.isPrimitiveOrVoid())
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   263
                    arg = types.boxedClass(type).type;
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   264
                else
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   265
                    throw new AssertionError(type);
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   266
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   267
                Type t = new ClassType(
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   268
                    classType.getEnclosingType(), List.of(arg), classType.tsym);
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   269
                return new VarSymbol(
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   270
                    STATIC | PUBLIC | FINAL, names._class, t, type.tsym);
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   271
            });
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   272
    }
39446351e625 8202141: Unique symbols for .class
bsrbnd
parents: 48054
diff changeset
   273
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    public void initType(Type type, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        type.tsym = c;
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   276
        typeOfTag[type.getTag().ordinal()] = type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    public void initType(Type type, String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        initType(
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            new ClassSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                PUBLIC, names.fromString(name), type, rootPackage));
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    public void initType(Type type, String name, String bname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        initType(type, name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   288
        boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    /** The class symbol that owns all predefined symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    public final ClassSymbol predefClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    /** Enter a class into symbol table.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   296
     *  @param s The name of the class.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    private Type enterClass(String s) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   299
        return enterClass(java_base, names.fromString(s)).type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   302
    public void synthesizeEmptyInterfaceIfMissing(final Type type) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   303
        final Completer completer = type.tsym.completer;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   304
        type.tsym.completer = new Completer() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   305
            @Override
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   306
            public void complete(Symbol sym) throws CompletionFailure {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   307
                try {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   308
                    completer.complete(sym);
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   309
                } catch (CompletionFailure e) {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   310
                    sym.flags_field |= (PUBLIC | INTERFACE);
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   311
                    ((ClassType) sym.type).supertype_field = objectType;
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   312
                }
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   313
            }
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   314
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   315
            @Override
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   316
            public boolean isTerminal() {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   317
                return completer.isTerminal();
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   318
            }
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   319
        };
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   320
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   321
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   322
    public void synthesizeBoxTypeIfMissing(final Type type) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   323
        ClassSymbol sym = enterClass(java_base, boxedName[type.getTag().ordinal()]);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   324
        final Completer completer = sym.completer;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   325
        sym.completer = new Completer() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   326
            @Override
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   327
            public void complete(Symbol sym) throws CompletionFailure {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   328
                try {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   329
                    completer.complete(sym);
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   330
                } catch (CompletionFailure e) {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   331
                    sym.flags_field |= PUBLIC;
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   332
                    ((ClassType) sym.type).supertype_field = objectType;
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   333
                    MethodSymbol boxMethod =
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   334
                        new MethodSymbol(PUBLIC | STATIC, names.valueOf,
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   335
                                         new MethodType(List.of(type), sym.type,
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   336
                                List.nil(), methodClass),
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   337
                            sym);
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   338
                    sym.members().enter(boxMethod);
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   339
                    MethodSymbol unboxMethod =
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   340
                        new MethodSymbol(PUBLIC,
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   341
                            type.tsym.name.append(names.Value), // x.intValue()
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   342
                            new MethodType(List.nil(), type,
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   343
                                List.nil(), methodClass),
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   344
                            sym);
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   345
                    sym.members().enter(unboxMethod);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   346
                }
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   347
            }
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   348
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   349
            @Override
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   350
            public boolean isTerminal() {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   351
                return completer.isTerminal();
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   352
            }
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   353
        };
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   354
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   355
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   356
    // Enter a synthetic class that is used to mark classes in ct.sym.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   357
    // This class does not have a class file.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   358
    private Type enterSyntheticAnnotation(String name) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   359
        // for now, leave the module null, to prevent problems from synthesizing the
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   360
        // existence of a class in any specific module, including noModule
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   361
        ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   362
        ClassSymbol sym = (ClassSymbol)type.tsym;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29295
diff changeset
   363
        sym.completer = Completer.NULL_COMPLETER;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   364
        sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   365
        sym.erasure_field = type;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
   366
        sym.members_field = WriteableScope.create(sym);
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   367
        type.typarams_field = List.nil();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   368
        type.allparams_field = List.nil();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   369
        type.supertype_field = annotationType;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   370
        type.interfaces_field = List.nil();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   371
        return type;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   372
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   373
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    /** Constructor; enters all predefined identifiers and operators
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
     *  into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    protected Symtab(Context context) throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        context.put(symtabKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   380
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        // Create the unknown type
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   383
        unknownType = new UnknownType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   385
        messages = JavacMessages.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   386
54514
b0651dcc8d98 8217047: Provide a way to inject missing parameter names
jlahoda
parents: 51563
diff changeset
   387
        MissingInfoHandler missingInfoHandler = MissingInfoHandler.instance(context);
b0651dcc8d98 8217047: Provide a way to inject missing parameter names
jlahoda
parents: 51563
diff changeset
   388
b0651dcc8d98 8217047: Provide a way to inject missing parameter names
jlahoda
parents: 51563
diff changeset
   389
        rootPackage = new RootPackageSymbol(names.empty, null, missingInfoHandler);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   390
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   391
        // create the basic builtin symbols
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   392
        unnamedModule = new ModuleSymbol(names.empty, null) {
40774
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   393
                {
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   394
                    directives = List.nil();
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   395
                    exports = List.nil();
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   396
                    provides = List.nil();
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   397
                    uses = List.nil();
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   398
                    ModuleSymbol java_base = enterModule(names.java_base);
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   399
                    com.sun.tools.javac.code.Directive.RequiresDirective d =
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   400
                            new com.sun.tools.javac.code.Directive.RequiresDirective(java_base,
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   401
                                    EnumSet.of(com.sun.tools.javac.code.Directive.RequiresFlag.MANDATED));
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   402
                    requires = List.of(d);
bed459be3a01 8160454: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getDirectives() causes NPE on unnamed modules
vromero
parents: 40593
diff changeset
   403
                }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   404
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
                public String toString() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   406
                    return messages.getLocalizedString("compiler.misc.unnamed.module");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            };
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   409
        addRootPackageFor(unnamedModule);
40593
d2edf0695b7e 8161501: JSR269 jigsaw update: javax.lang.model.element.ModuleElement.getEnclosedElements() on unnamed module with unnamed package
vromero
parents: 37744
diff changeset
   410
        unnamedModule.enclosedPackages = unnamedModule.enclosedPackages.prepend(unnamedModule.unnamedPackage);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   411
41999
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   412
        errModule = new ModuleSymbol(names.empty, null) {
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   413
                {
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   414
                    directives = List.nil();
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   415
                    exports = List.nil();
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   416
                    provides = List.nil();
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   417
                    uses = List.nil();
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   418
                    ModuleSymbol java_base = enterModule(names.java_base);
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   419
                    com.sun.tools.javac.code.Directive.RequiresDirective d =
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   420
                            new com.sun.tools.javac.code.Directive.RequiresDirective(java_base,
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   421
                                    EnumSet.of(com.sun.tools.javac.code.Directive.RequiresFlag.MANDATED));
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   422
                    requires = List.of(d);
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   423
                }
dbf796210eff 8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents: 41254
diff changeset
   424
            };
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   425
        addRootPackageFor(errModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   426
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   427
        noModule = new ModuleSymbol(names.empty, null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   428
            @Override public boolean isNoModule() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   429
                return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   430
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   431
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   432
        addRootPackageFor(noModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   433
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   434
        noSymbol = new TypeSymbol(NIL, 0, names.empty, Type.noType, rootPackage) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   435
            @Override @DefinedBy(Api.LANGUAGE_MODEL)
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   436
            public <R, P> R accept(ElementVisitor<R, P> v, P p) {
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   437
                return v.visitUnknown(this, p);
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   438
            }
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   439
        };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        // create the error symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   443
        errType = new ErrorType(errSymbol, Type.noType);
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   444
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   445
        unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   446
        unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol);
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   447
        unknownSymbol.type = unknownType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        // initialize builtin types
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        initType(byteType, "byte", "Byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        initType(shortType, "short", "Short");
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        initType(charType, "char", "Character");
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        initType(intType, "int", "Integer");
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        initType(longType, "long", "Long");
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        initType(floatType, "float", "Float");
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        initType(doubleType, "double", "Double");
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        initType(booleanType, "boolean", "Boolean");
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        initType(voidType, "void", "Void");
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        initType(botType, "<nulltype>");
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        initType(errType, errSymbol);
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   461
        initType(unknownType, unknownSymbol);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        // the builtin class of all arrays
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        // VGJ
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   468
        boundClass.members_field = new Scope.ErrorScope(boundClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        // the builtin class of all methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   472
        methodClass.members_field = new Scope.ErrorScope(boundClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        // Create class to hold all predefined constants and operations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
   476
        WriteableScope scope = WriteableScope.create(predefClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        predefClass.members_field = scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 22442
diff changeset
   479
        // Get the initial completer for Symbols from the ClassFinder
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 22442
diff changeset
   480
        initialCompleter = ClassFinder.instance(context).getCompleter();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   481
        rootPackage.members_field = WriteableScope.create(rootPackage);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   482
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        // Enter symbols for basic types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        scope.enter(byteType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        scope.enter(shortType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        scope.enter(charType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        scope.enter(intType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        scope.enter(longType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        scope.enter(floatType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        scope.enter(doubleType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        scope.enter(booleanType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        scope.enter(errType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   494
        // Enter symbol for the errSymbol
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   495
        scope.enter(errSymbol);
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   496
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   497
        Source source = Source.instance(context);
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47216
diff changeset
   498
        if (Feature.MODULES.allowedInSource(source)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   499
            java_base = enterModule(names.java_base);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   500
            //avoid completing java.base during the Symtab initialization
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   501
            java_base.completer = Completer.NULL_COMPLETER;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   502
            java_base.visiblePackages = Collections.emptyMap();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   503
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   504
            java_base = noModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   505
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   507
        // Get the initial completer for ModuleSymbols from Modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   508
        moduleCompleter = Modules.instance(context).getCompleter();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   509
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   510
        // Enter predefined classes. All are assumed to be in the java.base module.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        objectType = enterClass("java.lang.Object");
29295
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents: 29294
diff changeset
   512
        objectsType = enterClass("java.util.Objects");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        classType = enterClass("java.lang.Class");
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        stringType = enterClass("java.lang.String");
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        stringBufferType = enterClass("java.lang.StringBuffer");
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        stringBuilderType = enterClass("java.lang.StringBuilder");
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        cloneableType = enterClass("java.lang.Cloneable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        throwableType = enterClass("java.lang.Throwable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        serializableType = enterClass("java.io.Serializable");
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15361
diff changeset
   520
        serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
36995
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 35424
diff changeset
   521
        varHandleType = enterClass("java.lang.invoke.VarHandle");
8241
4161b56e0d20 7017414: before the move of JSR 292 to package java.lang.invoke, javac must recognize the new package
mcimadamore
parents: 8036
diff changeset
   522
        methodHandleType = enterClass("java.lang.invoke.MethodHandle");
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   523
        methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
   524
        methodTypeType = enterClass("java.lang.invoke.MethodType");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        errorType = enterClass("java.lang.Error");
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents: 8621
diff changeset
   527
        interruptedExceptionType = enterClass("java.lang.InterruptedException");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        exceptionType = enterClass("java.lang.Exception");
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        runtimeExceptionType = enterClass("java.lang.RuntimeException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        assertionErrorType = enterClass("java.lang.AssertionError");
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 49887
diff changeset
   534
        incompatibleClassChangeErrorType = enterClass("java.lang.IncompatibleClassChangeError");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
        annotationType = enterClass("java.lang.annotation.Annotation");
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        classLoaderType = enterClass("java.lang.ClassLoader");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   538
        enumSym = enterClass(java_base, names.java_lang_Enum);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        enumFinalFinalize =
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
                             names.finalize,
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   542
                             new MethodType(List.nil(), voidType,
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   543
                                            List.nil(), methodClass),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
                             enumSym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        listType = enterClass("java.util.List");
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        collectionsType = enterClass("java.util.Collections");
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        comparableType = enterClass("java.lang.Comparable");
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16316
diff changeset
   548
        comparatorType = enterClass("java.util.Comparator");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        arraysType = enterClass("java.util.Arrays");
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
   550
        iterableType = enterClass("java.lang.Iterable");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        iteratorType = enterClass("java.util.Iterator");
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        annotationTargetType = enterClass("java.lang.annotation.Target");
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        overrideType = enterClass("java.lang.Override");
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        retentionType = enterClass("java.lang.annotation.Retention");
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        deprecatedType = enterClass("java.lang.Deprecated");
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
        suppressWarningsType = enterClass("java.lang.SuppressWarnings");
29294
376a915b4ff0 8073645: Add lambda-based lazy eval versions of Assert.check methods
mcimadamore
parents: 29051
diff changeset
   557
        supplierType = enterClass("java.util.function.Supplier");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        inheritedType = enterClass("java.lang.annotation.Inherited");
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14539
diff changeset
   559
        repeatableType = enterClass("java.lang.annotation.Repeatable");
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   560
        documentedType = enterClass("java.lang.annotation.Documented");
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   561
        elementTypeType = enterClass("java.lang.annotation.ElementType");
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   562
        systemType = enterClass("java.lang.System");
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   563
        autoCloseableType = enterClass("java.lang.AutoCloseable");
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   564
        autoCloseableClose = new MethodSymbol(PUBLIC,
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   565
                             names.close,
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   566
                             new MethodType(List.nil(), voidType,
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   567
                                            List.of(exceptionType), methodClass),
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   568
                             autoCloseableType.tsym);
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 6709
diff changeset
   569
        trustMeType = enterClass("java.lang.SafeVarargs");
14539
507556c4e622 8003412: javac needs to understand java.lang.annotation.Native
jjg
parents: 14365
diff changeset
   570
        nativeHeaderType = enterClass("java.lang.annotation.Native");
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   571
        lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 30066
diff changeset
   572
        stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
15361
01f1828683e6 8005299: Add FunctionalInterface checking to javac
mcimadamore
parents: 15356
diff changeset
   573
        functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 54514
diff changeset
   574
        previewFeatureType = enterClass("jdk.internal.PreviewFeature");
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   575
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents: 8621
diff changeset
   576
        synthesizeEmptyInterfaceIfMissing(autoCloseableType);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   577
        synthesizeEmptyInterfaceIfMissing(cloneableType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   578
        synthesizeEmptyInterfaceIfMissing(serializableType);
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   579
        synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15361
diff changeset
   580
        synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 30066
diff changeset
   581
        synthesizeEmptyInterfaceIfMissing(stringConcatFactory);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   582
        synthesizeBoxTypeIfMissing(doubleType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   583
        synthesizeBoxTypeIfMissing(floatType);
3555
a6fd77fe81df 6390045: Unexpected error "cannot access java.lang.Void" with '-target cldc1.0' with -source >=1.5
mcimadamore
parents: 2723
diff changeset
   584
        synthesizeBoxTypeIfMissing(voidType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
5848
c5a4ce47e780 6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5847
diff changeset
   586
        // Enter a synthetic class that is used to mark internal
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        // proprietary classes in ct.sym.  This class does not have a
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        // class file.
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   589
        proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   590
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   591
        // Enter a synthetic class that is used to provide profile info for
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   592
        // classes in ct.sym.  This class does not have a class file.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   593
        profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   594
        MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   595
        profileType.tsym.members().enter(m);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        // Enter a class for arrays.
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        // The class implements java.lang.Cloneable and java.io.Serializable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        // It has a final length field and a clone method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        ClassType arrayClassType = (ClassType)arrayClass.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        arrayClassType.supertype_field = objectType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
   603
        arrayClass.members_field = WriteableScope.create(arrayClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        lengthVar = new VarSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            PUBLIC | FINAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            names.length,
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
        arrayClass.members().enter(lengthVar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
        arrayCloneMethod = new MethodSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
            PUBLIC,
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            names.clone,
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   613
            new MethodType(List.nil(), objectType,
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   614
                           List.nil(), methodClass),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        arrayClass.members().enter(arrayCloneMethod);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   617
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   618
        if (java_base != noModule)
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41999
diff changeset
   619
            java_base.completer = moduleCompleter::complete; //bootstrap issues
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   620
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
    }
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   622
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   623
    /** Define a new class given its name and owner.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   624
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   625
    public ClassSymbol defineClass(Name name, Symbol owner) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   626
        ClassSymbol c = new ClassSymbol(0, name, owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   627
        c.completer = initialCompleter;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   628
        return c;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   629
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   630
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   631
    /** Create a new toplevel or member class symbol with given name
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   632
     *  and owner and enter in `classes' unless already there.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   633
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   634
    public ClassSymbol enterClass(ModuleSymbol msym, Name name, TypeSymbol owner) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   635
        Assert.checkNonNull(msym);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   636
        Name flatname = TypeSymbol.formFlatName(name, owner);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   637
        ClassSymbol c = getClass(msym, flatname);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   638
        if (c == null) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   639
            c = defineClass(name, owner);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   640
            doEnterClass(msym, c);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   641
        } else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   642
            // reassign fields of classes that might have been loaded with
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   643
            // their flat names.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   644
            c.owner.members().remove(c);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   645
            c.name = name;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   646
            c.owner = owner;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   647
            c.fullname = ClassSymbol.formFullName(name, owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   648
        }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   649
        return c;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   650
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   651
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   652
    public ClassSymbol getClass(ModuleSymbol msym, Name flatName) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41999
diff changeset
   653
        Assert.checkNonNull(msym, flatName::toString);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   654
        return classes.getOrDefault(flatName, Collections.emptyMap()).get(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   655
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   656
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   657
    public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   658
        Assert.checkNonNull(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   659
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   660
        if (flatName.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   661
            //unnamed packages only from the current module - visiblePackages contains *root* package, not unnamed package!
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   662
            return msym.unnamedPackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   663
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   664
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   665
        if (msym == noModule) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   666
            return enterPackage(msym, flatName);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   667
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   668
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   669
        msym.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   670
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   671
        PackageSymbol pack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   672
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   673
        pack = msym.visiblePackages.get(flatName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   674
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   675
        if (pack != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   676
            return pack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   677
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   678
        pack = getPackage(msym, flatName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   679
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   680
        if (pack != null && pack.exists())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   681
            return pack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   682
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   683
        boolean dependsOnUnnamed = msym.requires != null &&
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   684
                                   msym.requires.stream()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   685
                                                .map(rd -> rd.module)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   686
                                                .anyMatch(mod -> mod == unnamedModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   687
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   688
        if (dependsOnUnnamed) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   689
            //msyms depends on the unnamed module, for which we generally don't know
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   690
            //the list of packages it "exports" ahead of time. So try to lookup the package in the
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   691
            //current module, and in the unnamed module and see if it exists in one of them
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   692
            PackageSymbol unnamedPack = getPackage(unnamedModule, flatName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   693
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   694
            if (unnamedPack != null && unnamedPack.exists()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   695
                msym.visiblePackages.put(unnamedPack.fullname, unnamedPack);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   696
                return unnamedPack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   697
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   698
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   699
            pack = enterPackage(msym, flatName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   700
            pack.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   701
            if (pack.exists())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   702
                return pack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   703
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   704
            unnamedPack = enterPackage(unnamedModule, flatName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   705
            unnamedPack.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   706
            if (unnamedPack.exists()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   707
                msym.visiblePackages.put(unnamedPack.fullname, unnamedPack);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   708
                return unnamedPack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   709
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   710
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   711
            return pack;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   712
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   713
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   714
        return enterPackage(msym, flatName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   715
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   716
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   717
    private static final Map<ModuleSymbol, ClassSymbol> EMPTY = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   718
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   719
    public void removeClass(ModuleSymbol msym, Name flatName) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   720
        classes.getOrDefault(flatName, EMPTY).remove(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   721
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   722
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   723
    public Iterable<ClassSymbol> getAllClasses() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   724
        return () -> Iterators.createCompoundIterator(classes.values(), v -> v.values().iterator());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   725
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   726
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   727
    private void doEnterClass(ModuleSymbol msym, ClassSymbol cs) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   728
        classes.computeIfAbsent(cs.flatname, n -> new HashMap<>()).put(msym, cs);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   729
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   730
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   731
    /** Create a new member or toplevel class symbol with given flat name
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   732
     *  and enter in `classes' unless already there.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   733
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   734
    public ClassSymbol enterClass(ModuleSymbol msym, Name flatname) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   735
        Assert.checkNonNull(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   736
        PackageSymbol ps = lookupPackage(msym, Convert.packagePart(flatname));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   737
        Assert.checkNonNull(ps);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   738
        Assert.checkNonNull(ps.modle);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   739
        ClassSymbol c = getClass(ps.modle, flatname);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   740
        if (c == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   741
            c = defineClass(Convert.shortName(flatname), ps);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   742
            doEnterClass(ps.modle, c);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   743
            return c;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   744
        } else
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   745
            return c;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   746
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   747
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   748
    /** Check to see if a package exists, given its fully qualified name.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   749
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   750
    public boolean packageExists(ModuleSymbol msym, Name fullname) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   751
        Assert.checkNonNull(msym);
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36996
diff changeset
   752
        return lookupPackage(msym, fullname).exists();
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   753
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   754
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   755
    /** Make a package, given its fully qualified name.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   756
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   757
    public PackageSymbol enterPackage(ModuleSymbol currModule, Name fullname) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   758
        Assert.checkNonNull(currModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   759
        PackageSymbol p = getPackage(currModule, fullname);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   760
        if (p == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   761
            Assert.check(!fullname.isEmpty(), () -> "rootPackage missing!; currModule: " + currModule);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   762
            p = new PackageSymbol(
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   763
                    Convert.shortName(fullname),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   764
                    enterPackage(currModule, Convert.packagePart(fullname)));
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   765
            p.completer = initialCompleter;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   766
            p.modle = currModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   767
            doEnterPackage(currModule, p);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   768
        }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   769
        return p;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   770
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   771
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   772
    private void doEnterPackage(ModuleSymbol msym, PackageSymbol pack) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   773
        packages.computeIfAbsent(pack.fullname, n -> new HashMap<>()).put(msym, pack);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   774
        msym.enclosedPackages = msym.enclosedPackages.prepend(pack);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   775
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   776
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   777
    private void addRootPackageFor(ModuleSymbol module) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   778
        doEnterPackage(module, rootPackage);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   779
        PackageSymbol unnamedPackage = new PackageSymbol(names.empty, rootPackage) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   780
                @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   781
                public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   782
                    return messages.getLocalizedString("compiler.misc.unnamed.package");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   783
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   784
            };
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   785
        unnamedPackage.modle = module;
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41999
diff changeset
   786
        //we cannot use a method reference below, as initialCompleter might be null now
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41999
diff changeset
   787
        unnamedPackage.completer = s -> initialCompleter.complete(s);
59058
3f57daa2d6eb 8234025: Elements.getPackageElement(ModuleElement,CharSequence) returns null for unnamed package
jjg
parents: 58713
diff changeset
   788
        unnamedPackage.flags_field |= EXISTS;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   789
        module.unnamedPackage = unnamedPackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   790
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   791
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   792
    public PackageSymbol getPackage(ModuleSymbol module, Name fullname) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   793
        return packages.getOrDefault(fullname, Collections.emptyMap()).get(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   794
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   795
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   796
    public ModuleSymbol enterModule(Name name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   797
        ModuleSymbol msym = modules.get(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   798
        if (msym == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   799
            msym = ModuleSymbol.create(name, names.module_info);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   800
            addRootPackageFor(msym);
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41999
diff changeset
   801
            msym.completer = s -> moduleCompleter.complete(s); //bootstrap issues
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   802
            modules.put(name, msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   803
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   804
        return msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   805
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   806
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   807
    public ModuleSymbol getModule(Name name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   808
        return modules.get(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   809
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   810
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   811
    //temporary:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   812
    public ModuleSymbol inferModule(Name packageName) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   813
        if (packageName.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   814
            return java_base == noModule ? noModule : unnamedModule;//!
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   815
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   816
        ModuleSymbol msym = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   817
        Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   818
        if (map == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   819
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   820
        for (Map.Entry<ModuleSymbol,PackageSymbol> e: map.entrySet()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   821
            if (!e.getValue().members().isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   822
                if (msym == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   823
                    msym = e.getKey();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   824
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   825
                    return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   826
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   827
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   828
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   829
        return msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   830
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   831
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   832
    public List<ModuleSymbol> listPackageModules(Name packageName) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   833
        if (packageName.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   834
            return List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   835
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   836
        List<ModuleSymbol> result = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   837
        Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   838
        if (map != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   839
            for (Map.Entry<ModuleSymbol, PackageSymbol> e: map.entrySet()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   840
                if (!e.getValue().members().isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   841
                    result = result.prepend(e.getKey());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   842
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   843
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   844
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   845
        return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   846
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   847
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   848
    public Collection<ModuleSymbol> getAllModules() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
   849
        return modules.values();
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   850
    }
43272
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   851
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   852
    public Iterable<ClassSymbol> getClassesForName(Name candidate) {
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   853
        return classes.getOrDefault(candidate, Collections.emptyMap()).values();
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   854
    }
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   855
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   856
    public Iterable<PackageSymbol> getPackagesForName(Name candidate) {
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   857
        return packages.getOrDefault(candidate, Collections.emptyMap()).values();
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43131
diff changeset
   858
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
}