langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java
author jlahoda
Mon, 24 Nov 2014 16:02:35 +0100
changeset 27854 22b4bfc4e22f
parent 27231 c1ca668b421e
child 27857 7e913a535736
permissions -rw-r--r--
8032211: Don't issue deprecation warnings on import statements 6598104: javac should not warn about imports of deprecated classes Summary: Suppressing the deprecation warnings when importing a deprecated element (deprecations in import qualifier will be produced). Reviewed-by: darcy, jjg, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
     2
 * Copyright (c) 2003, 2014, 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: 4877
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: 4877
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: 4877
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
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.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
    28
import java.util.Collections;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    29
import java.util.HashSet;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
    30
import java.util.IdentityHashMap;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.Set;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    32
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.code.*;
27854
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
    36
import com.sun.tools.javac.code.Lint.LintCategory;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
    37
import com.sun.tools.javac.code.Scope.ImportFilter;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
    38
import com.sun.tools.javac.code.Scope.NamedImportScope;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
    39
import com.sun.tools.javac.code.Scope.StarImportScope;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
    40
import com.sun.tools.javac.code.Scope.WriteableScope;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.util.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    44
import com.sun.tools.javac.util.DefinedBy.Api;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 24604
diff changeset
    46
import com.sun.tools.javac.code.Symbol.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import static com.sun.tools.javac.code.Flags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
    51
import static com.sun.tools.javac.code.Flags.ANNOTATION;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    52
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import static com.sun.tools.javac.code.Kinds.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    54
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
    55
import static com.sun.tools.javac.code.TypeTag.CLASS;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    56
import static com.sun.tools.javac.code.TypeTag.ERROR;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    57
import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
    58
import static com.sun.tools.javac.tree.JCTree.Tag.*;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24396
diff changeset
    59
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
    60
