langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
author mcimadamore
Thu, 04 Oct 2012 13:04:53 +0100
changeset 14057 b4b0377b8dba
parent 14051 9097cec96212
child 14058 c7ec7facdd20
permissions -rw-r--r--
7177387: Add target-typing support in method context Summary: Add support for deferred types and speculative attribution Reviewed-by: jjg, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12081
diff changeset
     2
 * Copyright (c) 2003, 2012, 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
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import static com.sun.tools.javac.code.Flags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
    43
import static com.sun.tools.javac.code.Flags.ANNOTATION;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import static com.sun.tools.javac.code.TypeTags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
    46
import static com.sun.tools.javac.tree.JCTree.Tag.*;
11709
0d56d3fc22e6 7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents: 10950
diff changeset
    47
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
/** This is the second phase of Enter, in which classes are completed
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  by entering their members into the class scope using
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  MemberEnter.complete().  See Enter for an overview.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    54
 *  <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
    55
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
public class MemberEnter extends JCTree.Visitor implements Completer {
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    protected static final Context.Key<MemberEnter> memberEnterKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        new Context.Key<MemberEnter>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /** A switch to determine whether we check for package/class conflicts
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    final static boolean checkClash = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
    67
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private final Enter enter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    private final Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private final Attr attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private final Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private final TreeMaker make;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    private final ClassReader reader;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    private final Todo todo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private final Annotate annotate;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    private final Types types;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
    78
    private final JCDiagnostic.Factory diags;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
    79
    private final Source source;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private final Target target;
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
    81
    private final DeferredLintHandler deferredLintHandler;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    public static MemberEnter instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        MemberEnter instance = context.get(memberEnterKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            instance = new MemberEnter(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    protected MemberEnter(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        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
    92
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        enter = Enter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        attr = Attr.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        reader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        todo = Todo.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        annotate = Annotate.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        types = Types.instance(context);
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   103
        diags = JCDiagnostic.Factory.instance(context);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   104
        source = Source.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        target = Target.instance(context);
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   106
        deferredLintHandler = DeferredLintHandler.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /** A queue for classes whose members still need to be entered into the
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     *  symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    ListBuffer<Env<AttrContext>> halfcompleted = new ListBuffer<Env<AttrContext>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /** Set to true only when the first of a set of classes is
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     *  processed from the halfcompleted queue.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    boolean isFirst = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** A flag to disable completion from time to time during member
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     *  enter, as we only need to look up types.  This avoids
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     *  unnecessarily deep recursion.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    boolean completionEnabled = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /* ---------- Processing import clauses ----------------
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /** Import all classes of a class or package on demand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     *  @param tsym          The class or package the members of which are imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     *  @param toScope   The (import) scope in which imported classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     *               are entered.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    private void importAll(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                           final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                           Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        // Check that packages imported from exist (JLS ???).
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            // If we can't find java.lang, exit immediately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            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
   141
                JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                throw new FatalError(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            } else {
11709
0d56d3fc22e6 7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents: 10950
diff changeset
   144
                log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        }
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents: 6929
diff changeset
   147
        env.toplevel.starImportScope.importAll(tsym.members());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /** Import all static members of a class or package on demand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     *  @param tsym          The class or package the members of which are imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *  @param toScope   The (import) scope in which imported classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *               are entered.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    private void importStaticAll(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                                 final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                                 Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        final JavaFileObject sourcefile = env.toplevel.sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        final Scope toScope = env.toplevel.starImportScope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        final PackageSymbol packge = env.toplevel.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        final TypeSymbol origin = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        // enter imported types immediately
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        new Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                final Scope fromScope = tsym.members();
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                    if (sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
                        (sym.flags() & STATIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                        sym.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                        !toScope.includes(sym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                        toScope.enter(sym, fromScope, origin.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        }.importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        // enter non-types before annotations that might use them
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        annotate.earlier(new Annotate.Annotator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                return "import static " + tsym + ".*" + " in " + sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
                final Scope fromScope = tsym.members();
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                    if (sym.isStatic() && sym.kind != TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                        !toScope.includes(sym) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                        sym.isMemberOf(origin, types)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                        toScope.enter(sym, fromScope, origin.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            public void enterAnnotation() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    // is the sym accessible everywhere in packge?
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    boolean staticImportAccessible(Symbol sym, PackageSymbol packge) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        int flags = (int)(sym.flags() & AccessFlags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        switch (flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            return sym.packge() == packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    /** Import statics types of a given name.  Non-types are handled in Attr.
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     *  @param tsym          The class from which the name is imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     *  @param name          The (simple) name being imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     *  @param env           The environment containing the named import
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     *                  scope to add to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    private void importNamedStatic(final DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                                   final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                                   final Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                                   final Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        if (tsym.kind != TYP) {
12917
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents: 12916
diff changeset
   249
            log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        final Scope toScope = env.toplevel.namedImportScope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        final PackageSymbol packge = env.toplevel.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        final TypeSymbol origin = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        // enter imported types immediately
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        new Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                for (Scope.Entry e = tsym.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                    if (sym.isStatic() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                        sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                        sym.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                        chk.checkUniqueStaticImport(pos, sym, toScope))
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                        toScope.enter(sym, sym.owner.members(), origin.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        }.importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        // enter non-types before annotations that might use them
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        annotate.earlier(new Annotate.Annotator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            boolean found = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                return "import static " + tsym + "." + name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                for (Scope.Entry e = tsym.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                    if (sym.isStatic() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                        sym.isMemberOf(origin, types)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                        found = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                        if (sym.kind == MTH ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                            sym.kind != TYP && chk.checkUniqueStaticImport(pos, sym, toScope))
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                            toScope.enter(sym, sym.owner.members(), origin.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            public void enterAnnotation() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
                    importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
                    if (!found) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                        log.error(pos, "cant.resolve.location",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   320
                                  KindName.STATIC,
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   321
                                  name, List.<Type>nil(), List.<Type>nil(),
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   322
                                  Kinds.typeKindName(tsym.type),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
                                  tsym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                    log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    /** Import given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     *  @param tsym          The class to be imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     *  @param env           The environment containing the named import
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     *                  scope to add to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        if (tsym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope))
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            env.toplevel.namedImportScope.enter(tsym, tsym.owner.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    /** Construct method type from method signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     *  @param typarams    The method's type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     *  @param params      The method's value parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     *  @param res             The method's result type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     *                 null if it is a constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     *  @param thrown      The method's thrown exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     *  @param env             The method's (local) environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    Type signature(List<JCTypeParameter> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                   List<JCVariableDecl> params,
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                   JCTree res,
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                   List<JCExpression> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                   Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        // Enter and attribute type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        List<Type> tvars = enter.classEnter(typarams, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        attr.attribTypeVariables(typarams, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        // Enter and attribute value parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        ListBuffer<Type> argbuf = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
            memberEnter(l.head, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            argbuf.append(l.head.vartype.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        // Attribute result type, if one is given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        Type restype = res == null ? syms.voidType : attr.attribType(res, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        // Attribute thrown exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        ListBuffer<Type> thrownbuf = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            Type exc = attr.attribType(l.head, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            if (exc.tag != TYPEVAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                exc = chk.checkClassType(l.head.pos(), exc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            thrownbuf.append(exc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        Type mtype = new MethodType(argbuf.toList(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                                    restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                                    thrownbuf.toList(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                                    syms.methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
 * Visitor methods for member enter
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    /** Visitor argument: the current environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    protected Env<AttrContext> env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    /** Enter field and method definitions and process import
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     *  clauses, catching any completion failure exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    protected void memberEnter(JCTree tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        Env<AttrContext> prevEnv = this.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        }  catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            this.env = prevEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    /** Enter members from a list of trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            memberEnter(l.head, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    /** Enter members for a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    void finishClass(JCClassDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        if ((tree.mods.flags & Flags.ENUM) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            addEnumMembers(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        memberEnter(tree.defs, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
    /** Add the implicit members for an enum type
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     *  to the symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass));
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        // public static T[] values() { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        JCMethodDecl values = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
                      names.values,
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
                      valuesType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
                      List.<JCTypeParameter>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
                      List.<JCVariableDecl>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                      List.<JCExpression>nil(), // thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
                      null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        memberEnter(values, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        // public static T valueOf(String name) { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        JCMethodDecl valueOf = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                      names.valueOf,
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
                      make.Type(tree.sym.type),
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                      List.<JCTypeParameter>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
                      List.of(make.VarDef(make.Modifiers(Flags.PARAMETER),
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
                                            names.fromString("name"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
                                            make.Type(syms.stringType), null)),
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
                      List.<JCExpression>nil(), // thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
                      null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        memberEnter(valueOf, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        // the remaining members are for bootstrapping only
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        if (!target.compilerBootstrap(tree.sym)) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        // public final int ordinal() { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        JCMethodDecl ordinal = make.at(tree.pos).
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
                      names.ordinal,
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
                      make.Type(syms.intType),
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
                      List.<JCTypeParameter>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
                      List.<JCVariableDecl>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
                      List.<JCExpression>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
                      null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        memberEnter(ordinal, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        // public final String name() { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        JCMethodDecl name = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
                      names._name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                      make.Type(syms.stringType),
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
                      List.<JCTypeParameter>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
                      List.<JCVariableDecl>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
                      List.<JCExpression>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
                      null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        memberEnter(name, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        // public int compareTo(E other) { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        MethodSymbol compareTo = new
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
            MethodSymbol(Flags.PUBLIC,
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
                         names.compareTo,
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
                         new MethodType(List.of(tree.sym.type),
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
                                        syms.intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                                        List.<Type>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
                                        syms.methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                         tree.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        memberEnter(make.MethodDef(compareTo, null), env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    public void visitTopLevel(JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        if (tree.starImportScope.elems != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
            // we must have already processed this toplevel
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        // check that no class exists with same fully qualified name as
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        // toplevel package
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        if (checkClash && tree.pid != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            Symbol p = tree.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
            while (p.owner != syms.rootPackage) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                p.owner.complete(); // enter all class members of p
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
                if (syms.classes.get(p.getQualifiedName()) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
                    log.error(tree.pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
                              "pkg.clashes.with.class.of.same.name",
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
                              p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
                p = p.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        // process package annotations
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        annotateLater(tree.packageAnnotations, env, tree.packge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        // Import-on-demand java.lang.
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        importAll(tree.pos, reader.enterPackage(names.java_lang), env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        // Process all import clauses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        memberEnter(tree.defs, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
    // process the non-static imports and the static imports of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
    public void visitImport(JCImport tree) {
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   530
        JCFieldAccess imp = (JCFieldAccess)tree.qualid;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        Name name = TreeInfo.name(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        // Create a local environment pointing to this tree to disable
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        // effects of other imports in Resolve.findGlobalType
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        Env<AttrContext> localEnv = env.dup(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   537
        TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        if (name == names.asterisk) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            // Import on demand.
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   540
            chk.checkCanonical(imp.selected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
            if (tree.staticImport)
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
                importStaticAll(tree.pos, p, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
                importAll(tree.pos, p, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            // Named type import.
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
            if (tree.staticImport) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
                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
   549
                chk.checkCanonical(imp.selected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
                TypeSymbol c = attribImportType(imp, localEnv).tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
                chk.checkCanonical(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                importNamed(tree.pos(), c, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
    public void visitMethodDef(JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        Scope enclScope = enter.enterScope(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        tree.sym = m;
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        Env<AttrContext> localEnv = methodEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   565
        DeferredLintHandler prevLintHandler =
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   566
                chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   567
        try {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   568
            // Compute the method type
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   569
            m.type = signature(tree.typarams, tree.params,
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   570
                               tree.restype, tree.thrown,
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   571
                               localEnv);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   572
        } finally {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   573
            chk.setDeferredLintHandler(prevLintHandler);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   574
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        // Set m.params
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
        JCVariableDecl lastParam = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
            JCVariableDecl param = lastParam = l.head;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   581
            params.append(Assert.checkNonNull(param.sym));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        m.params = params.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        // mark the method varargs, if necessary
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            m.flags_field |= Flags.VARARGS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        localEnv.info.scope.leave();
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        if (chk.checkUnique(tree.pos(), m, enclScope)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            enclScope.enter(m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        annotateLater(tree.mods.annotations, localEnv, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        if (tree.defaultValue != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            annotateDefaultValueLater(tree.defaultValue, localEnv, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
    /** Create a fresh environment for method bodies.
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
     *  @param tree     The method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
     *  @param env      The environment current outside of the method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
    Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        Env<AttrContext> localEnv =
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            env.dup(tree, env.info.dup(env.info.scope.dupUnshared()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        localEnv.enclMethod = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
        localEnv.info.scope.owner = tree.sym;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   607
        if (tree.sym.type != null) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   608
            //when this is called in the enter stage, there's no type to be set
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   609
            localEnv.info.returnResult = attr.new ResultInfo(VAL, tree.sym.type.getReturnType());
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   610
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        Env<AttrContext> localEnv = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
        if ((tree.mods.flags & STATIC) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
            (env.info.scope.owner.flags() & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            localEnv = env.dup(tree, env.info.dup());
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
            localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        }
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   622
        DeferredLintHandler prevLintHandler =
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   623
                chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   624
        try {
12916
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   625
            if (TreeInfo.isEnumInit(tree)) {
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   626
                attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   627
            } else {
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   628
                attr.attribType(tree.vartype, localEnv);
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   629
            }
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   630
        } finally {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   631
            chk.setDeferredLintHandler(prevLintHandler);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   632
        }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   633
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   634
        if ((tree.mods.flags & VARARGS) != 0) {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   635
            //if we are entering a varargs parameter, we need to replace its type
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   636
            //(a plain array type) with the more precise VarargsType --- we need
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   637
            //to do it this way because varargs is represented in the tree as a modifier
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   638
            //on the parameter declaration, and not as a distinct type of array node.
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   639
            ArrayType atype = (ArrayType)tree.vartype.type;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   640
            tree.vartype.type = atype.makeVarargs();
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   641
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        Scope enclScope = enter.enterScope(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        VarSymbol v =
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        tree.sym = v;
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        if (tree.init != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            v.flags_field |= HASINIT;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
   649
            if ((v.flags_field & FINAL) != 0 && !tree.init.hasTag(NEWCLASS)) {
1045
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 1043
diff changeset
   650
                Env<AttrContext> initEnv = getInitEnv(tree, env);
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 1043
diff changeset
   651
                initEnv.info.enclVar = v;
8225
e9e5670e6a71 6554097: "final" confuses @SuppressWarnings
jjg
parents: 8045
diff changeset
   652
                v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init);
1045
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 1043
diff changeset
   653
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        if (chk.checkUnique(tree.pos(), v, enclScope)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
            chk.checkTransparentVar(tree.pos(), v, enclScope);
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            enclScope.enter(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
        annotateLater(tree.mods.annotations, localEnv, v);
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
        v.pos = tree.pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
    /** Create a fresh environment for a variable's initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
     *  If the variable is a field, the owner of the environment's scope
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
     *  is be the variable itself, otherwise the owner is the method
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
     *  enclosing the variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
     *  @param tree     The variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
     *  @param env      The environment current outside of the variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
    Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
        if (tree.sym.owner.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
            localEnv.info.scope = new Scope.DelegatedScope(env.info.scope);
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
            localEnv.info.scope.owner = tree.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        if ((tree.mods.flags & STATIC) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
            (env.enclClass.sym.flags() & INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
            localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
    /** Default member enter visitor method: do nothing
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
    public void visitTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
    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
   689
        if (tree.errs != null)
81a6a7c1bef1 6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents: 6721
diff changeset
   690
            memberEnter(tree.errs, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
    public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
        Env<AttrContext> mEnv = methodEnv(tree, env);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   695
        mEnv.info.lint = mEnv.info.lint.augment(tree.sym.annotations, tree.sym.flags());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            mEnv.info.scope.enterIfAbsent(l.head.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
        return mEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
    public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
        Env<AttrContext> iEnv = initEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        return iEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
 * Type completion
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
    Type attribImportType(JCTree tree, Env<AttrContext> env) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   713
        Assert.check(completionEnabled);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            // To prevent deep recursion, suppress completion of some
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            // types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            completionEnabled = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
            return attr.attribType(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
            completionEnabled = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
 * Annotation processing
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
    /** Queue annotations for later processing. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
    void annotateLater(final List<JCAnnotation> annotations,
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
                       final Env<AttrContext> localEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
                       final Symbol s) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   732
        if (annotations.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   733
            return;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   734
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   735
        if (s.kind != PCK) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   736
            s.annotations.reset(); // mark Annotations as incomplete for now
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   737
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   738
        annotate.normal(new Annotate.Annotator() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   739
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
                    return "annotate " + annotations + " onto " + s + " in " + s.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   743
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   744
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
                public void enterAnnotation() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   746
                    Assert.check(s.kind == PCK || s.annotations.pendingCompletion());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
                    JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
                    try {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   749
                        if (!s.annotations.isEmpty() &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
                            annotations.nonEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
                            log.error(annotations.head.pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
                                      "already.annotated",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   753
                                      kindName(s), s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
                        enterAnnotations(annotations, localEnv, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
                    } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
                        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            });
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
     * Check if a list of annotations contains a reference to
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
     * java.lang.Deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
    private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   767
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
            JCAnnotation a = al.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
    /** Enter a set of annotations. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
    private void enterAnnotations(List<JCAnnotation> annotations,
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
                          Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                          Symbol s) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   779
        Map<TypeSymbol, ListBuffer<Attribute.Compound>> annotated =
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   780
                new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.Compound>>();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   781
        Map<Attribute.Compound, DiagnosticPosition> pos =
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   782
                new HashMap<Attribute.Compound, DiagnosticPosition>();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   783
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   784
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            JCAnnotation a = al.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            Attribute.Compound c = annotate.enterAnnotation(a,
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
                                                            syms.annotationType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
                                                            env);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   789
            if (c == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   790
                continue;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   791
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   792
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   793
            if (annotated.containsKey(a.type.tsym)) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   794
                if (source.allowRepeatedAnnotations()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   795
                    ListBuffer<Attribute.Compound> l = annotated.get(a.type.tsym);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   796
                    l = l.append(c);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   797
                    annotated.put(a.type.tsym, l);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   798
                    pos.put(c, a.pos());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   799
                } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   800
                    log.error(a.pos(), "duplicate.annotation");
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   801
                }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   802
            } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   803
                annotated.put(a.type.tsym, ListBuffer.of(c));
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   804
                pos.put(c, a.pos());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   805
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   806
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            // Note: @Deprecated has no effect on local variables and parameters
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
            if (!c.type.isErroneous()
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                && s.owner.kind != MTH
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   810
                && types.isSameType(c.type, syms.deprecatedType)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
                s.flags_field |= Flags.DEPRECATED;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   812
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   814
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   815
        s.annotations.setAttributesWithCompletion(
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   816
                annotate.new AnnotateRepeatedContext(env, annotated, pos, log));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
    /** Queue processing of an attribute default value. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
    void annotateDefaultValueLater(final JCExpression defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
                                   final Env<AttrContext> localEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
                                   final MethodSymbol m) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   823
        annotate.normal(new Annotate.Annotator() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   824
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
                    return "annotate " + m.owner + "." +
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
                        m + " default " + defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   829
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   830
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
                public void enterAnnotation() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
                    JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
                        enterDefaultValue(defaultValue, localEnv, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
                    } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
                        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
            });
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
    /** Enter a default value for an attribute method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
    private void enterDefaultValue(final JCExpression defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                                   final Env<AttrContext> localEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
                                   final MethodSymbol m) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
        m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
                                                      defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
                                                      localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
 * Source completer
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
    /** Complete entering a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
     *  @param sym         The symbol of the class to be completed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
    public void complete(Symbol sym) throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
        // Suppress some (recursive) MemberEnter invocations
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
        if (!completionEnabled) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
            // Re-install same completer for next time around and return.
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   862
            Assert.check((sym.flags() & Flags.COMPOUND) == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            sym.completer = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
        ClassSymbol c = (ClassSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
        ClassType ct = (ClassType)c.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
        Env<AttrContext> env = enter.typeEnvs.get(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
        JCClassDecl tree = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
        boolean wasFirst = isFirst;
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
        isFirst = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
            // Save class environment for later member enter (2) processing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
            halfcompleted.append(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
1043
11ea4773b0af 6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents: 1040
diff changeset
   879
            // Mark class as not yet attributed.
11ea4773b0af 6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents: 1040
diff changeset
   880
            c.flags_field |= UNATTRIBUTED;
11ea4773b0af 6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents: 1040
diff changeset
   881
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
            // If this is a toplevel-class, make sure any preceding import
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
            // clauses have been seen.
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
            if (c.owner.kind == PCK) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
   885
                memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
                todo.append(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
            if (c.owner.kind == TYP)
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
                c.owner.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
            // create an environment for evaluating the base clauses
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
            Env<AttrContext> baseEnv = baseEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
            // Determine supertype.
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
            Type supertype =
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
                (tree.extending != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                ? attr.attribBase(tree.extending, baseEnv, true, false, true)
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
                : ((tree.mods.flags & Flags.ENUM) != 0 && !target.compilerBootstrap(c))
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
                ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
                                  true, false, false)
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
                : (c.fullname == names.java_lang_Object)
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
                ? Type.noType
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
                : syms.objectType;
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   905
            ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            // Determine interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            ListBuffer<Type> interfaces = new ListBuffer<Type>();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   909
            ListBuffer<Type> all_interfaces = null; // lazy init
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
            Set<Type> interfaceSet = new HashSet<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
            List<JCExpression> interfaceTrees = tree.implementing;
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
            if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
                // add interface Comparable<T>
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
                interfaceTrees =
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
                    interfaceTrees.prepend(make.Type(new ClassType(syms.comparableType.getEnclosingType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
                                                                   List.of(c.type),
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
                                                                   syms.comparableType.tsym)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
                // add interface Serializable
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
                interfaceTrees =
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
                    interfaceTrees.prepend(make.Type(syms.serializableType));
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
            for (JCExpression iface : interfaceTrees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
                Type i = attr.attribBase(iface, baseEnv, false, true, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
                if (i.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
                    interfaces.append(i);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   926
                    if (all_interfaces != null) all_interfaces.append(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
                    chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   928
                } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   929
                    if (all_interfaces == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   930
                        all_interfaces = new ListBuffer<Type>().appendList(interfaces);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   931
                    all_interfaces.append(modelMissingTypes(i, iface, true));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
            }
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   934
            if ((c.flags_field & ANNOTATION) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
                ct.interfaces_field = List.of(syms.annotationType);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   936
                ct.all_interfaces_field = ct.interfaces_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   937
            }  else {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
                ct.interfaces_field = interfaces.toList();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   939
                ct.all_interfaces_field = (all_interfaces == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   940
                        ? ct.interfaces_field : all_interfaces.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
   941
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
            if (c.fullname == names.java_lang_Object) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                if (tree.extending != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
                    chk.checkNonCyclic(tree.extending.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                                       supertype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                    ct.supertype_field = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
                else if (tree.implementing.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
                    chk.checkNonCyclic(tree.implementing.head.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
                                       ct.interfaces_field.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
                    ct.interfaces_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
            // Annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
            // In general, we cannot fully process annotations yet,  but we
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
            // can attribute the annotation types and then check to see if the
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
            // @Deprecated annotation is present.
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
            attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
            if (hasDeprecatedAnnotation(tree.mods.annotations))
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
                c.flags_field |= DEPRECATED;
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
            annotateLater(tree.mods.annotations, baseEnv, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
6711
fc9732adc790 6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents: 6709
diff changeset
   965
            chk.checkNonCyclicDecl(tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
165
1875ac59896a 6663588: Compiler goes into infinite loop for Cyclic Inheritance test case
mcimadamore
parents: 10
diff changeset
   967
            attr.attribTypeVariables(tree.typarams, baseEnv);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
            // Add default constructor if needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
            if ((c.flags() & INTERFACE) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
                !TreeInfo.hasConstructors(tree.defs)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
                List<Type> argtypes = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
                List<Type> typarams = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
                List<Type> thrown = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
                long ctorFlags = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
                boolean based = false;
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   977
                boolean addConstructor = true;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
   978
                if (c.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
                    JCNewClass nc = (JCNewClass)env.next.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
                    if (nc.constructor != null) {
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   981
                        addConstructor = nc.constructor.kind != ERR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
                        Type superConstrType = types.memberType(c.type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
                                                                nc.constructor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
                        argtypes = superConstrType.getParameterTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
                        typarams = superConstrType.getTypeArguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
                        ctorFlags = nc.constructor.flags() & VARARGS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
                        if (nc.encl != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
                            argtypes = argtypes.prepend(nc.encl.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
                            based = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
                        thrown = superConstrType.getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
                }
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   994
                if (addConstructor) {
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   995
                    JCTree constrDef = DefaultConstructor(make.at(tree.pos), c,
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   996
                                                        typarams, argtypes, thrown,
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   997
                                                        ctorFlags, based);
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   998
                    tree.defs = tree.defs.prepend(constrDef);
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
   999
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
            // If this is a class, enter symbols for this and super into
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
            // current scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
            if ((c.flags_field & INTERFACE) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
                VarSymbol thisSym =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
                    new VarSymbol(FINAL | HASINIT, names._this, c.type, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
                thisSym.pos = Position.FIRSTPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
                env.info.scope.enter(thisSym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
                if (ct.supertype_field.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
                    VarSymbol superSym =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
                        new VarSymbol(FINAL | HASINIT, names._super,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
                                      ct.supertype_field, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
                    superSym.pos = Position.FIRSTPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
                    env.info.scope.enter(superSym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
            // check that no package exists with same fully qualified name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
            // but admit classes in the unnamed package which have the same
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
            // name as a top-level package.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
            if (checkClash &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
                c.owner.kind == PCK && c.owner != syms.unnamedPackage &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
                reader.packageExists(c.fullname))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
                {
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8038
diff changeset
  1025
                    log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
        // Enter all member fields and methods of a set of half completed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
        // classes in a second phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
        if (wasFirst) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
                while (halfcompleted.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
                    finish(halfcompleted.next());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
                isFirst = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
            // commit pending annotations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
            annotate.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
    private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
8242
3873b4aaf4a8 7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents: 8241
diff changeset
  1051
        Scope baseScope = new Scope(tree.sym);
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1052
        //import already entered local classes into base scope
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1053
        for (Scope.Entry e = env.outer.info.scope.elems ; e != null ; e = e.sibling) {
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1054
            if (e.sym.isLocal()) {
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1055
                baseScope.enter(e.sym);
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1056
            }
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1057
        }
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1058
        //import current type-parameters into base scope
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
        if (tree.typarams != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            for (List<JCTypeParameter> typarams = tree.typarams;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                 typarams.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
                 typarams = typarams.tail)
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1063
                baseScope.enter(typarams.head.type.tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
        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
  1065
        Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
        localEnv.baseClause = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
        localEnv.outer = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
        localEnv.info.isSelfCall = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
    /** Enter member fields and methods of a class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
     *  @param env        the environment current for the class block.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
    private void finish(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
            JCClassDecl tree = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
            finishClass(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
    /** Generate a base clause for an enum type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
     *  @param pos              The position for trees and diagnostics, if any
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
     *  @param c                The class symbol of the enum
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
    private JCExpression enumBase(int pos, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
        JCExpression result = make.at(pos).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
            TypeApply(make.QualIdent(syms.enumSym),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
                      List.<JCExpression>of(make.Type(c.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1096
    Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1097
        if (t.tag != ERROR)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1098
            return t;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1099
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1100
        return new ErrorType(((ErrorType) t).getOriginalType(), t.tsym) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1101
            private Type modelType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1102
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1103
            @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1104
            public Type getModelType() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1105
                if (modelType == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1106
                    modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1107
                return modelType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1108
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1109
        };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1110
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1111
    // where
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1112
    private class Synthesizer extends JCTree.Visitor {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1113
        Type originalType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1114
        boolean interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1115
        List<ClassSymbol> synthesizedSymbols = List.nil();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1116
        Type result;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1117
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1118
        Synthesizer(Type originalType, boolean interfaceExpected) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1119
            this.originalType = originalType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1120
            this.interfaceExpected = interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1121
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1122
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1123
        Type visit(JCTree tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1124
            tree.accept(this);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1125
            return result;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1126
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1127
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1128
        List<Type> visit(List<? extends JCTree> trees) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1129
            ListBuffer<Type> lb = new ListBuffer<Type>();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1130
            for (JCTree t: trees)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1131
                lb.append(visit(t));
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1132
            return lb.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1133
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1134
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1135
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1136
        public void visitTree(JCTree tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1137
            result = syms.errType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1138
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1139
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1140
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1141
        public void visitIdent(JCIdent tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1142
            if (tree.type.tag != ERROR) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1143
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1144
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1145
                result = synthesizeClass(tree.name, syms.unnamedPackage).type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1146
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1147
        }
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
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1150
        public void visitSelect(JCFieldAccess tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1151
            if (tree.type.tag != ERROR) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1152
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1153
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1154
                Type selectedType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1155
                boolean prev = interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1156
                try {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1157
                    interfaceExpected = false;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1158
                    selectedType = visit(tree.selected);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1159
                } finally {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1160
                    interfaceExpected = prev;
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
                ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1163
                result = c.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1164
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1165
        }
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
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1168
        public void visitTypeApply(JCTypeApply tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1169
            if (tree.type.tag != ERROR) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1170
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1171
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1172
                ClassType clazzType = (ClassType) visit(tree.clazz);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1173
                if (synthesizedSymbols.contains(clazzType.tsym))
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1174
                    synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1175
                final List<Type> actuals = visit(tree.arguments);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1176
                result = new ErrorType(tree.type, clazzType.tsym) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1177
                    @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1178
                    public List<Type> getTypeArguments() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1179
                        return actuals;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1180
                    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1181
                };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1182
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1183
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1184
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1185
        ClassSymbol synthesizeClass(Name name, Symbol owner) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1186
            int flags = interfaceExpected ? INTERFACE : 0;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1187
            ClassSymbol c = new ClassSymbol(flags, name, owner);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1188
            c.members_field = new Scope.ErrorScope(c);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1189
            c.type = new ErrorType(originalType, c) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1190
                @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1191
                public List<Type> getTypeArguments() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1192
                    return typarams_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1193
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1194
            };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1195
            synthesizedSymbols = synthesizedSymbols.prepend(c);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1196
            return c;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1197
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1198
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1199
        void synthesizeTyparams(ClassSymbol sym, int n) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1200
            ClassType ct = (ClassType) sym.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1201
            Assert.check(ct.typarams_field.isEmpty());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1202
            if (n == 1) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1203
                TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1204
                ct.typarams_field = ct.typarams_field.prepend(v);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1205
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1206
                for (int i = n; i > 0; i--) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1207
                    TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1208
                    ct.typarams_field = ct.typarams_field.prepend(v);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1209
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1210
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1211
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1212
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1213
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1214
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
 * tree building
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
    /** Generate default constructor for given class. For classes different
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
     *  from java.lang.Object, this is:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
     *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
     *      super(x_0, ..., x_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
     *    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
     *  or, if based == true:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
     *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
     *      x_0.super(x_1, ..., x_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
     *    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
     *  @param make     The tree factory.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
     *  @param c        The class owning the default constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
     *  @param argtypes The parameter types of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
     *  @param thrown   The thrown exceptions of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
     *  @param based    Is first parameter a this$n?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
    JCTree DefaultConstructor(TreeMaker make,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
                            ClassSymbol c,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
                            List<Type> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
                            List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
                            List<Type> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
                            long flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
                            boolean based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
        List<JCVariableDecl> params = make.Params(argtypes, syms.noSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
        List<JCStatement> stats = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        if (c.type != syms.objectType)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
            stats = stats.prepend(SuperCall(make, typarams, params, based));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
        if ((c.flags() & ENUM) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
            (types.supertype(c.type).tsym == syms.enumSym ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
             target.compilerBootstrap(c))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
            // constructors of true enums are private
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
            flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
            flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
  1256
        if (c.name.isEmpty()) flags |= ANONCONSTR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
        JCTree result = make.MethodDef(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
            make.Modifiers(flags),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
            names.init,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
            null,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
            make.TypeParams(typarams),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
            params,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
            make.Types(thrown),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
            make.Block(0, stats),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
            null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
    /** Generate call to superclass constructor. This is:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
     *    super(id_0, ..., id_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
     * or, if based == true
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
     *    id_0.super(id_1,...,id_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
     *  where id_0, ..., id_n are the names of the given parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
     *  @param make    The tree factory
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
     *  @param params  The parameters that need to be passed to super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
     *  @param typarams  The type parameters that need to be passed to super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
     *  @param based   Is first parameter a this$n?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
    JCExpressionStatement SuperCall(TreeMaker make,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
                   List<Type> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
                   List<JCVariableDecl> params,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
                   boolean based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        JCExpression meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
        if (based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
            meth = make.Select(make.Ident(params.head), names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
            params = params.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
            meth = make.Ident(names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
        List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
        return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
}