langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
author emc
Wed, 23 Oct 2013 23:20:32 -0400
changeset 21498 58c2486db8d0
parent 21040 3e32f68d2151
child 22163 3651128c74eb
permissions -rw-r--r--
8006732: support correct bytecode storage of type annotations in multicatch Summary: Fix issue with annotations being added before attribution, which causes multicatch not to work right and several tests to fail. Reviewed-by: jfranck, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
     2
 * Copyright (c) 2003, 2013, 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
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    28
import java.util.HashMap;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    29
import java.util.HashSet;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    30
import java.util.LinkedHashMap;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    31
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.Set;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
    33
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import static com.sun.tools.javac.code.Flags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
    46
import static com.sun.tools.javac.code.Flags.ANNOTATION;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import static com.sun.tools.javac.code.Kinds.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    48
import static com.sun.tools.javac.code.TypeTag.CLASS;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    49
import static com.sun.tools.javac.code.TypeTag.ERROR;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    50
import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
    51
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
    52
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
/** This is the second phase of Enter, in which classes are completed
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  by entering their members into the class scope using
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  MemberEnter.complete().  See Enter for an overview.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    59
 *  <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
    60
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
public class MemberEnter extends JCTree.Visitor implements Completer {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    protected static final Context.Key<MemberEnter> memberEnterKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        new Context.Key<MemberEnter>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /** A switch to determine whether we check for package/class conflicts
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    final static boolean checkClash = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
    72
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private final Enter enter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    private final Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private final Attr attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    private final Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    private final TreeMaker make;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    private final ClassReader reader;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private final Todo todo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    private final Annotate annotate;
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 19942
diff changeset
    82
    private final TypeAnnotations typeAnnotations;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private final Types types;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
    84
    private final JCDiagnostic.Factory diags;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
    85
    private final Source source;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    private final Target target;
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
    87
    private final DeferredLintHandler deferredLintHandler;
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
    88
    private final Lint lint;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    public static MemberEnter instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        MemberEnter instance = context.get(memberEnterKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            instance = new MemberEnter(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    protected MemberEnter(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        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
    99
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        enter = Enter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        attr = Attr.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        reader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        todo = Todo.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        annotate = Annotate.instance(context);
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 19942
diff changeset
   109
        typeAnnotations = TypeAnnotations.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        types = Types.instance(context);
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   111
        diags = JCDiagnostic.Factory.instance(context);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   112
        source = Source.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        target = Target.instance(context);
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   114
        deferredLintHandler = DeferredLintHandler.instance(context);
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   115
        lint = Lint.instance(context);
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   116
        allowTypeAnnos = source.allowTypeAnnotations();
21009
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   117
        allowRepeatedAnnos = source.allowRepeatedAnnotations();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   120
    /** Switch: support type annotations.
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   121
     */
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   122
    boolean allowTypeAnnos;
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   123
21009
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   124
    boolean allowRepeatedAnnos;
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   125
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /** A queue for classes whose members still need to be entered into the
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     *  symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    ListBuffer<Env<AttrContext>> halfcompleted = new ListBuffer<Env<AttrContext>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /** Set to true only when the first of a set of classes is
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
   132
     *  processed from the half completed queue.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    boolean isFirst = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    /** A flag to disable completion from time to time during member
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     *  enter, as we only need to look up types.  This avoids
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     *  unnecessarily deep recursion.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    boolean completionEnabled = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /* ---------- Processing import clauses ----------------
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /** Import all classes of a class or package on demand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *  @param tsym          The class or package the members of which are imported.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14058
diff changeset
   148
     *  @param env           The env in which the imported classes will be entered.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    private void importAll(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                           final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                           Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        // Check that packages imported from exist (JLS ???).
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            // If we can't find java.lang, exit immediately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
            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
   157
                JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                throw new FatalError(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            } else {
11709
0d56d3fc22e6 7129225: javac fails to run annotation processors when star import of package of gensrc
jjh
parents: 10950
diff changeset
   160
                log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        }
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents: 6929
diff changeset
   163
        env.toplevel.starImportScope.importAll(tsym.members());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /** Import all static members of a class or package on demand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     *  @param tsym          The class or package the members of which are imported.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14058
diff changeset
   169
     *  @param env           The env in which the imported classes will be entered.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    private void importStaticAll(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                                 final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                                 Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        final JavaFileObject sourcefile = env.toplevel.sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        final Scope toScope = env.toplevel.starImportScope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        final PackageSymbol packge = env.toplevel.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        final TypeSymbol origin = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        // enter imported types immediately
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        new Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                final Scope fromScope = tsym.members();
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                    if (sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                        (sym.flags() & STATIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
                        sym.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
                        !toScope.includes(sym))
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 18919
diff changeset
   199
                        toScope.enter(sym, fromScope, origin.members(), true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        }.importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        // enter non-types before annotations that might use them
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   205
        annotate.earlier(new Annotate.Worker() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                return "import static " + tsym + ".*" + " in " + sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                final Scope fromScope = tsym.members();
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                    if (sym.isStatic() && sym.kind != TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                        !toScope.includes(sym) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                        sym.isMemberOf(origin, types)) {
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 18919
diff changeset
   227
                        toScope.enter(sym, fromScope, origin.members(), true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            }
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   231
            public void run() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            }
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
    // is the sym accessible everywhere in packge?
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    boolean staticImportAccessible(Symbol sym, PackageSymbol packge) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        int flags = (int)(sym.flags() & AccessFlags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        switch (flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            return sym.packge() == packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    /** Import statics types of a given name.  Non-types are handled in Attr.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     *  @param tsym          The class from which the name is imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     *  @param name          The (simple) name being imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     *  @param env           The environment containing the named import
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     *                  scope to add to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    private void importNamedStatic(final DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                                   final TypeSymbol tsym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                                   final Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                                   final Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        if (tsym.kind != TYP) {
12917
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents: 12916
diff changeset
   264
            log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        final Scope toScope = env.toplevel.namedImportScope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        final PackageSymbol packge = env.toplevel.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        final TypeSymbol origin = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        // enter imported types immediately
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        new Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                for (Scope.Entry e = tsym.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                    if (sym.isStatic() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                        sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
                        sym.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                        chk.checkUniqueStaticImport(pos, sym, toScope))
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 18919
diff changeset
   293
                        toScope.enter(sym, sym.owner.members(), origin.members(), true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        }.importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        // enter non-types before annotations that might use them
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   299
        annotate.earlier(new Annotate.Worker() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            Set<Symbol> processed = new HashSet<Symbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            boolean found = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
            public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                return "import static " + tsym + "." + name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            void importFrom(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                if (tsym == null || !processed.add(tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                // also import inherited names
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                importFrom(types.supertype(tsym.type).tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                for (Type t : types.interfaces(tsym.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                    importFrom(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                for (Scope.Entry e = tsym.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
                    Symbol sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                    if (sym.isStatic() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                        staticImportAccessible(sym, packge) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                        sym.isMemberOf(origin, types)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
                        found = true;
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 18919
diff changeset
   323
                        if (sym.kind != TYP) {
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 18919
diff changeset
   324
                            toScope.enter(sym, sym.owner.members(), origin.members(), true);
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 18919
diff changeset
   325
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            }
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   329
            public void run() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                    importFrom(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                    if (!found) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                        log.error(pos, "cant.resolve.location",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   335
                                  KindName.STATIC,
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   336
                                  name, List.<Type>nil(), List.<Type>nil(),
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   337
                                  Kinds.typeKindName(tsym.type),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                                  tsym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                    log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
    /** Import given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     *  @param pos           Position to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     *  @param tsym          The class to be imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     *  @param env           The environment containing the named import
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
     *                  scope to add to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        if (tsym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope))
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            env.toplevel.namedImportScope.enter(tsym, tsym.owner.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    /** Construct method type from method signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
     *  @param typarams    The method's type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
     *  @param params      The method's value parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
     *  @param res             The method's result type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     *                 null if it is a constructor.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   363
     *  @param recvparam       The method's receiver parameter,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   364
     *                 null if none given; TODO: or already set here?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
     *  @param thrown      The method's thrown exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
     *  @param env             The method's (local) environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     */
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   368
    Type signature(MethodSymbol msym,
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   369
                   List<JCTypeParameter> typarams,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
                   List<JCVariableDecl> params,
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
                   JCTree res,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   372
                   JCVariableDecl recvparam,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                   List<JCExpression> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                   Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        // Enter and attribute type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        List<Type> tvars = enter.classEnter(typarams, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        attr.attribTypeVariables(typarams, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        // Enter and attribute value parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        ListBuffer<Type> argbuf = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            memberEnter(l.head, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            argbuf.append(l.head.vartype.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        // Attribute result type, if one is given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        Type restype = res == null ? syms.voidType : attr.attribType(res, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   390
        // Attribute receiver type, if one is given.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   391
        Type recvtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   392
        if (recvparam!=null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   393
            memberEnter(recvparam, env);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   394
            recvtype = recvparam.vartype.type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   395
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   396
            recvtype = null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   397
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   398
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        // Attribute thrown exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        ListBuffer<Type> thrownbuf = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            Type exc = attr.attribType(l.head, env);
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   403
            if (!exc.hasTag(TYPEVAR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
                exc = chk.checkClassType(l.head.pos(), exc);
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   405
            } else if (exc.tsym.owner == msym) {
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   406
                //mark inference variables in 'throws' clause
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   407
                exc.tsym.flags_field |= THROWS;
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18643
diff changeset
   408
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            thrownbuf.append(exc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   411
        MethodType mtype = new MethodType(argbuf.toList(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                                    restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                                    thrownbuf.toList(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
                                    syms.methodClass);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   415
        mtype.recvtype = recvtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   416
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
 * Visitor methods for member enter
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    /** Visitor argument: the current environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
    protected Env<AttrContext> env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
    /** Enter field and method definitions and process import
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
     *  clauses, catching any completion failure exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    protected void memberEnter(JCTree tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        Env<AttrContext> prevEnv = this.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
            tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
        }  catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
            this.env = prevEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
    /** Enter members from a list of trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
            memberEnter(l.head, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    /** Enter members for a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    void finishClass(JCClassDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        if ((tree.mods.flags & Flags.ENUM) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
            addEnumMembers(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        memberEnter(tree.defs, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    /** Add the implicit members for an enum type
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     *  to the symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
    private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass));
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        // public static T[] values() { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        JCMethodDecl values = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
                      names.values,
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
                      valuesType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                      List.<JCTypeParameter>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
                      List.<JCVariableDecl>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                      List.<JCExpression>nil(), // thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                      null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        memberEnter(values, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        // public static T valueOf(String name) { return ???; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        JCMethodDecl valueOf = make.
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
                      names.valueOf,
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
                      make.Type(tree.sym.type),
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
                      List.<JCTypeParameter>nil(),
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15385
diff changeset
   484
                      List.of(make.VarDef(make.Modifiers(Flags.PARAMETER |
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15385
diff changeset
   485
                                                         Flags.MANDATED),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
                                            names.fromString("name"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
                                            make.Type(syms.stringType), null)),
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
                      List.<JCExpression>nil(), // thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
                      null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
                      null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        memberEnter(valueOf, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
    public void visitTopLevel(JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        if (tree.starImportScope.elems != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            // we must have already processed this toplevel
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        // check that no class exists with same fully qualified name as
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        // toplevel package
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        if (checkClash && tree.pid != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            Symbol p = tree.packge;
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
            while (p.owner != syms.rootPackage) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                p.owner.complete(); // enter all class members of p
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
                if (syms.classes.get(p.getQualifiedName()) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                    log.error(tree.pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                              "pkg.clashes.with.class.of.same.name",
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
                              p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
                p = p.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        // process package annotations
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   516
        annotateLater(tree.packageAnnotations, env, tree.packge, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   518
        DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   519
        Lint prevLint = chk.setLint(lint);
18919
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   520
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   521
        try {
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   522
            // Import-on-demand java.lang.
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   523
            importAll(tree.pos, reader.enterPackage(names.java_lang), env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
18919
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   525
            // Process all import clauses.
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   526
            memberEnter(tree.defs, env);
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   527
        } finally {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   528
            chk.setLint(prevLint);
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   529
            deferredLintHandler.setPos(prevLintPos);
18919
7d1f1448a9db 8020586: Warning produced for an incorrect file
jlahoda
parents: 18909
diff changeset
   530
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
    // process the non-static imports and the static imports of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
    public void visitImport(JCImport tree) {
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   535
        JCFieldAccess imp = (JCFieldAccess)tree.qualid;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
        Name name = TreeInfo.name(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        // Create a local environment pointing to this tree to disable
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        // effects of other imports in Resolve.findGlobalType
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        Env<AttrContext> localEnv = env.dup(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   542
        TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        if (name == names.asterisk) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            // Import on demand.
12081
42f541476d14 7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents: 11709
diff changeset
   545
            chk.checkCanonical(imp.selected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            if (tree.staticImport)
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
                importStaticAll(tree.pos, p, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
                importAll(tree.pos, p, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
            // Named type import.
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            if (tree.staticImport) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                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
   554
                chk.checkCanonical(imp.selected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
                TypeSymbol c = attribImportType(imp, localEnv).tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
                chk.checkCanonical(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
                importNamed(tree.pos(), c, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
    public void visitMethodDef(JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        Scope enclScope = enter.enterScope(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
        tree.sym = m;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   568
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   569
        //if this is a default method, add the DEFAULT flag to the enclosing interface
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   570
        if ((tree.mods.flags & DEFAULT) != 0) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   571
            m.enclClass().flags_field |= DEFAULT;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   572
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   573
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
        Env<AttrContext> localEnv = methodEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   576
        annotate.enterStart();
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   577
        try {
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   578
            DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   579
            try {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   580
                // Compute the method type
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   581
                m.type = signature(m, tree.typarams, tree.params,
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   582
                                   tree.restype, tree.recvparam,
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   583
                                   tree.thrown,
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   584
                                   localEnv);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   585
            } finally {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   586
                deferredLintHandler.setPos(prevLintPos);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   587
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   589
            if (types.isSignaturePolymorphic(m)) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   590
                m.flags_field |= SIGNATURE_POLYMORPHIC;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   591
            }
18389
a425d0819f36 8016569: javac, add new flag for polymorphic method signatures
vromero
parents: 18010
diff changeset
   592
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   593
            // Set m.params
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   594
            ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   595
            JCVariableDecl lastParam = null;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   596
            for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   597
                JCVariableDecl param = lastParam = l.head;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   598
                params.append(Assert.checkNonNull(param.sym));
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   599
            }
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   600
            m.params = params.toList();
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   601
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   602
            // mark the method varargs, if necessary
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   603
            if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   604
                m.flags_field |= Flags.VARARGS;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   606
            localEnv.info.scope.leave();
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   607
            if (chk.checkUnique(tree.pos(), m, enclScope)) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   608
            enclScope.enter(m);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   609
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   611
            annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   612
            // Visit the signature of the method. Note that
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   613
            // TypeAnnotate doesn't descend into the body.
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   614
            typeAnnotate(tree, localEnv, m, tree.pos());
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   615
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   616
            if (tree.defaultValue != null)
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   617
                annotateDefaultValueLater(tree.defaultValue, localEnv, m);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   618
        } finally {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   619
            annotate.enterDone();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
    /** Create a fresh environment for method bodies.
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
     *  @param tree     The method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
     *  @param env      The environment current outside of the method definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
    Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        Env<AttrContext> localEnv =
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            env.dup(tree, env.info.dup(env.info.scope.dupUnshared()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        localEnv.enclMethod = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
        localEnv.info.scope.owner = tree.sym;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   632
        if (tree.sym.type != null) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14051
diff changeset
   633
            //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
   634
            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
   635
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
        if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
    public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        Env<AttrContext> localEnv = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        if ((tree.mods.flags & STATIC) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
            (env.info.scope.owner.flags() & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            localEnv = env.dup(tree, env.info.dup());
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        }
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   647
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   648
        annotate.enterStart();
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   649
        try {
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   650
            try {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   651
                if (TreeInfo.isEnumInit(tree)) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   652
                    attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   653
                } else {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   654
                    attr.attribType(tree.vartype, localEnv);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   655
                    if (tree.nameexpr != null) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   656
                        attr.attribExpr(tree.nameexpr, localEnv);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   657
                        MethodSymbol m = localEnv.enclMethod.sym;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   658
                        if (m.isConstructor()) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   659
                            Type outertype = m.owner.owner.type;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   660
                            if (outertype.hasTag(TypeTag.CLASS)) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   661
                                checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   662
                                checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   663
                            } else {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   664
                                log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   665
                            }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   666
                        } else {
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   667
                            checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   668
                            checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   669
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   670
                    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   671
                }
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   672
            } finally {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   673
                deferredLintHandler.setPos(prevLintPos);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   674
            }
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   675
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   676
            if ((tree.mods.flags & VARARGS) != 0) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   677
                //if we are entering a varargs parameter, we need to
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   678
                //replace its type (a plain array type) with the more
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   679
                //precise VarargsType --- we need to do it this way
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   680
                //because varargs is represented in the tree as a
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   681
                //modifier on the parameter declaration, and not as a
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   682
                //distinct type of array node.
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   683
                ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType();
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   684
                tree.vartype.type = atype.makeVarargs();
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   685
            }
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   686
            Scope enclScope = enter.enterScope(env);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   687
            VarSymbol v =
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   688
                new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   689
            v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   690
            tree.sym = v;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   691
            if (tree.init != null) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   692
                v.flags_field |= HASINIT;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   693
                if ((v.flags_field & FINAL) != 0 &&
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   694
                    needsLazyConstValue(tree.init)) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   695
                    Env<AttrContext> initEnv = getInitEnv(tree, env);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   696
                    initEnv.info.enclVar = v;
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   697
                    v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   698
                }
12916
021c069e8e27 7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents: 12335
diff changeset
   699
            }
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   700
            if (chk.checkUnique(tree.pos(), v, enclScope)) {
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   701
                chk.checkTransparentVar(tree.pos(), v, enclScope);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   702
                enclScope.enter(v);
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   703
            }
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   704
            annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   705
            typeAnnotate(tree.vartype, env, v, tree.pos());
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   706
            v.pos = tree.pos;
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8225
diff changeset
   707
        } finally {
21498
58c2486db8d0 8006732: support correct bytecode storage of type annotations in multicatch
emc
parents: 21040
diff changeset
   708
            annotate.enterDone();
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7615
diff changeset
   709
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
    }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   711
    // where
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   712
    void checkType(JCTree tree, Type type, String diag) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   713
        if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   714
            log.error(tree, diag, type, tree.type);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   715
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
   716
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
19656
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   718
    public boolean needsLazyConstValue(JCTree tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   719
        InitTreeVisitor initTreeVisitor = new InitTreeVisitor();
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   720
        tree.accept(initTreeVisitor);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   721
        return initTreeVisitor.result;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   722
    }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   723
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   724
    /** Visitor class for expressions which might be constant expressions.
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   725
     */
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   726
    static class InitTreeVisitor extends JCTree.Visitor {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   727
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   728
        private boolean result = true;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   729
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   730
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   731
        public void visitTree(JCTree tree) {}
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   732
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   733
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   734
        public void visitNewClass(JCNewClass that) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   735
            result = false;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   736
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   737
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   738
        @Override
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   739
        public void visitNewArray(JCNewArray that) {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   740
            result = false;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   741
        }
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   742
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   743
        @Override
19656
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   744
        public void visitLambda(JCLambda that) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   745
            result = false;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   746
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   747
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   748
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   749
        public void visitReference(JCMemberReference that) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   750
            result = false;
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   751
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   752
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   753
        @Override
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   754
        public void visitApply(JCMethodInvocation that) {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   755
            result = false;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   756
        }
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   757
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   758
        @Override
19656
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   759
        public void visitSelect(JCFieldAccess tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   760
            tree.selected.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   761
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   762
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   763
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   764
        public void visitConditional(JCConditional tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   765
            tree.cond.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   766
            tree.truepart.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   767
            tree.falsepart.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   768
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   769
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   770
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   771
        public void visitParens(JCParens tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   772
            tree.expr.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   773
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   774
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   775
        @Override
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   776
        public void visitTypeCast(JCTypeCast tree) {
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   777
            tree.expr.accept(this);
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   778
        }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   779
    }
7f0afbdbf142 8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents: 19651
diff changeset
   780
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
    /** Create a fresh environment for a variable's initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
     *  If the variable is a field, the owner of the environment's scope
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
     *  is be the variable itself, otherwise the owner is the method
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
     *  enclosing the variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
     *  @param tree     The variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
     *  @param env      The environment current outside of the variable definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
    Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        if (tree.sym.owner.kind == TYP) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   792
            localEnv.info.scope = env.info.scope.dupUnshared();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            localEnv.info.scope.owner = tree.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        if ((tree.mods.flags & STATIC) != 0 ||
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
   796
                ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            localEnv.info.staticLevel++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
    /** Default member enter visitor method: do nothing
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
    public void visitTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
    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
   807
        if (tree.errs != null)
81a6a7c1bef1 6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents: 6721
diff changeset
   808
            memberEnter(tree.errs, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
    public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        Env<AttrContext> mEnv = methodEnv(tree, env);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
   813
        mEnv.info.lint = mEnv.info.lint.augment(tree.sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
        for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
            mEnv.info.scope.enterIfAbsent(l.head.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
        return mEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
    public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
        Env<AttrContext> iEnv = initEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        return iEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
 * Type completion
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
    Type attribImportType(JCTree tree, Env<AttrContext> env) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   831
        Assert.check(completionEnabled);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
            // To prevent deep recursion, suppress completion of some
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
            // types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
            completionEnabled = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
            return attr.attribType(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
            completionEnabled = true;
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
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
 * Annotation processing
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
    /** Queue annotations for later processing. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
    void annotateLater(final List<JCAnnotation> annotations,
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
                       final Env<AttrContext> localEnv,
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   849
                       final Symbol s,
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   850
                       final DiagnosticPosition deferPos) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   851
        if (annotations.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   852
            return;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   853
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   854
        if (s.kind != PCK) {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
   855
            s.resetAnnotations(); // mark Annotations as incomplete for now
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   856
        }
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   857
        annotate.normal(new Annotate.Worker() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   858
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
                    return "annotate " + annotations + " onto " + s + " in " + s.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   862
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   863
                @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   864
                public void run() {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
   865
                    Assert.check(s.kind == PCK || s.annotationsPendingCompletion());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
                    JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   867
                    DiagnosticPosition prevLintPos =
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   868
                        deferPos != null
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   869
                        ? deferredLintHandler.setPos(deferPos)
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   870
                        : deferredLintHandler.immediate();
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   871
                    Lint prevLint = deferPos != null ? null : chk.setLint(lint);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
                    try {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
   873
                        if (s.hasAnnotations() &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
                            annotations.nonEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
                            log.error(annotations.head.pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
                                      "already.annotated",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   877
                                      kindName(s), s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   878
                        actualEnterAnnotations(annotations, localEnv, s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
                    } finally {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   880
                        if (prevLint != null)
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   881
                            chk.setLint(prevLint);
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
   882
                        deferredLintHandler.setPos(prevLintPos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
                        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
            });
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   887
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   888
        annotate.validate(new Annotate.Worker() { //validate annotations
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   889
            @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   890
            public void run() {
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   891
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   892
                try {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   893
                    chk.validateAnnotations(annotations, s);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   894
                } finally {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   895
                    log.useSource(prev);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   896
                }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   897
            }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   898
        });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
     * Check if a list of annotations contains a reference to
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
     * java.lang.Deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
    private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   906
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            JCAnnotation a = al.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
    /** Enter a set of annotations. */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   915
    private void actualEnterAnnotations(List<JCAnnotation> annotations,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
                          Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
                          Symbol s) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   918
        Map<TypeSymbol, ListBuffer<Attribute.Compound>> annotated =
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   919
                new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.Compound>>();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   920
        Map<Attribute.Compound, DiagnosticPosition> pos =
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   921
                new HashMap<Attribute.Compound, DiagnosticPosition>();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   922
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   923
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
            JCAnnotation a = al.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            Attribute.Compound c = annotate.enterAnnotation(a,
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
                                                            syms.annotationType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
                                                            env);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   928
            if (c == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   929
                continue;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   930
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   931
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   932
            if (annotated.containsKey(a.type.tsym)) {
21009
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   933
                if (!allowRepeatedAnnos) {
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   934
                    log.error(a.pos(), "repeatable.annotations.not.supported.in.source");
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   935
                    allowRepeatedAnnos = true;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   936
                }
21009
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   937
                ListBuffer<Attribute.Compound> l = annotated.get(a.type.tsym);
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   938
                l = l.append(c);
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   939
                annotated.put(a.type.tsym, l);
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
   940
                pos.put(c, a.pos());
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   941
            } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   942
                annotated.put(a.type.tsym, ListBuffer.of(c));
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   943
                pos.put(c, a.pos());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   944
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   945
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
            // Note: @Deprecated has no effect on local variables and parameters
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
            if (!c.type.isErroneous()
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
                && s.owner.kind != MTH
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   949
                && types.isSameType(c.type, syms.deprecatedType)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
                s.flags_field |= Flags.DEPRECATED;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   951
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
        }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   953
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
   954
        s.setDeclarationAttributesWithCompletion(
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
   955
                annotate.new AnnotateRepeatedContext<Attribute.Compound>(env, annotated, pos, log, false));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
    /** Queue processing of an attribute default value. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
    void annotateDefaultValueLater(final JCExpression defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
                                   final Env<AttrContext> localEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
                                   final MethodSymbol m) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   962
        annotate.normal(new Annotate.Worker() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   963
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
                    return "annotate " + m.owner + "." +
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
                        m + " default " + defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   968
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12917
diff changeset
   969
                @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   970
                public void run() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
                    JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
                        enterDefaultValue(defaultValue, localEnv, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
                    } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
                        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
            });
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   979
        annotate.validate(new Annotate.Worker() { //validate annotations
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   980
            @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   981
            public void run() {
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   982
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   983
                try {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   984
                    // if default value is an annotation, check it is a well-formed
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   985
                    // annotation value (e.g. no duplicate values, no missing values, etc.)
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   986
                    chk.validateAnnotationTree(defaultValue);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   987
                } finally {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   988
                    log.useSource(prev);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   989
                }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   990
            }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   991
        });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
    /** Enter a default value for an attribute method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
    private void enterDefaultValue(final JCExpression defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
                                   final Env<AttrContext> localEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
                                   final MethodSymbol m) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
        m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
                                                      defaultValue,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
                                                      localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
 * Source completer
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
    /** Complete entering a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
     *  @param sym         The symbol of the class to be completed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
    public void complete(Symbol sym) throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
        // Suppress some (recursive) MemberEnter invocations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
        if (!completionEnabled) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
            // Re-install same completer for next time around and return.
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1014
            Assert.check((sym.flags() & Flags.COMPOUND) == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
            sym.completer = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
        ClassSymbol c = (ClassSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
        ClassType ct = (ClassType)c.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
        Env<AttrContext> env = enter.typeEnvs.get(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
        JCClassDecl tree = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
        boolean wasFirst = isFirst;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        isFirst = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1027
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
            // Save class environment for later member enter (2) processing.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
            halfcompleted.append(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
1043
11ea4773b0af 6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents: 1040
diff changeset
  1032
            // 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
  1033
            c.flags_field |= UNATTRIBUTED;
11ea4773b0af 6695838: javac does not detect cyclic inheritance involving static inner classes after import clause
mcimadamore
parents: 1040
diff changeset
  1034
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
            // If this is a toplevel-class, make sure any preceding import
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
            // clauses have been seen.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
            if (c.owner.kind == PCK) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9082
diff changeset
  1038
                memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
                todo.append(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
            if (c.owner.kind == TYP)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
                c.owner.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
            // create an environment for evaluating the base clauses
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
            Env<AttrContext> baseEnv = baseEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1048
            if (tree.extending != null)
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1049
                typeAnnotate(tree.extending, baseEnv, sym, tree.pos());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1050
            for (JCExpression impl : tree.implementing)
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1051
                typeAnnotate(impl, baseEnv, sym, tree.pos());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1052
            annotate.flush();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1053
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
            // Determine supertype.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
            Type supertype =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
                (tree.extending != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
                ? attr.attribBase(tree.extending, baseEnv, true, false, true)
16558
07c08ad4a700 8010179: Remove transitional target values from javac
darcy
parents: 15720
diff changeset
  1058
                : ((tree.mods.flags & Flags.ENUM) != 0)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
                ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
                                  true, false, false)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                : (c.fullname == names.java_lang_Object)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
                ? Type.noType
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
                : syms.objectType;
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1064
            ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
            // Determine interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
            ListBuffer<Type> interfaces = new ListBuffer<Type>();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1068
            ListBuffer<Type> all_interfaces = null; // lazy init
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
            Set<Type> interfaceSet = new HashSet<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
            List<JCExpression> interfaceTrees = tree.implementing;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
            for (JCExpression iface : interfaceTrees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
                Type i = attr.attribBase(iface, baseEnv, false, true, true);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1073
                if (i.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
                    interfaces.append(i);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1075
                    if (all_interfaces != null) all_interfaces.append(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
                    chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1077
                } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1078
                    if (all_interfaces == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1079
                        all_interfaces = new ListBuffer<Type>().appendList(interfaces);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1080
                    all_interfaces.append(modelMissingTypes(i, iface, true));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
            }
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1083
            if ((c.flags_field & ANNOTATION) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
                ct.interfaces_field = List.of(syms.annotationType);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1085
                ct.all_interfaces_field = ct.interfaces_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1086
            }  else {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
                ct.interfaces_field = interfaces.toList();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1088
                ct.all_interfaces_field = (all_interfaces == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1089
                        ? ct.interfaces_field : all_interfaces.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1090
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
            if (c.fullname == names.java_lang_Object) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
                if (tree.extending != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
                    chk.checkNonCyclic(tree.extending.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
                                       supertype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
                    ct.supertype_field = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
                else if (tree.implementing.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
                    chk.checkNonCyclic(tree.implementing.head.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
                                       ct.interfaces_field.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
                    ct.interfaces_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
            // Annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            // In general, we cannot fully process annotations yet,  but we
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
            // can attribute the annotation types and then check to see if the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
            // @Deprecated annotation is present.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
            attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
            if (hasDeprecatedAnnotation(tree.mods.annotations))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
                c.flags_field |= DEPRECATED;
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1112
            annotateLater(tree.mods.annotations, baseEnv, c, tree.pos());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1113
            // class type parameters use baseEnv but everything uses env
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
6711
fc9732adc790 6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents: 6709
diff changeset
  1115
            chk.checkNonCyclicDecl(tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
165
1875ac59896a 6663588: Compiler goes into infinite loop for Cyclic Inheritance test case
mcimadamore
parents: 10
diff changeset
  1117
            attr.attribTypeVariables(tree.typarams, baseEnv);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1118
            // Do this here, where we have the symbol.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1119
            for (JCTypeParameter tp : tree.typarams)
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1120
                typeAnnotate(tp, baseEnv, sym, tree.pos());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
            // Add default constructor if needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
            if ((c.flags() & INTERFACE) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
                !TreeInfo.hasConstructors(tree.defs)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
                List<Type> argtypes = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
                List<Type> typarams = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
                List<Type> thrown = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
                long ctorFlags = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
                boolean based = false;
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1130
                boolean addConstructor = true;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1131
                JCNewClass nc = null;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1045
diff changeset
  1132
                if (c.name.isEmpty()) {
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1133
                    nc = (JCNewClass)env.next.tree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
                    if (nc.constructor != null) {
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1135
                        addConstructor = nc.constructor.kind != ERR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
                        Type superConstrType = types.memberType(c.type,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
                                                                nc.constructor);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
                        argtypes = superConstrType.getParameterTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
                        typarams = superConstrType.getTypeArguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
                        ctorFlags = nc.constructor.flags() & VARARGS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
                        if (nc.encl != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
                            argtypes = argtypes.prepend(nc.encl.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                            based = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                        thrown = superConstrType.getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
                }
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1148
                if (addConstructor) {
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1149
                    MethodSymbol basedConstructor = nc != null ?
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1150
                            (MethodSymbol)nc.constructor : null;
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1151
                    JCTree constrDef = DefaultConstructor(make.at(tree.pos), c,
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1152
                                                        basedConstructor,
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1153
                                                        typarams, argtypes, thrown,
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1154
                                                        ctorFlags, based);
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1155
                    tree.defs = tree.defs.prepend(constrDef);
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 13689
diff changeset
  1156
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1159
            // enter symbols for 'this' into current scope.
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1160
            VarSymbol thisSym =
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1161
                new VarSymbol(FINAL | HASINIT, names._this, c.type, c);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1162
            thisSym.pos = Position.FIRSTPOS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1163
            env.info.scope.enter(thisSym);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1164
            // if this is a class, enter symbol for 'super' into current scope.
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1165
            if ((c.flags_field & INTERFACE) == 0 &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1166
                    ct.supertype_field.hasTag(CLASS)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1167
                VarSymbol superSym =
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1168
                    new VarSymbol(FINAL | HASINIT, names._super,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1169
                                  ct.supertype_field, c);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1170
                superSym.pos = Position.FIRSTPOS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14369
diff changeset
  1171
                env.info.scope.enter(superSym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
            // check that no package exists with same fully qualified name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
            // but admit classes in the unnamed package which have the same
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
            // name as a top-level package.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
            if (checkClash &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
                c.owner.kind == PCK && c.owner != syms.unnamedPackage &&
14369
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1179
                reader.packageExists(c.fullname)) {
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1180
                log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c);
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1181
            }
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1182
            if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 &&
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1183
                !env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) {
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1184
                c.flags_field |= AUXILIARY;
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1185
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
            chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
        } finally {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1189
            deferredLintHandler.setPos(prevLintPos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
        // Enter all member fields and methods of a set of half completed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
        // classes in a second phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
        if (wasFirst) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
                while (halfcompleted.nonEmpty()) {
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
  1198
                    Env<AttrContext> toFinish = halfcompleted.next();
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
  1199
                    finish(toFinish);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
  1200
                    if (allowTypeAnnos) {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
  1201
                        typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
  1202
                        typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
  1203
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
                isFirst = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1208
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1209
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1211
    /*
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1212
     * If the symbol is non-null, attach the type annotation to it.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1213
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1214
    private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1215
            final Env<AttrContext> env,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1216
            final Symbol s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1217
        Map<TypeSymbol, ListBuffer<Attribute.TypeCompound>> annotated =
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1218
                new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.TypeCompound>>();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1219
        Map<Attribute.TypeCompound, DiagnosticPosition> pos =
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1220
                new HashMap<Attribute.TypeCompound, DiagnosticPosition>();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1221
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1222
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1223
            JCAnnotation a = al.head;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1224
            Attribute.TypeCompound tc = annotate.enterTypeAnnotation(a,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1225
                    syms.annotationType,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1226
                    env);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1227
            if (tc == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1228
                continue;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1229
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1230
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1231
            if (annotated.containsKey(a.type.tsym)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1232
                if (source.allowRepeatedAnnotations()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1233
                    ListBuffer<Attribute.TypeCompound> l = annotated.get(a.type.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1234
                    l = l.append(tc);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1235
                    annotated.put(a.type.tsym, l);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1236
                    pos.put(tc, a.pos());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1237
                } else {
21009
b35973e2d42e 8019461: Clean up javac diagnostics
emc
parents: 20258
diff changeset
  1238
                    log.error(a.pos(), "repeatable.annotations.not.supported.in.source");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1239
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1240
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1241
                annotated.put(a.type.tsym, ListBuffer.of(tc));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1242
                pos.put(tc, a.pos());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1243
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1244
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1245
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1246
        if (s != null) {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17999
diff changeset
  1247
            s.appendTypeAttributesWithCompletion(
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1248
                    annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1249
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1250
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1251
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1252
    public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) {
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
  1253
        if (allowTypeAnnos) {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1254
            tree.accept(new TypeAnnotate(env, sym, deferPos));
18643
fdd7572e0c18 8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents: 18389
diff changeset
  1255
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1256
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1257
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1258
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1259
     * We need to use a TreeScanner, because it is not enough to visit the top-level
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1260
     * annotations. We also need to visit type arguments, etc.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1261
     */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1262
    private class TypeAnnotate extends TreeScanner {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1263
        private Env<AttrContext> env;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1264
        private Symbol sym;
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1265
        private DiagnosticPosition deferPos;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1266
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1267
        public TypeAnnotate(final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1268
            this.env = env;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1269
            this.sym = sym;
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1270
            this.deferPos = deferPos;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1271
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1272
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1273
        void annotateTypeLater(final List<JCAnnotation> annotations) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1274
            if (annotations.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1275
                return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1276
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1277
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1278
            final DiagnosticPosition deferPos = this.deferPos;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1279
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
  1280
            annotate.normal(new Annotate.Worker() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1281
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1282
                public String toString() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1283
                    return "type annotate " + annotations + " onto " + sym + " in " + sym.owner;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1284
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1285
                @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
  1286
                public void run() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1287
                    JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1288
                    DiagnosticPosition prevLintPos = null;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1289
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1290
                    if (deferPos != null) {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1291
                        prevLintPos = deferredLintHandler.setPos(deferPos);
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1292
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1293
                    try {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1294
                        actualEnterTypeAnnotations(annotations, env, sym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1295
                    } finally {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1296
                        if (prevLintPos != null)
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1297
                            deferredLintHandler.setPos(prevLintPos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1298
                        log.useSource(prev);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1299
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1300
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1301
            });
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1302
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1303
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1304
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1305
        public void visitAnnotatedType(final JCAnnotatedType tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1306
            annotateTypeLater(tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1307
            super.visitAnnotatedType(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1308
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1309
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1310
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1311
        public void visitTypeParameter(final JCTypeParameter tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1312
            annotateTypeLater(tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1313
            super.visitTypeParameter(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1314
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1315
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1316
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1317
        public void visitNewArray(final JCNewArray tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1318
            annotateTypeLater(tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1319
            for (List<JCAnnotation> dimAnnos : tree.dimAnnotations)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1320
                annotateTypeLater(dimAnnos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1321
            super.visitNewArray(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1322
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1323
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1324
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1325
        public void visitMethodDef(final JCMethodDecl tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1326
            scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1327
            scan(tree.restype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1328
            scan(tree.typarams);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1329
            scan(tree.recvparam);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1330
            scan(tree.params);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1331
            scan(tree.thrown);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1332
            scan(tree.defaultValue);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1333
            // Do not annotate the body, just the signature.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1334
            // scan(tree.body);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
        }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1336
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1337
        @Override
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1338
        public void visitVarDef(final JCVariableDecl tree) {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1339
            DiagnosticPosition prevPos = deferPos;
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1340
            deferPos = tree.pos();
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1341
            try {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1342
                if (sym != null && sym.kind == Kinds.VAR) {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1343
                    // Don't visit a parameter once when the sym is the method
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1344
                    // and once when the sym is the parameter.
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1345
                    scan(tree.mods);
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1346
                    scan(tree.vartype);
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1347
                }
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1348
                scan(tree.init);
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1349
            } finally {
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19941
diff changeset
  1350
                deferPos = prevPos;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1351
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1352
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1353
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1354
        @Override
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1355
        public void visitClassDef(JCClassDecl tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1356
            // We can only hit a classdef if it is declared within
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1357
            // a method. Ignore it - the class will be visited
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1358
            // separately later.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1359
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1360
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1361
        @Override
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1362
        public void visitNewClass(JCNewClass tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1363
            if (tree.def == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1364
                // For an anonymous class instantiation the class
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1365
                // will be visited separately.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1366
                super.visitNewClass(tree);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1367
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16558
diff changeset
  1368
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14443
diff changeset
  1371
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
    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
  1373
        Scope baseScope = new Scope(tree.sym);
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1374
        //import already entered local classes into base scope
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1375
        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
  1376
            if (e.sym.isLocal()) {
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1377
                baseScope.enter(e.sym);
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1378
            }
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1379
        }
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1380
        //import current type-parameters into base scope
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
        if (tree.typarams != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
            for (List<JCTypeParameter> typarams = tree.typarams;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
                 typarams.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
                 typarams = typarams.tail)
6352
217d5a69681a 6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents: 5857
diff changeset
  1385
                baseScope.enter(typarams.head.type.tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
        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
  1387
        Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
        localEnv.baseClause = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
        localEnv.outer = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
        localEnv.info.isSelfCall = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
    /** Enter member fields and methods of a class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
     *  @param env        the environment current for the class block.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
    private void finish(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
            JCClassDecl tree = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
            finishClass(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
    /** Generate a base clause for an enum type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
     *  @param pos              The position for trees and diagnostics, if any
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
     *  @param c                The class symbol of the enum
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
    private JCExpression enumBase(int pos, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
        JCExpression result = make.at(pos).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
            TypeApply(make.QualIdent(syms.enumSym),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
                      List.<JCExpression>of(make.Type(c.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1418
    Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1419
        if (!t.hasTag(ERROR))
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1420
            return t;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1421
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21010
diff changeset
  1422
        return new ErrorType(t.getOriginalType(), t.tsym) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1423
            private Type modelType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1424
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1425
            @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1426
            public Type getModelType() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1427
                if (modelType == null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1428
                    modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1429
                return modelType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1430
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1431
        };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1432
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1433
    // where
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1434
    private class Synthesizer extends JCTree.Visitor {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1435
        Type originalType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1436
        boolean interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1437
        List<ClassSymbol> synthesizedSymbols = List.nil();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1438
        Type result;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1439
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1440
        Synthesizer(Type originalType, boolean interfaceExpected) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1441
            this.originalType = originalType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1442
            this.interfaceExpected = interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1443
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1444
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1445
        Type visit(JCTree tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1446
            tree.accept(this);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1447
            return result;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1448
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1449
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1450
        List<Type> visit(List<? extends JCTree> trees) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1451
            ListBuffer<Type> lb = new ListBuffer<Type>();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1452
            for (JCTree t: trees)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1453
                lb.append(visit(t));
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1454
            return lb.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1455
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1456
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1457
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1458
        public void visitTree(JCTree tree) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1459
            result = syms.errType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1460
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1461
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1462
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1463
        public void visitIdent(JCIdent tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1464
            if (!tree.type.hasTag(ERROR)) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1465
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1466
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1467
                result = synthesizeClass(tree.name, syms.unnamedPackage).type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1468
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1469
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1470
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1471
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1472
        public void visitSelect(JCFieldAccess tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1473
            if (!tree.type.hasTag(ERROR)) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1474
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1475
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1476
                Type selectedType;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1477
                boolean prev = interfaceExpected;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1478
                try {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1479
                    interfaceExpected = false;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1480
                    selectedType = visit(tree.selected);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1481
                } finally {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1482
                    interfaceExpected = prev;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1483
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1484
                ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1485
                result = c.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1486
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1487
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1488
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1489
        @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1490
        public void visitTypeApply(JCTypeApply tree) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
  1491
            if (!tree.type.hasTag(ERROR)) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1492
                result = tree.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1493
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1494
                ClassType clazzType = (ClassType) visit(tree.clazz);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1495
                if (synthesizedSymbols.contains(clazzType.tsym))
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1496
                    synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1497
                final List<Type> actuals = visit(tree.arguments);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1498
                result = new ErrorType(tree.type, clazzType.tsym) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1499
                    @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1500
                    public List<Type> getTypeArguments() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1501
                        return actuals;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1502
                    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1503
                };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1504
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1505
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1506
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1507
        ClassSymbol synthesizeClass(Name name, Symbol owner) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1508
            int flags = interfaceExpected ? INTERFACE : 0;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1509
            ClassSymbol c = new ClassSymbol(flags, name, owner);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1510
            c.members_field = new Scope.ErrorScope(c);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1511
            c.type = new ErrorType(originalType, c) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1512
                @Override
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1513
                public List<Type> getTypeArguments() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1514
                    return typarams_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1515
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1516
            };
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1517
            synthesizedSymbols = synthesizedSymbols.prepend(c);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1518
            return c;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1519
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1520
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1521
        void synthesizeTyparams(ClassSymbol sym, int n) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1522
            ClassType ct = (ClassType) sym.type;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1523
            Assert.check(ct.typarams_field.isEmpty());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1524
            if (n == 1) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1525
                TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1526
                ct.typarams_field = ct.typarams_field.prepend(v);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1527
            } else {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1528
                for (int i = n; i > 0; i--) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1529
                    TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1530
                    ct.typarams_field = ct.typarams_field.prepend(v);
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1531
                }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1532
            }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1533
        }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1534
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1535
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8242
diff changeset
  1536
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
 * tree building
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
    /** Generate default constructor for given class. For classes different
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
     *  from java.lang.Object, this is:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
     *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
     *      super(x_0, ..., x_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1546
     *    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
     *  or, if based == true:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
     *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1551
     *      x_0.super(x_1, ..., x_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
     *    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
     *  @param make     The tree factory.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
     *  @param c        The class owning the default constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
     *  @param argtypes The parameter types of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
     *  @param thrown   The thrown exceptions of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1558
     *  @param based    Is first parameter a this$n?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
    JCTree DefaultConstructor(TreeMaker make,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1561
                            ClassSymbol c,
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1562
                            MethodSymbol baseInit,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
                            List<Type> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
                            List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1565
                            List<Type> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1566
                            long flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1567
                            boolean based) {
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1568
        JCTree result;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
        if ((c.flags() & ENUM) != 0 &&
16558
07c08ad4a700 8010179: Remove transitional target values from javac
darcy
parents: 15720
diff changeset
  1570
            (types.supertype(c.type).tsym == syms.enumSym)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
            // constructors of true enums are private
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
            flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1573
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1574
            flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1575
        if (c.name.isEmpty()) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1576
            flags |= ANONCONSTR;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1577
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1578
        Type mType = new MethodType(argtypes, null, thrown, c);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1579
        Type initType = typarams.nonEmpty() ?
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1580
                new ForAll(typarams, mType) :
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1581
                mType;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1582
        MethodSymbol init = new MethodSymbol(flags, names.init,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1583
                initType, c);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1584
        init.params = createDefaultConstructorParams(make, baseInit, init,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1585
                argtypes, based);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1586
        List<JCVariableDecl> params = make.Params(argtypes, init);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1587
        List<JCStatement> stats = List.nil();
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1588
        if (c.type != syms.objectType) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1589
            stats = stats.prepend(SuperCall(make, typarams, params, based));
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1590
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1591
        result = make.MethodDef(init, make.Block(0, stats));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1594
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1595
    private List<VarSymbol> createDefaultConstructorParams(
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1596
            TreeMaker make,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1597
            MethodSymbol baseInit,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1598
            MethodSymbol init,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1599
            List<Type> argtypes,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1600
            boolean based) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1601
        List<VarSymbol> initParams = null;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1602
        List<Type> argTypesList = argtypes;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1603
        if (based) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1604
            /*  In this case argtypes will have an extra type, compared to baseInit,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1605
             *  corresponding to the type of the enclosing instance i.e.:
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1606
             *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1607
             *  Inner i = outer.new Inner(1){}
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1608
             *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1609
             *  in the above example argtypes will be (Outer, int) and baseInit
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1610
             *  will have parameter's types (int). So in this case we have to add
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1611
             *  first the extra type in argtypes and then get the names of the
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1612
             *  parameters from baseInit.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1613
             */
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1614
            initParams = List.nil();
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19656
diff changeset
  1615
            VarSymbol param = new VarSymbol(PARAMETER, make.paramName(0), argtypes.head, init);
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1616
            initParams = initParams.append(param);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1617
            argTypesList = argTypesList.tail;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1618
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1619
        if (baseInit != null && baseInit.params != null &&
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1620
            baseInit.params.nonEmpty() && argTypesList.nonEmpty()) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1621
            initParams = (initParams == null) ? List.<VarSymbol>nil() : initParams;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1622
            List<VarSymbol> baseInitParams = baseInit.params;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1623
            while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) {
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 19656
diff changeset
  1624
                VarSymbol param = new VarSymbol(baseInitParams.head.flags() | PARAMETER,
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1625
                        baseInitParams.head.name, argTypesList.head, init);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1626
                initParams = initParams.append(param);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1627
                baseInitParams = baseInitParams.tail;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1628
                argTypesList = argTypesList.tail;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1629
            }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1630
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1631
        return initParams;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1632
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents: 17578
diff changeset
  1633
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
    /** Generate call to superclass constructor. This is:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
     *    super(id_0, ..., id_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
     * or, if based == true
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
     *    id_0.super(id_1,...,id_n)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
     *  where id_0, ..., id_n are the names of the given parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
     *  @param make    The tree factory
06bc494ca11e Initial load
duke
parents:
diff changeset
  1645
     *  @param params  The parameters that need to be passed to super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
     *  @param typarams  The type parameters that need to be passed to super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
     *  @param based   Is first parameter a this$n?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
    JCExpressionStatement SuperCall(TreeMaker make,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
                   List<Type> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
                   List<JCVariableDecl> params,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
                   boolean based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
        JCExpression meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
        if (based) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
            meth = make.Select(make.Ident(params.head), names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
            params = params.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
            meth = make.Ident(names._super);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
        List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
        return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
}