import com.sun.tools.javac.util.Dependencies.AttributionKind;
11709
0d56d3fc22e6 7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents: 10950
diff changeset
    61
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
/** This is the second phase of Enter, in which classes are completed
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  by entering their members into the class scope using
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  MemberEnter.complete().  See Enter for an overview.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    68
 *  <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
    69
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
public class MemberEnter extends JCTree.Visitor implements Completer {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21498
diff changeset
    74
    protected static final Context.Key<MemberEnter> memberEnterKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /** A switch to determine whether we check for package/class conflicts
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    final static boolean checkClash = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
    80
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    private final Enter enter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private final Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    private final Attr attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    private final Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    private final TreeMaker make;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    private final Todo todo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    private final Annotate annotate;
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
    89
    private final TypeAnnotations typeAnnotations;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    private final Types types;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
    91
    private final JCDiagnostic.Factory diags;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
    92
    private final Source source;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    private final Target target;
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
    94
    private final DeferredLintHandler deferredLintHandler;
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
    95
    private final Lint lint;
25007
eb097d3a68f5 8038975: Access control in enhanced for
pgovereau
parents: 24903
diff changeset
    96
    private final TypeEnvs typeEnvs;
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
    97
    private final Dependencies dependencies;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    public static MemberEnter instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        MemberEnter instance = context.get(memberEnterKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            instance = new MemberEnter(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    protected MemberEnter(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        context.put(memberEnterKey, this);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
   108
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        enter = Enter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        attr = Attr.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        todo = Todo.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        annotate = Annotate.instance(context);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   117
        typeAnnotations = TypeAnnotations.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        types = Types.instance(context);
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   119
        diags = JCDiagnostic.Factory.instance(context);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   120
        source = Source.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        target = Target.instance(context);
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   122
        deferredLintHandler = DeferredLintHandler.instance(context);
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   123
        lint = Lint.instance(context);
25007
eb097d3a68f5 8038975: Access control in enhanced for
pgovereau
parents: 24903
diff changeset
   124
        typeEnvs = TypeEnvs.instance(context);
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
   125
        dependencies = Dependencies.instance(context);
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   126
        allowTypeAnnos = source.allowTypeAnnotations();
27854
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   127
        allowDeprecationOnImport = source.allowDeprecationOnImport();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   130
    /** Switch: support type annotations.
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   131
     */
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   132
    boolean allowTypeAnnos;
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   133
27854
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   134
    /**
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   135
     * Switch: should deprecation warnings be issued on import
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   136
     */
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   137
    boolean allowDeprecationOnImport;
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   138
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /** A queue for classes whose members still need to be entered into the
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     *  symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21498
diff changeset
   142
    ListBuffer<Env<AttrContext>> halfcompleted = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /** Set to true only when the first of a set of classes is
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   145
     *  processed from the half completed queue.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    boolean isFirst = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /** A flag to disable completion from time to time during member
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     *  enter, as we only need to look up types.  This avoids
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     *  unnecessarily deep recursion.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    boolean completionEnabled = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    /* ---------- Processing import clauses ----------------
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    /** Import all classes of a class or package on demand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     *  @param tsym          The class or package the members of which are imported.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14058
diff changeset
   161
     *  @param env           The env in which the imported classes will be entered.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    private void importAll(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                           final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                           Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        // Check that packages imported from exist (JLS ???).
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   167
        if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
            // If we can't find java.lang, exit immediately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
            if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   170
                JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                throw new FatalError(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            } else {
11709
0d56d3fc22e6 7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents: 10950
diff changeset
   173
                log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   176
        env.toplevel.starImportScope.importAll(tsym.members(), tsym.members(), typeImportFilter, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    /** Import all static members of a class or package on demand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *  @param tsym          The class or package the members of which are imported.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14058
diff changeset
   182
     *  @param env           The env in which the imported classes will be entered.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    private void importStaticAll(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                                 final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                                 Env<AttrContext> env) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   187
        final StarImportScope toScope = env.toplevel.starImportScope;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        final PackageSymbol packge = env.toplevel.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        final TypeSymbol origin = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        // enter imported types immediately
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   192
        new SymbolImporter() {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   193
            void doImport(TypeSymbol tsym) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   194
                toScope.importAll(tsym.members(), origin.members(), staticImportFilter, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        }.importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    /** Import statics types of a given name.  Non-types are handled in Attr.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *  @param tsym          The class from which the name is imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     *  @param name          The (simple) name being imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     *  @param env           The environment containing the named import
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     *                  scope to add to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    private void importNamedStatic(final DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                                   final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                                   final Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                                   final Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        if (tsym.kind != TYP) {
12917
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents: 12916
diff changeset
   211
            log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   215
        final NamedImportScope toScope = env.toplevel.namedImportScope;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   216
        final Scope originMembers = tsym.members();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        // enter imported types immediately
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   219
        new SymbolImporter() {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   220
            void doImport(TypeSymbol tsym) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   221
                Set<Symbol> maskedOut = null;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   222
                for (Symbol sym : tsym.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   223
                    if (sym.kind == TYP &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   224
                        staticImportFilter.accepts(originMembers, sym) &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   225
                        !chk.checkUniqueStaticImport(pos, env.toplevel, sym)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   226
                        if (maskedOut == null)
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   227
                            maskedOut = Collections.newSetFromMap(new IdentityHashMap<Symbol, Boolean>());
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   228
                        maskedOut.add(sym);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   229
                    }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   230
                }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   231
                ImportFilter importFilter = maskedOut != null ?
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   232
                        new MaskedImportFilter(staticImportFilter, maskedOut) :
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   233
                        staticImportFilter;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   234
                toScope.importByName(tsym.members(), originMembers, name, importFilter);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   235
            }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   236
        }.importFrom(tsym);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   237
    }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   238
    //where:
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   239
        class MaskedImportFilter implements ImportFilter {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   240
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   241
            private final ImportFilter delegate;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   242
            private final Set<Symbol> maskedOut;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   243
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   244
            public MaskedImportFilter(ImportFilter delegate, Set<Symbol> maskedOut) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   245
                this.delegate = delegate;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   246
                this.maskedOut = maskedOut;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   247
            }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   248
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   249
            @Override
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   250
            public boolean accepts(Scope origin, Symbol sym) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   251
                return !maskedOut.contains(sym) && delegate.accepts(origin, sym);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   252
            }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   253
        }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   254
        abstract class SymbolImporter {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21498
diff changeset
   255
            Set<Symbol> processed = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   265
                doImport(tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
            }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   267
            abstract void doImport(TypeSymbol tsym);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   268
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    /** Import given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     *  @param tsym          The class to be imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     *  @param env           The environment containing the named import
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     *                  scope to add to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   276
    private void importNamed(DiagnosticPosition pos, final Symbol tsym, Env<AttrContext> env) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        if (tsym.kind == TYP &&
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   278
            chk.checkUniqueImport(pos, env.toplevel, tsym))
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   279
            env.toplevel.namedImportScope.importType(tsym.owner.members(), tsym.owner.members(), tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    /** Construct method type from method signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     *  @param typarams    The method's type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     *  @param params      The method's value parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     *  @param res             The method's result type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     *                 null if it is a constructor.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   287
     *  @param recvparam       The method's receiver parameter,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   288
     *                 null if none given; TODO: or already set here?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     *  @param thrown      The method's thrown exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     *  @param env             The method's (local) environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   292
    Type signature(MethodSymbol msym,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   293
                   List<JCTypeParameter> typarams,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   294
                   List<JCVariableDecl> params,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   295
                   JCTree res,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   296
                   JCVariableDecl recvparam,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   297
                   List<JCExpression> thrown,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   298
                   Env<AttrContext> env) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        // Enter and attribute type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        List<Type> tvars = enter.classEnter(typarams, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        attr.attribTypeVariables(typarams, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   304
        // Enter and attribute value parameters.
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21498
diff changeset
   305
        ListBuffer<Type> argbuf = new ListBuffer<>();
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   306
        for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   307
            memberEnter(l.head, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            argbuf.append(l.head.vartype.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        // Attribute result type, if one is given.
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   312
        Type restype = res == null ? syms.voidType : attr.attribType(res, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   314
        // Attribute receiver type, if one is given.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   315
        Type recvtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   316
        if (recvparam!=null) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   317
            memberEnter(recvparam, env);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   318
            recvtype = recvparam.vartype.type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   319
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   320
            recvtype = null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   321
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   322
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        // Attribute thrown exceptions.
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21498
diff changeset
   324
        ListBuffer<Type> thrownbuf = new ListBuffer<>();
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   325
        for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            Type exc = attr.attribType(l.head, env);
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   327
            if (!exc.hasTag(TYPEVAR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                exc = chk.checkClassType(l.head.pos(), exc);
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   329
            } else if (exc.tsym.owner == msym) {
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   330
                //mark inference variables in 'throws' clause
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   331
                exc.tsym.flags_field |= THROWS;
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   332
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            thrownbuf.append(exc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   335
        MethodType mtype = new MethodType(argbuf.toList(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                                    restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                                    thrownbuf.toList(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                                    syms.methodClass);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   339
        mtype.recvtype = recvtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   340
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
 * Visitor methods for member enter
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   348
    ImportFilter staticImportFilter;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   349
    ImportFilter typeImportFilter = new ImportFilter() {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   350
        @Override
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   351
        public boolean accepts(Scope origin, Symbol t) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   352
            return t.kind == TYP;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   353
        }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   354
    };
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   355
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   356
    protected void memberEnter(JCCompilationUnit tree, Env<AttrContext> env) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   357
        ImportFilter prevStaticImportFilter = staticImportFilter;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   358
        try {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   359
            final PackageSymbol packge = env.toplevel.packge;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   360
            this.staticImportFilter = new ImportFilter() {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   361
                @Override
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   362
                public boolean accepts(Scope origin, Symbol sym) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   363
                    return sym.isStatic() &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   364
                           chk.staticImportAccessible(sym, packge) &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   365
                           sym.isMemberOf((TypeSymbol) origin.owner, types);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   366
                }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   367
            };
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   368
            memberEnter((JCTree) tree, env);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   369
        } finally {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   370
            this.staticImportFilter = prevStaticImportFilter;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   371
        }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   372
    }
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   373
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    /** Visitor argument: the current environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    protected Env<AttrContext> env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    /** Enter field and method definitions and process import
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
     *  clauses, catching any completion failure exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   381
    protected void memberEnter(JCTree tree, Env<AttrContext> env) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        Env<AttrContext> prevEnv = this.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        }  catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            this.env = prevEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    /** Enter members from a list of trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   395
    void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   397
            memberEnter(l.head, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    /** Enter members for a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   402
    void finishClass(JCClassDecl tree, Env<AttrContext> env) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        if ((tree.mods.flags & Flags.ENUM) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            addEnumMembers(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        }
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   407
        memberEnter(tree.defs, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    /** Add the implicit members for an enum type
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
     *  to the symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26532
diff changeset
   414
        JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        // public static T[] values() { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        JCMethodDecl values = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
                      names.values,
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
                      valuesType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                      List.<JCTypeParameter>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
                      List.<JCVariableDecl>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                      List.<JCExpression>nil(), // thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                      null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        memberEnter(values, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        // public static T valueOf(String name) { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        JCMethodDecl valueOf = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
                      names.valueOf,
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
                      make.Type(tree.sym.type),
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
                      List.<JCTypeParameter>nil(),
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15385
diff changeset
   434
                      List.of(make.VarDef(make.Modifiers(Flags.PARAMETER |
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15385
diff changeset
   435
                                                         Flags.MANDATED),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
                                            names.fromString("name"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
                                            make.Type(syms.stringType), null)),
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
                      List.<JCExpression>nil(), // thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                      null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        memberEnter(valueOf, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
    public void visitTopLevel(JCCompilationUnit tree) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   445
        if (!tree.starImportScope.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            // we must have already processed this toplevel
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   450
        DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   451
        Lint prevLint = chk.setLint(lint);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   452
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   453
        try {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   454
            // Import-on-demand java.lang.
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   455
            importAll(tree.pos, syms.enterPackage(names.java_lang), env);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   456
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   457
            // Process the package def and all import clauses.
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   458
            memberEnter(tree.defs, env);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   459
        } finally {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   460
            chk.setLint(prevLint);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   461
            deferredLintHandler.setPos(prevLintPos);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   462
        }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   463
    }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   464
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   465
    public void visitPackageDef(JCPackageDecl tree) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        // check that no class exists with same fully qualified name as
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        // toplevel package
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        if (checkClash && tree.pid != null) {
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23129
diff changeset
   469
            Symbol p = env.toplevel.packge;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            while (p.owner != syms.rootPackage) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                p.owner.complete(); // enter all class members of p
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
                if (syms.classes.get(p.getQualifiedName()) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                    log.error(tree.pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                              "pkg.clashes.with.class.of.same.name",
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
                              p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                p = p.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        // process package annotations
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   481
        annotate.annotateLater(tree.annotations, env, env.toplevel.packge, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
    // process the non-static imports and the static imports of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    public void visitImport(JCImport tree) {
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
   486
        dependencies.push(AttributionKind.IMPORT, tree);
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   487
        JCFieldAccess imp = (JCFieldAccess)tree.qualid;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        Name name = TreeInfo.name(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        // Create a local environment pointing to this tree to disable
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        // effects of other imports in Resolve.findGlobalType
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        Env<AttrContext> localEnv = env.dup(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   494
        TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        if (name == names.asterisk) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            // Import on demand.
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   497
            chk.checkCanonical(imp.selected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            if (tree.staticImport)
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
                importStaticAll(tree.pos, p, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                importAll(tree.pos, p, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            // Named type import.
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
            if (tree.staticImport) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                importNamedStatic(tree.pos(), p, name, localEnv);
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   506
                chk.checkCanonical(imp.selected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                TypeSymbol c = attribImportType(imp, localEnv).tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
                chk.checkCanonical(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
                importNamed(tree.pos(), c, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        }
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
   513
        dependencies.pop();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
    public void visitMethodDef(JCMethodDecl tree) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   517
        WriteableScope enclScope = enter.enterScope(env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        tree.sym = m;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   521
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   522
        //if this is a default method, add the DEFAULT flag to the enclosing interface
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   523
        if ((tree.mods.flags & DEFAULT) != 0) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   524
            m.enclClass().flags_field |= DEFAULT;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   525
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   526
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        Env<AttrContext> localEnv = methodEnv(tree, env);
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   528
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   529
        try {
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   530
            // Compute the method type
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   531
            m.type = signature(m, tree.typarams, tree.params,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   532
                               tree.restype, tree.recvparam,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   533
                               tree.thrown,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   534
                               localEnv);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   535
        } finally {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   536
            deferredLintHandler.setPos(prevLintPos);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   537
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   539
        if (types.isSignaturePolymorphic(m)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   540
            m.flags_field |= SIGNATURE_POLYMORPHIC;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   541
        }
18389
a425d0819f36 8016569: javac, add new flag for polymorphic method signatures
vromero
parents: 18010
diff changeset
   542
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   543
        // Set m.params
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   544
        ListBuffer<VarSymbol> params = new ListBuffer<>();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   545
        JCVariableDecl lastParam = null;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   546
        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   547
            JCVariableDecl param = lastParam = l.head;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   548
            params.append(Assert.checkNonNull(param.sym));
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   549
        }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   550
        m.params = params.toList();
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   551
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   552
        // mark the method varargs, if necessary
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   553
        if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   554
            m.flags_field |= Flags.VARARGS;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   556
        localEnv.info.scope.leave();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   557
        if (chk.checkUnique(tree.pos(), m, enclScope)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   558
        enclScope.enter(m);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   559
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   561
        annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   562
        // Visit the signature of the method. Note that
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   563
        // TypeAnnotate doesn't descend into the body.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   564
        annotate.annotateTypeLater(tree, localEnv, m, tree.pos());
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   565
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   566
        if (tree.defaultValue != null)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   567
            annotateDefaultValueLater(tree.defaultValue, localEnv, m);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    /** Create a fresh environment for method bodies.
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
     *  @param tree     The method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
     *  @param env      The environment current outside of the method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
    Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
        Env<AttrContext> localEnv =
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   576
            env.dup(tree, env.info.dup(env.info.scope.dupUnshared(tree.sym)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        localEnv.enclMethod = tree;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   578
        if (tree.sym.type != null) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   579
            //when this is called in the enter stage, there's no type to be set
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   580
            localEnv.info.returnResult = attr.new ResultInfo(KindSelector.VAL,
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   581
                                                             tree.sym.type.getReturnType());
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   582
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        Env<AttrContext> localEnv = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        if ((tree.mods.flags & STATIC) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            (env.info.scope.owner.flags() & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            localEnv = env.dup(tree, env.info.dup());
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        }
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   594
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   595
        try {
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   596
            if (TreeInfo.isEnumInit(tree)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   597
                attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   598
            } else {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   599
                attr.attribType(tree.vartype, localEnv);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   600
                if (TreeInfo.isReceiverParam(tree))
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   601
                    checkReceiver(tree, localEnv);
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   602
            }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   603
        } finally {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   604
            deferredLintHandler.setPos(prevLintPos);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   605
        }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   606
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   607
        if ((tree.mods.flags & VARARGS) != 0) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   608
            //if we are entering a varargs parameter, we need to
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   609
            //replace its type (a plain array type) with the more
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   610
            //precise VarargsType --- we need to do it this way
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   611
            //because varargs is represented in the tree as a
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   612
            //modifier on the parameter declaration, and not as a
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   613
            //distinct type of array node.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   614
            ArrayType atype = (ArrayType)tree.vartype.type;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   615
            tree.vartype.type = atype.makeVarargs();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   616
        }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   617
        WriteableScope enclScope = enter.enterScope(env);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   618
        VarSymbol v =
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   619
            new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   620
        v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   621
        tree.sym = v;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   622
        if (tree.init != null) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   623
            v.flags_field |= HASINIT;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   624
            if ((v.flags_field & FINAL) != 0 &&
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   625
                needsLazyConstValue(tree.init)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   626
                Env<AttrContext> initEnv = getInitEnv(tree, env);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   627
                initEnv.info.enclVar = v;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   628
                v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
12916
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   629
            }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   630
        }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   631
        if (chk.checkUnique(tree.pos(), v, enclScope)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   632
            chk.checkTransparentVar(tree.pos(), v, enclScope);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   633
            enclScope.enter(v);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   634
        }
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   635
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   636
        annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   637
        annotate.annotateTypeLater(tree.vartype, localEnv, v, tree.pos());
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   638
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   639
        v.pos = tree.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
    }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   641
    // where
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   642
    void checkType(JCTree tree, Type type, String diag) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   643
        if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   644
            log.error(tree, diag, type, tree.type);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   645
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   646
    }
24903
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   647
    void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) {
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   648
        attr.attribExpr(tree.nameexpr, localEnv);
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   649
        MethodSymbol m = localEnv.enclMethod.sym;
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   650
        if (m.isConstructor()) {
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   651
            Type outertype = m.owner.owner.type;
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   652
            if (outertype.hasTag(TypeTag.METHOD)) {
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   653
                // we have a local inner class
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   654
                outertype = m.owner.owner.owner.type;
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   655
            }
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   656
            if (outertype.hasTag(TypeTag.CLASS)) {
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   657
                checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   658
                checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   659
            } else {
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   660
                log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   661
            }
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   662
        } else {
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   663
            checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   664
            checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   665
        }
41e1812d6b4c 8027886: javac allows illegal receiver parameters
pgovereau
parents: 24895
diff changeset
   666
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
19656
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   668
    public boolean needsLazyConstValue(JCTree tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   669
        InitTreeVisitor initTreeVisitor = new InitTreeVisitor();
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   670
        tree.accept(initTreeVisitor);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   671
        return initTreeVisitor.result;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   672
    }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   673
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   674
    /** Visitor class for expressions which might be constant expressions.
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   675
     */
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   676
    static class InitTreeVisitor extends JCTree.Visitor {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   677
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   678
        private boolean result = true;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   679
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   680
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   681
        public void visitTree(JCTree tree) {}
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   682
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   683
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   684
        public void visitNewClass(JCNewClass that) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   685
            result = false;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   686
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   687
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   688
        @Override
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   689
        public void visitNewArray(JCNewArray that) {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   690
            result = false;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   691
        }
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   692
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   693
        @Override
19656
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   694
        public void visitLambda(JCLambda that) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   695
            result = false;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   696
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   697
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   698
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   699
        public void visitReference(JCMemberReference that) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   700
            result = false;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   701
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   702
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   703
        @Override
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   704
        public void visitApply(JCMethodInvocation that) {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   705
            result = false;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   706
        }
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   707
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   708
        @Override
19656
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   709
        public void visitSelect(JCFieldAccess tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   710
            tree.selected.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   711
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   712
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   713
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   714
        public void visitConditional(JCConditional tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   715
            tree.cond.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   716
            tree.truepart.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   717
            tree.falsepart.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   718
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   719
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   720
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   721
        public void visitParens(JCParens tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   722
            tree.expr.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   723
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   724
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   725
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   726
        public void visitTypeCast(JCTypeCast tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   727
            tree.expr.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   728
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   729
    }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   730
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
    /** Create a fresh environment for a variable's initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
     *  If the variable is a field, the owner of the environment's scope
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
     *  is be the variable itself, otherwise the owner is the method
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
     *  enclosing the variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
     *  @param tree     The variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
     *  @param env      The environment current outside of the variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
    Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
        if (tree.sym.owner.kind == TYP) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
   742
            localEnv.info.scope = env.info.scope.dupUnshared(tree.sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
        if ((tree.mods.flags & STATIC) != 0 ||
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   745
                ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
            localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
    /** Default member enter visitor method: do nothing
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
    public void visitTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
    public void visitErroneous(JCErroneous tree) {
6929
81a6a7c1bef1 6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents: 6721
diff changeset
   756
        if (tree.errs != null)
81a6a7c1bef1 6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents: 6721
diff changeset
   757
            memberEnter(tree.errs, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
    public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
        Env<AttrContext> mEnv = methodEnv(tree, env);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
   762
        mEnv.info.lint = mEnv.info.lint.augment(tree.sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
        for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
            mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            mEnv.info.scope.enterIfAbsent(l.head.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
        return mEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
    public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        Env<AttrContext> iEnv = initEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        return iEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
 * Type completion
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
    Type attribImportType(JCTree tree, Env<AttrContext> env) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   780
        Assert.check(completionEnabled);
27854
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   781
        Lint prevLint = chk.setLint(allowDeprecationOnImport ?
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   782
                lint : lint.suppress(LintCategory.DEPRECATION));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
            // To prevent deep recursion, suppress completion of some
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            // types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            completionEnabled = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
            return attr.attribType(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
            completionEnabled = true;
27854
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27231
diff changeset
   790
            chk.setLint(prevLint);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
     * Check if a list of annotations contains a reference to
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
     * java.lang.Deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
    private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   799
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
            JCAnnotation a = al.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
            if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
    /** Queue processing of an attribute default value. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
    void annotateDefaultValueLater(final JCExpression defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                                   final Env<AttrContext> localEnv,
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   810
                                   final MethodSymbol m) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   811
        annotate.normal(new Annotate.Worker() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   812
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
                    return "annotate " + m.owner + "." +
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
                        m + " default " + defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   817
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   818
                @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   819
                public void run() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
                    JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
                        enterDefaultValue(defaultValue, localEnv, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
                    } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
                        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
            });
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   828
        annotate.validate(new Annotate.Worker() { //validate annotations
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   829
            @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   830
            public void run() {
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   831
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   832
                try {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   833
                    // if default value is an annotation, check it is a well-formed
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   834
                    // annotation value (e.g. no duplicate values, no missing values, etc.)
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   835
                    chk.validateAnnotationTree(defaultValue);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   836
                } finally {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   837
                    log.useSource(prev);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   838
                }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   839
            }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   840
        });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
    /** Enter a default value for an attribute method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
    private void enterDefaultValue(final JCExpression defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
                                   final Env<AttrContext> localEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
                                   final MethodSymbol m) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
                                                      defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
                                                      localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
 * Source completer
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
    /** Complete entering a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
     *  @param sym         The symbol of the class to be completed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
    public void complete(Symbol sym) throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
        // Suppress some (recursive) MemberEnter invocations
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
        if (!completionEnabled) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
            // Re-install same completer for next time around and return.
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   863
            Assert.check((sym.flags() & Flags.COMPOUND) == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            sym.completer = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   868
        try {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   869
            annotate.enterStart();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   870
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   871
            ClassSymbol c = (ClassSymbol)sym;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   872
            ClassType ct = (ClassType)c.type;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   873
            Env<AttrContext> env = typeEnvs.get(c);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   874
            JCClassDecl tree = (JCClassDecl)env.tree;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   875
            boolean wasFirst = isFirst;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   876
            isFirst = false;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   877
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   878
            JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   879
            DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   880
            try {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   881
                dependencies.push(c);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   882
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   883
                // Save class environment for later member enter (2) processing.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   884
                halfcompleted.append(env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   886
                // Mark class as not yet attributed.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   887
                c.flags_field |= UNATTRIBUTED;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   888
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   889
                // If this is a toplevel-class, make sure any preceding import
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   890
                // clauses have been seen.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   891
                if (c.owner.kind == PCK) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   892
                    memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   893
                    todo.append(env);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   894
                }
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
   895
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   896
                if (c.owner.kind == TYP)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   897
                    c.owner.complete();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   898
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   899
                // create an environment for evaluating the base clauses
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   900
                Env<AttrContext> baseEnv = baseEnv(tree, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   902
                if (tree.extending != null)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   903
                    annotate.annotateTypeLater(tree.extending, baseEnv, sym, tree.pos());
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   904
                for (JCExpression impl : tree.implementing)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   905
                    annotate.annotateTypeLater(impl, baseEnv, sym, tree.pos());
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   906
                annotate.flush();
1043
11ea4773b0af 6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents: 1040
diff changeset
   907
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   908
                // Determine supertype.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   909
                Type supertype;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   910
                if (tree.extending != null) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   911
                    dependencies.push(AttributionKind.EXTENDS, tree.extending);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   912
                    try {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   913
                        supertype = attr.attribBase(tree.extending, baseEnv,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   914
                                true, false, true);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   915
                    } finally {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   916
                        dependencies.pop();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   917
                    }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   918
                } else {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   919
                    supertype = ((tree.mods.flags & Flags.ENUM) != 0)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   920
                    ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   921
                                      true, false, false)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   922
                    : (c.fullname == names.java_lang_Object)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   923
                    ? Type.noType
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   924
                    : syms.objectType;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   925
                }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   926
                ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   928
                // Determine interfaces.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   929
                ListBuffer<Type> interfaces = new ListBuffer<>();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   930
                ListBuffer<Type> all_interfaces = null; // lazy init
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   931
                Set<Type> interfaceSet = new HashSet<>();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   932
                List<JCExpression> interfaceTrees = tree.implementing;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   933
                for (JCExpression iface : interfaceTrees) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   934
                    dependencies.push(AttributionKind.IMPLEMENTS, iface);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   935
                    try {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   936
                        Type it = attr.attribBase(iface, baseEnv, false, true, true);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   937
                        if (it.hasTag(CLASS)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   938
                            interfaces.append(it);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   939
                            if (all_interfaces != null) all_interfaces.append(it);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   940
                            chk.checkNotRepeated(iface.pos(), types.erasure(it), interfaceSet);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   941
                        } else {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   942
                            if (all_interfaces == null)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   943
                                all_interfaces = new ListBuffer<Type>().appendList(interfaces);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   944
                            all_interfaces.append(modelMissingTypes(it, iface, true));
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   945
                        }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   946
                    } finally {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   947
                        dependencies.pop();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   948
                    }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   949
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   950
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   951
                if ((c.flags_field & ANNOTATION) != 0) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   952
                    ct.interfaces_field = List.of(syms.annotationType);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   953
                    ct.all_interfaces_field = ct.interfaces_field;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   954
                }  else {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   955
                    ct.interfaces_field = interfaces.toList();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   956
                    ct.all_interfaces_field = (all_interfaces == null)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   957
                            ? ct.interfaces_field : all_interfaces.toList();
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 24604
diff changeset
   958
                }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   959
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   960
                if (c.fullname == names.java_lang_Object) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   961
                    if (tree.extending != null) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   962
                        chk.checkNonCyclic(tree.extending.pos(),
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   963
                                           supertype);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   964
                        ct.supertype_field = Type.noType;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   965
                    }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   966
                    else if (tree.implementing.nonEmpty()) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   967
                        chk.checkNonCyclic(tree.implementing.head.pos(),
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   968
                                           ct.interfaces_field.head);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   969
                        ct.interfaces_field = List.nil();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   970
                    }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   971
                }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   972
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   973
                // Annotations.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   974
                // In general, we cannot fully process annotations yet,  but we
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   975
                // can attribute the annotation types and then check to see if the
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   976
                // @Deprecated annotation is present.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   977
                attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   978
                if (hasDeprecatedAnnotation(tree.mods.annotations))
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   979
                    c.flags_field |= DEPRECATED;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   980
                annotate.annotateLater(tree.mods.annotations, baseEnv,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   981
                            c, tree.pos());
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   982
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   983
                chk.checkNonCyclicDecl(tree);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   984
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   985
                // class type parameters use baseEnv but everything uses env
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   986
                attr.attribTypeVariables(tree.typarams, baseEnv);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   987
                for (JCTypeParameter tp : tree.typarams)
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   988
                    annotate.annotateTypeLater(tp, baseEnv, sym, tree.pos());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   990
                // Add default constructor if needed.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   991
                if ((c.flags() & INTERFACE) == 0 &&
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   992
                    !TreeInfo.hasConstructors(tree.defs)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   993
                    List<Type> argtypes = List.nil();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   994
                    List<Type> typarams = List.nil();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   995
                    List<Type> thrown = List.nil();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   996
                    long ctorFlags = 0;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   997
                    boolean based = false;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   998
                    boolean addConstructor = true;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
   999
                    JCNewClass nc = null;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1000
                    if (c.name.isEmpty()) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1001
                        nc = (JCNewClass)env.next.tree;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1002
                        if (nc.constructor != null) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1003
                            addConstructor = nc.constructor.kind != ERR;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1004
                            Type superConstrType = types.memberType(c.type,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1005
                                                                    nc.constructor);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1006
                            argtypes = superConstrType.getParameterTypes();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1007
                            typarams = superConstrType.getTypeArguments();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1008
                            ctorFlags = nc.constructor.flags() & VARARGS;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1009
                            if (nc.encl != null) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1010
                                argtypes = argtypes.prepend(nc.encl.type);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1011
                                based = true;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1012
                            }
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1013
                            thrown = superConstrType.getThrownTypes();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1014
                        }
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25443
diff changeset
  1015
                    }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1016
                    if (addConstructor) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1017
                        MethodSymbol basedConstructor = nc != null ?
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1018
                                (MethodSymbol)nc.constructor : null;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1019
                        JCTree constrDef = DefaultConstructor(make.at(tree.pos), c,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1020
                                                            basedConstructor,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1021
                                                            typarams, argtypes, thrown,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1022
                                                            ctorFlags, based);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1023
                        tree.defs = tree.defs.prepend(constrDef);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1024
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
                }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 24604
diff changeset
  1026
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1027
                // enter symbols for 'this' into current scope.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1028
                VarSymbol thisSym =
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1029
                    new VarSymbol(FINAL | HASINIT, names._this, c.type, c);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1030
                thisSym.pos = Position.FIRSTPOS;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1031
                env.info.scope.enter(thisSym);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1032
                // if this is a class, enter symbol for 'super' into current scope.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1033
                if ((c.flags_field & INTERFACE) == 0 &&
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1034
                        ct.supertype_field.hasTag(CLASS)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1035
                    VarSymbol superSym =
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1036
                        new VarSymbol(FINAL | HASINIT, names._super,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1037
                                      ct.supertype_field, c);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1038
                    superSym.pos = Position.FIRSTPOS;
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1039
                    env.info.scope.enter(superSym);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1040
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1042
                // check that no package exists with same fully qualified name,
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1043
                // but admit classes in the unnamed package which have the same
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1044
                // name as a top-level package.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1045
                if (checkClash &&
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1046
                    c.owner.kind == PCK && c.owner != syms.unnamedPackage &&
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1047
                    syms.packageExists(c.fullname)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1048
                    log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
                }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1050
                if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 &&
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1051
                    !env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1052
                    c.flags_field |= AUXILIARY;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
                }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1054
            } catch (CompletionFailure ex) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1055
                chk.completionError(tree.pos(), ex);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1056
            } finally {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1057
                deferredLintHandler.setPos(prevLintPos);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1058
                log.useSource(prev);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1059
                dependencies.pop();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1062
            // Enter all member fields and methods of a set of half completed
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1063
            // classes in a second phase.
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1064
            if (wasFirst) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1065
                Set<JCCompilationUnit> topLevels = new HashSet<>();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1066
                try {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1067
                    while (halfcompleted.nonEmpty()) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1068
                        Env<AttrContext> toFinish = halfcompleted.next();
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1069
                        topLevels.add(toFinish.toplevel);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1070
                        finish(toFinish);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1071
                        if (allowTypeAnnos) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1072
                            typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1073
                            typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
                    }
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1076
                } finally {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1077
                    isFirst = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1080
                for (JCCompilationUnit toplevel : topLevels) {
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1081
                    chk.checkImportsResolvable(toplevel);
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1082
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
14369
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1084
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
        } finally {
27231
c1ca668b421e 8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents: 27224
diff changeset
  1086
            annotate.enterDone();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1087
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1088
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
    private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
  1091
        WriteableScope baseScope = WriteableScope.create(tree.sym);
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1092
        //import already entered local classes into base scope
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
  1093
        for (Symbol sym : env.outer.info.scope.getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
  1094
            if (sym.isLocal()) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25007
diff changeset
  1095
                baseScope.enter(sym);
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1096
            }
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1097
        }
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1098
        //import current type-parameters into base scope
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
        if (tree.typarams != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
            for (List<JCTypeParameter> typarams = tree.typarams;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
                 typarams.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
                 typarams = typarams.tail)
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1103
                baseScope.enter(typarams.head.type.tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
        Env<AttrContext> outer = env.outer; // the base clause can't see members of this class
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1105
        Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
        localEnv.baseClause = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
        localEnv.outer = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        localEnv.info.isSelfCall = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
    /** Enter member fields and methods of a class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
     *  @param env        the environment current for the class block.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
    private void finish(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
            JCClassDecl tree = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
            finishClass(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
    /** Generate a base clause for an enum type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
     *  @param pos              The position for trees and diagnostics, if any
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
     *  @param c                The class symbol of the enum
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
    private JCExpression enumBase(int pos, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
        JCExpression result = make.at(pos).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
            TypeApply(make.QualIdent(syms.enumSym),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
                      List.<JCExpression>of(make.Type(c.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1136
    Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1137
        if (!t.hasTag(ERROR))
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1138
            return t;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1139
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21010
diff changeset
  1140
        return new ErrorType(t.getOriginalType(), t.tsym) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1141
            private Type modelType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1142
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1143
            @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1144
            public Type getModelType() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1145
                if (modelType == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1146
                    modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1147
                return modelType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1148
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1149
        };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1150
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1151
    // where
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1152
    private class Synthesizer extends JCTree.Visitor {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1153
        Type originalType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1154
        boolean interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1155
        List<ClassSymbol> synthesizedSymbols = List.nil();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1156
        Type result;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1157
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1158
        Synthesizer(Type originalType, boolean interfaceExpected) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1159
            this.originalType = originalType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1160
            this.interfaceExpected = interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1161
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1162
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1163
        Type visit(JCTree tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1164
            tree.accept(this);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1165
            return result;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1166
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1167
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1168
        List<Type> visit(List<? extends JCTree> trees) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21498
diff changeset
  1169
            ListBuffer<Type> lb = new ListBuffer<>();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1170
            for (JCTree t: trees)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1171
                lb.append(visit(t));
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1172
            return lb.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1173
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1174
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1175
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1176
        public void visitTree(JCTree tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1177
            result = syms.errType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1178
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1179
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1180
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1181
        public void visitIdent(JCIdent tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1182
            if (!tree.type.hasTag(ERROR)) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1183
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1184
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1185
                result = synthesizeClass(tree.name, syms.unnamedPackage).type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1186
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1187
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1188
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1189
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1190
        public void visitSelect(JCFieldAccess tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1191
            if (!tree.type.hasTag(ERROR)) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1192
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1193
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1194
                Type selectedType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1195
                boolean prev = interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1196
                try {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1197
                    interfaceExpected = false;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1198
                    selectedType = visit(tree.selected);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1199
                } finally {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1200
                    interfaceExpected = prev;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1201
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1202
                ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1203
                result = c.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1204
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1205
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1206
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1207
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1208
        public void visitTypeApply(JCTypeApply tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1209
            if (!tree.type.hasTag(ERROR)) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1210
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1211
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1212
                ClassType clazzType = (ClassType) visit(tree.clazz);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1213
                if (synthesizedSymbols.contains(clazzType.tsym))
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1214
                    synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1215
                final List<Type> actuals = visit(tree.arguments);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1216
                result = new ErrorType(tree.type, clazzType.tsym) {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1217
                    @Override @DefinedBy(Api.LANGUAGE_MODEL)
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1218
                    public List<Type> getTypeArguments() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1219
                        return actuals;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1220
                    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1221
                };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1222
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1223
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1224
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1225
        ClassSymbol synthesizeClass(Name name, Symbol owner) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1226
            int flags = interfaceExpected ? INTERFACE : 0;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1227
            ClassSymbol c = new ClassSymbol(flags, name, owner);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1228
            c.members_field = new Scope.ErrorScope(c);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1229
            c.type = new ErrorType(originalType, c) {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1230
                @Override @DefinedBy(Api.LANGUAGE_MODEL)
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1231
                public List<Type> getTypeArguments() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1232
                    return typarams_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1233
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1234
            };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1235
            synthesizedSymbols = synthesizedSymbols.prepend(c);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1236
            return c;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1237
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1238
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1239
        void synthesizeTyparams(ClassSymbol sym, int n) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1240
            ClassType ct = (ClassType) sym.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1241
            Assert.check(ct.typarams_field.isEmpty());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1242
            if (n == 1) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26532
diff changeset
  1243
                TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1244
                ct.typarams_field = ct.typarams_field.prepend(v);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1245
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1246
                for (int i = n; i > 0; i--) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24069
diff changeset
  1247
                    TypeVar v = new TypeVar(names.fromString("T" + i), sym,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26532
diff changeset
  1248
                                            syms.botType);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1249
                    ct.typarams_field = ct.typarams_field.prepend(v);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1250
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1251
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1252
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1253
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1254
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1255
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
 * tree building
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
    /** Generate default constructor for given class. For classes different
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
     *  from java.lang.Object, this is:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
     *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
     *      super(x_0, ..., x_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
     *    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
     *  or, if based == true:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
     *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
     *      x_0.super(x_1, ..., x_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
     *    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
     *  @param make     The tree factory.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
     *  @param c        The class owning the default constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
     *  @param argtypes The parameter types of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
     *  @param thrown   The thrown exceptions of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
     *  @param based    Is first parameter a this$n?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
    JCTree DefaultConstructor(TreeMaker make,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
                            ClassSymbol c,
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1281
                            MethodSymbol baseInit,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
                            List<Type> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
                            List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
                            List<Type> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
                            long flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
                            boolean based) {
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1287
        JCTree result;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        if ((c.flags() & ENUM) != 0 &&
16558
07c08ad4a700 8010179: Remove transitional target values from javac
darcy
parents: 15720
diff changeset
  1289
            (types.supertype(c.type).tsym == syms.enumSym)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
            // constructors of true enums are private
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
            flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
            flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1294
        if (c.name.isEmpty()) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1295
            flags |= ANONCONSTR;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1296
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1297
        Type mType = new MethodType(argtypes, null, thrown, c);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1298
        Type initType = typarams.nonEmpty() ?
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24069
diff changeset
  1299
            new ForAll(typarams, mType) :
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24069
diff changeset
  1300
            mType;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1301
        MethodSymbol init = new MethodSymbol(flags, names.init,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1302
                initType, c);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1303
        init.params = createDefaultConstructorParams(make, baseInit, init,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1304
                argtypes, based);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1305
        List<JCVariableDecl> params = make.Params(argtypes, init);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1306
        List<JCStatement> stats = List.nil();
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1307
        if (c.type != syms.objectType) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1308
            stats = stats.prepend(SuperCall(make, typarams, params, based));
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1309
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1310
        result = make.MethodDef(init, make.Block(0, stats));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1314
    private List<VarSymbol> createDefaultConstructorParams(
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1315
            TreeMaker make,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1316
            MethodSymbol baseInit,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1317
            MethodSymbol init,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1318
            List<Type> argtypes,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1319
            boolean based) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1320
        List<VarSymbol> initParams = null;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1321
        List<Type> argTypesList = argtypes;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1322
        if (based) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1323
            /*  In this case argtypes will have an extra type, compared to baseInit,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1324
             *  corresponding to the type of the enclosing instance i.e.:
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1325
             *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1326
             *  Inner i = outer.new Inner(1){}
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1327
             *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1328
             *  in the above example argtypes will be (Outer, int) and baseInit
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1329
             *  will have parameter's types (int). So in this case we have to add
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1330
             *  first the extra type in argtypes and then get the names of the
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1331
             *  parameters from baseInit.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1332
             */
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1333
            initParams = List.nil();
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19656
diff changeset
  1334
            VarSymbol param = new VarSymbol(PARAMETER, make.paramName(0), argtypes.head, init);
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1335
            initParams = initParams.append(param);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1336
            argTypesList = argTypesList.tail;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1337
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1338
        if (baseInit != null && baseInit.params != null &&
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1339
            baseInit.params.nonEmpty() && argTypesList.nonEmpty()) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1340
            initParams = (initParams == null) ? List.<VarSymbol>nil() : initParams;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1341
            List<VarSymbol> baseInitParams = baseInit.params;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1342
            while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) {
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19656
diff changeset
  1343
                VarSymbol param = new VarSymbol(baseInitParams.head.flags() | PARAMETER,
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1344
                        baseInitParams.head.name, argTypesList.head, init);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1345
                initParams = initParams.append(param);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1346
                baseInitParams = baseInitParams.tail;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1347
                argTypesList = argTypesList.tail;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1348
            }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1349
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1350
        return initParams;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1351
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1352
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
    /** Generate call to superclass constructor. This is:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
     *    super(id_0, ..., id_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
     * or, if based == true
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
     *    id_0.super(id_1,...,id_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
     *  where id_0, ..., id_n are the names of the given parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
     *  @param make    The tree factory
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
     *  @param params  The parameters that need to be passed to super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
     *  @param typarams  The type parameters that need to be passed to super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
     *  @param based   Is first parameter a this$n?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
    JCExpressionStatement SuperCall(TreeMaker make,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
                   List<Type> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
                   List<JCVariableDecl> params,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
                   boolean based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
        JCExpression meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
        if (based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
            meth = make.Select(make.Ident(params.head), names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
            params = params.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
            meth = make.Ident(names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
        List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
        return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
}