langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
author mcimadamore
Tue, 12 Apr 2011 20:58:06 -0700
changeset 9302 13a19cf713fd
parent 9075 cba34854a40e
child 9303 eae35c201e19
permissions -rw-r--r--
7034019: ClassCastException in javac with conjunction types Summary: Resolve.mostSpecific doesn't handle case of raw override Reviewed-by: dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
     2
 * Copyright (c) 1999, 2011, 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: 5489
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: 5489
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: 5489
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.tree.*;
1534
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
    33
import com.sun.tools.javac.api.Formattable.LocalizedString;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
    34
import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import static com.sun.tools.javac.code.TypeTags.*;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
    43
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
    44
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import javax.lang.model.element.ElementVisitor;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
    47
import java.util.Map;
8634
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
    48
import java.util.Set;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
    49
import java.util.HashMap;
8634
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
    50
import java.util.HashSet;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
    51
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
/** Helper class for name resolution, used mostly by the attribution phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    54
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    55
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
public class Resolve {
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    protected static final Context.Key<Resolve> resolveKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        new Context.Key<Resolve>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
    63
    Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    Infer infer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    ClassReader reader;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    TreeInfo treeinfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    Types types;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
    71
    JCDiagnostic.Factory diags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    public final boolean boxingEnabled; // = source.allowBoxing();
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public final boolean varargsEnabled; // = source.allowVarargs();
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
    74
    public final boolean allowMethodHandles;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    private final boolean debugResolve;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
    77
    Scope polymorphicSignatureScope;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
    78
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public static Resolve instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        Resolve instance = context.get(resolveKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            instance = new Resolve(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    protected Resolve(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        context.put(resolveKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        varNotFound = new
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
    91
            SymbolNotFoundError(ABSENT_VAR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        wrongMethod = new
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
    93
            InapplicableSymbolError(syms.errSymbol);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        wrongMethods = new
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
    95
            InapplicableSymbolsError(syms.errSymbol);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        methodNotFound = new
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
    97
            SymbolNotFoundError(ABSENT_MTH);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        typeNotFound = new
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
    99
            SymbolNotFoundError(ABSENT_TYP);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   101
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        infer = Infer.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        reader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        treeinfo = TreeInfo.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        types = Types.instance(context);
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   108
        diags = JCDiagnostic.Factory.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        Source source = Source.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        boxingEnabled = source.allowBoxing();
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        varargsEnabled = source.allowVarargs();
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        Options options = Options.instance(context);
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6710
diff changeset
   113
        debugResolve = options.isSet("debugresolve");
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   114
        Target target = Target.instance(context);
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
   115
        allowMethodHandles = target.hasMethodHandles();
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   116
        polymorphicSignatureScope = new Scope(syms.noSymbol);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   117
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   118
        inapplicableMethodException = new InapplicableMethodException(diags);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /** error symbols, which are returned when resolution fails
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   123
    final SymbolNotFoundError varNotFound;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   124
    final InapplicableSymbolError wrongMethod;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   125
    final InapplicableSymbolsError wrongMethods;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   126
    final SymbolNotFoundError methodNotFound;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   127
    final SymbolNotFoundError typeNotFound;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 * Identifier resolution
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    /** An environment is "static" if its static level is greater than
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     *  the one of its outer environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    static boolean isStatic(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        return env.info.staticLevel > env.outer.info.staticLevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    /** An environment is an "initializer" if it is a constructor or
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     *  an instance initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    static boolean isInitializer(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        Symbol owner = env.info.scope.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        return owner.isConstructor() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            owner.owner.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            (owner.kind == VAR ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
             owner.kind == MTH && (owner.flags() & BLOCK) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
            (owner.flags() & STATIC) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /** Is class accessible in given evironment?
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *  @param env    The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *  @param c      The class whose accessibility is checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    public boolean isAccessible(Env<AttrContext> env, TypeSymbol c) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   157
        return isAccessible(env, c, false);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   158
    }
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   159
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   160
    public boolean isAccessible(Env<AttrContext> env, TypeSymbol c, boolean checkInner) {
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   161
        boolean isAccessible = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        switch ((short)(c.flags() & AccessFlags)) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   163
            case PRIVATE:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   164
                isAccessible =
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   165
                    env.enclClass.sym.outermostClass() ==
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   166
                    c.owner.outermostClass();
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   167
                break;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   168
            case 0:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   169
                isAccessible =
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   170
                    env.toplevel.packge == c.owner // fast special case
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   171
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   172
                    env.toplevel.packge == c.packge()
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   173
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   174
                    // Hack: this case is added since synthesized default constructors
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   175
                    // of anonymous classes should be allowed to access
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   176
                    // classes which would be inaccessible otherwise.
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   177
                    env.enclMethod != null &&
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   178
                    (env.enclMethod.mods.flags & ANONCONSTR) != 0;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   179
                break;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   180
            default: // error recovery
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   181
            case PUBLIC:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   182
                isAccessible = true;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   183
                break;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   184
            case PROTECTED:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   185
                isAccessible =
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   186
                    env.toplevel.packge == c.owner // fast special case
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   187
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   188
                    env.toplevel.packge == c.packge()
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   189
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   190
                    isInnerSubClass(env.enclClass.sym, c.owner);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   191
                break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        }
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   193
        return (checkInner == false || c.type.getEnclosingType() == Type.noType) ?
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   194
            isAccessible :
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 7635
diff changeset
   195
            isAccessible && isAccessible(env, c.type.getEnclosingType(), checkInner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        /** Is given class a subclass of given base class, or an inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
         *  of a subclass?
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
         *  Return null if no such class exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
         *  @param c     The class which is the subclass or is contained in it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
         *  @param base  The base class
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        private boolean isInnerSubClass(ClassSymbol c, Symbol base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            while (c != null && !c.isSubClass(base, types)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                c = c.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            return c != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    boolean isAccessible(Env<AttrContext> env, Type t) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   212
        return isAccessible(env, t, false);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   213
    }
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   214
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   215
    boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        return (t.tag == ARRAY)
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            ? isAccessible(env, types.elemtype(t))
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   218
            : isAccessible(env, t.tsym, checkInner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    /** Is symbol accessible as a member of given type in given evironment?
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     *  @param env    The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     *  @param site   The type of which the tested symbol is regarded
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     *                as a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     *  @param sym    The symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   228
        return isAccessible(env, site, sym, false);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   229
    }
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   230
    public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        if (sym.name == names.init && sym.owner != site.tsym) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        switch ((short)(sym.flags() & AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                (env.enclClass.sym == sym.owner // fast special case
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                 env.enclClass.sym.outermostClass() ==
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                 sym.owner.outermostClass())
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                sym.isInheritedIn(site.tsym, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                (env.toplevel.packge == sym.owner.owner // fast special case
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                 env.toplevel.packge == sym.packge())
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                &&
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   247
                isAccessible(env, site, checkInner)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                &&
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   249
                sym.isInheritedIn(site.tsym, types)
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   250
                &&
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   251
                notOverriddenIn(site, sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                (env.toplevel.packge == sym.owner.owner // fast special case
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                 env.toplevel.packge == sym.packge()
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                 isProtectedAccessible(sym, env.enclClass.sym, site)
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                 // OK to select instance method or field from 'super' or type name
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                 // (but type names should be disallowed elsewhere!)
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                 env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP)
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                &&
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   264
                isAccessible(env, site, checkInner)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                &&
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   266
                notOverriddenIn(site, sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        default: // this case includes erroneous combinations as well
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   268
            return isAccessible(env, site, checkInner) && notOverriddenIn(site, sym);
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   269
        }
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   270
    }
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   271
    //where
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   272
    /* `sym' is accessible only if not overridden by
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   273
     * another symbol which is a member of `site'
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   274
     * (because, if it is overridden, `sym' is not strictly
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   275
     * speaking a member of `site'). A polymorphic signature method
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   276
     * cannot be overridden (e.g. MH.invokeExact(Object[])).
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   277
     */
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   278
    private boolean notOverriddenIn(Type site, Symbol sym) {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   279
        if (sym.kind != MTH || sym.isConstructor() || sym.isStatic())
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   280
            return true;
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   281
        else {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   282
            Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   283
            return (s2 == null || s2 == sym || sym.owner == s2.owner ||
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   284
                    s2.isPolymorphicSignatureGeneric() ||
3372
544ec1ab333c 6846972: cannot access member of raw type when erasure change overriding into overloading
mcimadamore
parents: 3143
diff changeset
   285
                    !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        /** Is given protected symbol accessible if it is selected from given site
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
         *  and the selection takes place in given class?
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
         *  @param sym     The symbol with protected access
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
         *  @param c       The class where the access takes place
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
         *  @site          The type of the qualifier
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        private
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            while (c != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                   !(c.isSubClass(sym.owner, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                     (c.flags() & INTERFACE) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                     // In JLS 2e 6.6.2.1, the subclass restriction applies
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                     // only to instance fields and methods -- types are excluded
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                     // regardless of whether they are declared 'static' or not.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                     ((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types))))
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                c = c.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            return c != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    /** Try to instantiate the type of a method so that it fits
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     *  given type arguments and argument types. If succesful, return
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     *  the method's instantiated type, else return null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     *  The instantiation will take into account an additional leading
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     *  formal parameter if the method is an instance method seen as a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     *  of un underdetermined site In this case, we treat site as an additional
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     *  parameter and the parameters of the class containing the method as
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     *  additional type variables that get instantiated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     *  @param env         The current environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     *  @param site        The type of which the method is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     *  @param m           The method symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     *  @param argtypes    The invocation's given value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     *  @param typeargtypes    The invocation's given type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    Type rawInstantiate(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                        Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                        Symbol m,
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                        List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                        List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                        boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                        boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                        Warner warn)
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 2723
diff changeset
   333
        throws Infer.InferenceException {
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
   334
        boolean polymorphicSignature = m.isPolymorphicSignatureGeneric() && allowMethodHandles;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   335
        if (useVarargs && (m.flags() & VARARGS) == 0)
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   336
            throw inapplicableMethodException.setMessage();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        Type mt = types.memberType(site, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        // tvars is the list of formal type variables for which type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        // need to inferred.
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents: 8634
diff changeset
   341
        List<Type> tvars = null;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents: 8634
diff changeset
   342
        if (env.info.tvars != null) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents: 8634
diff changeset
   343
            tvars = types.newInstances(env.info.tvars);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents: 8634
diff changeset
   344
            mt = types.subst(mt, env.info.tvars, tvars);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents: 8634
diff changeset
   345
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        if (typeargtypes == null) typeargtypes = List.nil();
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
   347
        if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            // This is not a polymorphic method, but typeargs are supplied
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            // which is fine, see JLS3 15.12.2.1
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        } else if (mt.tag == FORALL && typeargtypes.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            ForAll pmt = (ForAll) mt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            if (typeargtypes.length() != pmt.tvars.length())
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   353
                throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            // Check type arguments are within bounds
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            List<Type> formals = pmt.tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            List<Type> actuals = typeargtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            while (formals.nonEmpty() && actuals.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                List<Type> bounds = types.subst(types.getBounds((TypeVar)formals.head),
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                                                pmt.tvars, typeargtypes);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                for (; bounds.nonEmpty(); bounds = bounds.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                    if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn))
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   362
                        throw inapplicableMethodException.setMessage("explicit.param.do.not.conform.to.bounds",actuals.head, bounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                formals = formals.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                actuals = actuals.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            mt = types.subst(pmt.qtype, pmt.tvars, typeargtypes);
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        } else if (mt.tag == FORALL) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
            ForAll pmt = (ForAll) mt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
            List<Type> tvars1 = types.newInstances(pmt.tvars);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            tvars = tvars.appendList(tvars1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
            mt = types.subst(pmt.qtype, pmt.tvars, tvars1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        // find out whether we need to go the slow route via infer
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   375
        boolean instNeeded = tvars.tail != null || /*inlined: tvars.nonEmpty()*/
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   376
                polymorphicSignature;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        for (List<Type> l = argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
             l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded;
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            if (l.head.tag == FORALL) instNeeded = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        if (instNeeded)
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   384
            return polymorphicSignature ?
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
   385
                infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes) :
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
   386
                infer.instantiateMethod(env,
5489
e7af65bf7577 6730476: invalid "unchecked generic array" warning
mcimadamore
parents: 5321
diff changeset
   387
                                    tvars,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                                    (MethodType)mt,
5846
6df0e6bcb388 6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents: 5520
diff changeset
   389
                                    m,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
                                    argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
                                    allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
                                    useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
                                    warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   394
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   395
        checkRawArgumentsAcceptable(env, argtypes, mt.getParameterTypes(),
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   396
                                allowBoxing, useVarargs, warn);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   397
        return mt;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    /** Same but returns null instead throwing a NoInstanceException
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    Type instantiate(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
                     Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
                     Symbol m,
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
                     List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
                     List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                     boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
                     boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
                     Warner warn) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            return rawInstantiate(env, site, m, argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                                  allowBoxing, useVarargs, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   413
        } catch (InapplicableMethodException ex) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    /** Check if a parameter list accepts a list of args.
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
     */
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   420
    boolean argumentsAcceptable(Env<AttrContext> env,
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   421
                                List<Type> argtypes,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
                                List<Type> formals,
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                                boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                                boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
                                Warner warn) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   426
        try {
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   427
            checkRawArgumentsAcceptable(env, argtypes, formals, allowBoxing, useVarargs, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   428
            return true;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   429
        } catch (InapplicableMethodException ex) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   430
            return false;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   431
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   432
    }
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   433
    void checkRawArgumentsAcceptable(Env<AttrContext> env,
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   434
                                List<Type> argtypes,
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   435
                                List<Type> formals,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   436
                                boolean allowBoxing,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   437
                                boolean useVarargs,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   438
                                Warner warn) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        Type varargsFormal = useVarargs ? formals.last() : null;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   440
        if (varargsFormal == null &&
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   441
                argtypes.size() != formals.size()) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   442
            throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   443
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   444
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        while (argtypes.nonEmpty() && formals.head != varargsFormal) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            boolean works = allowBoxing
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                ? types.isConvertible(argtypes.head, formals.head, warn)
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
                : types.isSubtypeUnchecked(argtypes.head, formals.head, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   449
            if (!works)
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   450
                throw inapplicableMethodException.setMessage("no.conforming.assignment.exists",
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   451
                        argtypes.head,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   452
                        formals.head);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            argtypes = argtypes.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            formals = formals.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   456
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   457
        if (formals.head != varargsFormal)
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   458
            throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   459
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   460
        if (useVarargs) {
7635
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   461
            //note: if applicability check is triggered by most specific test,
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   462
            //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5)
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   463
            Type elt = types.elemtypeOrType(varargsFormal);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   464
            while (argtypes.nonEmpty()) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   465
                if (!types.isConvertible(argtypes.head, elt, warn))
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   466
                    throw inapplicableMethodException.setMessage("varargs.argument.mismatch",
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   467
                            argtypes.head,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   468
                            elt);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   469
                argtypes = argtypes.tail;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   470
            }
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   471
            //check varargs element type accessibility
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   472
            if (!isAccessible(env, elt)) {
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   473
                Symbol location = env.enclClass.sym;
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   474
                throw inapplicableMethodException.setMessage("inaccessible.varargs.type",
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   475
                            elt,
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   476
                            Kinds.kindName(location),
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   477
                            location);
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   478
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   480
        return;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   482
    // where
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   483
        public static class InapplicableMethodException extends RuntimeException {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   484
            private static final long serialVersionUID = 0;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   485
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   486
            JCDiagnostic diagnostic;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   487
            JCDiagnostic.Factory diags;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   488
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   489
            InapplicableMethodException(JCDiagnostic.Factory diags) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   490
                this.diagnostic = null;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   491
                this.diags = diags;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   492
            }
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   493
            InapplicableMethodException setMessage() {
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   494
                this.diagnostic = null;
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   495
                return this;
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   496
            }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   497
            InapplicableMethodException setMessage(String key) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   498
                this.diagnostic = key != null ? diags.fragment(key) : null;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   499
                return this;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   500
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   501
            InapplicableMethodException setMessage(String key, Object... args) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   502
                this.diagnostic = key != null ? diags.fragment(key, args) : null;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   503
                return this;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   504
            }
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   505
            InapplicableMethodException setMessage(JCDiagnostic diag) {
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   506
                this.diagnostic = diag;
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   507
                return this;
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   508
            }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   509
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   510
            public JCDiagnostic getDiagnostic() {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   511
                return diagnostic;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   512
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   513
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   514
        private final InapplicableMethodException inapplicableMethodException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
 *  Symbol lookup
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
 *  the following naming conventions for arguments are used
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
 *       env      is the environment where the symbol was mentioned
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
 *       site     is the type of which the symbol is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
 *       name     is the symbol's name
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
 *                if no arguments are given
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
 *       argtypes are the value arguments, if we search for a method
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
 *  If no symbol was found, a ResolveError detailing the problem is returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
    /** Find field. Synthetic fields are always skipped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
     *  @param env     The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
     *  @param site    The original type from where the selection takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
     *  @param name    The name of the field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
     *  @param c       The class to search for the field. This is always
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
     *                 a superclass or implemented interface of site's class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
    Symbol findField(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                     Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                     Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
                     TypeSymbol c) {
326
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   540
        while (c.type.tag == TYPEVAR)
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   541
            c = c.type.getUpperBound().tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
        Symbol bestSoFar = varNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        while (e.scope != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            if (e.sym.kind == VAR && (e.sym.flags_field & SYNTHETIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
                return isAccessible(env, site, e.sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
                    ? e.sym : new AccessError(env, site, e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        Type st = types.supertype(c.type);
326
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   553
        if (st != null && (st.tag == CLASS || st.tag == TYPEVAR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
            sym = findField(env, site, name, st.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        for (List<Type> l = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
             bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
            sym = findField(env, site, name, l.head.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
            if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
                sym.owner != bestSoFar.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
                bestSoFar = new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
            else if (sym.kind < bestSoFar.kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    /** Resolve a field identifier, throw a fatal error if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     *  @param site      The type of the qualifying expression, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     *                   identifier is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
    public VarSymbol resolveInternalField(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
                                          Type site, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        Symbol sym = findField(env, site, name, site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        if (sym.kind == VAR) return (VarSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        else throw new FatalError(
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   582
                 diags.fragment("fatal.err.cant.locate.field",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
                                name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
    /** Find unqualified variable or field with given name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
     *  Synthetic fields always skipped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
     *  @param env     The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
     *  @param name    The name of the variable or field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
    Symbol findVar(Env<AttrContext> env, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        Symbol bestSoFar = varNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        Env<AttrContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        while (env1.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
            Scope.Entry e = env1.info.scope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
            while (e.scope != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
                   (e.sym.kind != VAR ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
                    (e.sym.flags_field & SYNTHETIC) != 0))
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
                e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            sym = (e.scope != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
                ? e.sym
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
                : findField(
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
                    env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
                if (staticOnly &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                    sym.kind == VAR &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                    sym.owner.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                    (sym.flags() & STATIC) == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                    return new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                    return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            } else if (sym.kind < bestSoFar.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
            env1 = env1.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        sym = findField(env, syms.predefClass.type, name, syms.predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        if (sym.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        if (bestSoFar.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
        Scope.Entry e = env.toplevel.namedImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            Type origin = e.getOrigin().owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            if (sym.kind == VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
                if (e.sym.owner.type != origin)
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
                    sym = sym.clone(e.getOrigin().owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
                return isAccessible(env, origin, sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
                    ? sym : new AccessError(env, origin, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        Symbol origin = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        e = env.toplevel.starImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            if (sym.kind != VAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
            // invariant: sym.kind == VAR
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            if (bestSoFar.kind < AMBIGUOUS && sym.owner != bestSoFar.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
                return new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            else if (bestSoFar.kind >= VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
                origin = e.getOrigin().owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                bestSoFar = isAccessible(env, origin.type, sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                    ? sym : new AccessError(env, origin.type, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
        if (bestSoFar.kind == VAR && bestSoFar.owner.type != origin.type)
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            return bestSoFar.clone(origin);
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
    Warner noteWarner = new Warner();
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    /** Select the best method for a call site among two choices.
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
     *  @param env              The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
     *  @param site             The original type from where the
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
     *                          selection takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
     *  @param argtypes         The invocation's value arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
     *  @param typeargtypes     The invocation's type arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
     *  @param sym              Proposed new best match.
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
     *  @param bestSoFar        Previously found best match.
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
     */
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   675
    @SuppressWarnings("fallthrough")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
    Symbol selectBest(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                      Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                      List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                      List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                      Symbol sym,
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
                      Symbol bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
                      boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
                      boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
                      boolean operator) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        if (sym.kind == ERR) return bestSoFar;
1649
9ec015f3661e 6776289: Regression: javac7 doesnt resolve method calls properly
mcimadamore
parents: 1534
diff changeset
   686
        if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   687
        Assert.check(sym.kind < AMBIGUOUS);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
        try {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   689
            rawInstantiate(env, site, sym, argtypes, typeargtypes,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   690
                               allowBoxing, useVarargs, Warner.noWarnings);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   691
        } catch (InapplicableMethodException ex) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
            switch (bestSoFar.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
            case ABSENT_MTH:
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
                return wrongMethod.setWrongSym(sym, ex.getDiagnostic());
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            case WRONG_MTH:
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   696
                wrongMethods.addCandidate(currentStep, wrongMethod.sym, wrongMethod.explanation);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   697
            case WRONG_MTHS:
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   698
                return wrongMethods.addCandidate(currentStep, sym, ex.getDiagnostic());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
                return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
        if (!isAccessible(env, site, sym)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
            return (bestSoFar.kind == ABSENT_MTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                ? new AccessError(env, site, sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                : bestSoFar;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   707
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        return (bestSoFar.kind > AMBIGUOUS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
            ? sym
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
            : mostSpecific(sym, bestSoFar, env, site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
                           allowBoxing && operator, useVarargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
    /* Return the most specific of the two methods for a call,
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
     *  given that both are accessible and applicable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
     *  @param m1               A new candidate for most specific.
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
     *  @param m2               The previous most specific candidate.
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
     *  @param env              The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
     *  @param site             The original type from where the selection
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
     *                          takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
    Symbol mostSpecific(Symbol m1,
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
                        Symbol m2,
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
                        Env<AttrContext> env,
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   727
                        final Type site,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
                        boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
                        boolean useVarargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
        switch (m2.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
        case MTH:
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
            if (m1 == m2) return m1;
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   733
            boolean m1SignatureMoreSpecific = signatureMoreSpecific(env, site, m1, m2, allowBoxing, useVarargs);
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   734
            boolean m2SignatureMoreSpecific = signatureMoreSpecific(env, site, m2, m1, allowBoxing, useVarargs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) {
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   736
                Type mt1 = types.memberType(site, m1);
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   737
                Type mt2 = types.memberType(site, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
                if (!types.overrideEquivalent(mt1, mt2))
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   739
                    return ambiguityError(m1, m2);
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   740
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
                // same signature; select (a) the non-bridge method, or
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
                // (b) the one that overrides the other, or (c) the concrete
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
                // one, or (d) merge both abstract signatures
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   744
                if ((m1.flags() & BRIDGE) != (m2.flags() & BRIDGE))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
                    return ((m1.flags() & BRIDGE) != 0) ? m2 : m1;
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   746
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
                // if one overrides or hides the other, use it
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
                TypeSymbol m1Owner = (TypeSymbol)m1.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
                TypeSymbol m2Owner = (TypeSymbol)m2.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
                if (types.asSuper(m1Owner.type, m2Owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
                    ((m1.owner.flags_field & INTERFACE) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
                     (m2.owner.flags_field & INTERFACE) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
                    m1.overrides(m2, m1Owner, types, false))
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
                    return m1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
                if (types.asSuper(m2Owner.type, m1Owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
                    ((m2.owner.flags_field & INTERFACE) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
                     (m1.owner.flags_field & INTERFACE) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
                    m2.overrides(m1, m2Owner, types, false))
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
                    return m2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
                boolean m1Abstract = (m1.flags() & ABSTRACT) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
                boolean m2Abstract = (m2.flags() & ABSTRACT) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
                if (m1Abstract && !m2Abstract) return m2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
                if (m2Abstract && !m1Abstract) return m1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
                // both abstract or both concrete
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
                if (!m1Abstract && !m2Abstract)
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   766
                    return ambiguityError(m1, m2);
1529
a076d4cd3048 6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents: 1528
diff changeset
   767
                // check that both signatures have the same erasure
a076d4cd3048 6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents: 1528
diff changeset
   768
                if (!types.isSameTypes(m1.erasure(types).getParameterTypes(),
a076d4cd3048 6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents: 1528
diff changeset
   769
                                       m2.erasure(types).getParameterTypes()))
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   770
                    return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
                // both abstract, neither overridden; merge throws clause and result type
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   772
                Symbol mostSpecific;
9302
13a19cf713fd 7034019: ClassCastException in javac with conjunction types
mcimadamore
parents: 9075
diff changeset
   773
                if (types.returnTypeSubstitutable(mt1, mt2))
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   774
                    mostSpecific = m1;
9302
13a19cf713fd 7034019: ClassCastException in javac with conjunction types
mcimadamore
parents: 9075
diff changeset
   775
                else if (types.returnTypeSubstitutable(mt2, mt1))
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   776
                    mostSpecific = m2;
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   777
                else {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                    // Theoretically, this can't happen, but it is possible
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
                    // due to error recovery or mixing incompatible class files
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   780
                    return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                }
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
   782
                List<Type> allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes());
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
   783
                Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown);
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   784
                MethodSymbol result = new MethodSymbol(
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   785
                        mostSpecific.flags(),
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   786
                        mostSpecific.name,
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
   787
                        newSig,
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   788
                        mostSpecific.owner) {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   789
                    @Override
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   790
                    public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   791
                        if (origin == site.tsym)
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   792
                            return this;
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   793
                        else
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   794
                            return super.implementation(origin, types, checkResult);
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   795
                    }
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   796
                };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
                return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
            if (m1SignatureMoreSpecific) return m1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
            if (m2SignatureMoreSpecific) return m2;
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   801
            return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
        case AMBIGUOUS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
            AmbiguityError e = (AmbiguityError)m2;
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   804
            Symbol err1 = mostSpecific(m1, e.sym, env, site, allowBoxing, useVarargs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            Symbol err2 = mostSpecific(m1, e.sym2, env, site, allowBoxing, useVarargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            if (err1 == err2) return err1;
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   807
            if (err1 == e.sym && err2 == e.sym2) return m2;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
            if (err1 instanceof AmbiguityError &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                err2 instanceof AmbiguityError &&
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
   810
                ((AmbiguityError)err1).sym == ((AmbiguityError)err2).sym)
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   811
                return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
            else
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   813
                return ambiguityError(err1, err2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
    }
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   818
    //where
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   819
    private boolean signatureMoreSpecific(Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) {
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   820
        noteWarner.clear();
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   821
        Type mtype1 = types.memberType(site, adjustVarargs(m1, m2, useVarargs));
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   822
        return (instantiate(env, site, adjustVarargs(m2, m1, useVarargs), types.lowerBoundArgtypes(mtype1), null,
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   823
                             allowBoxing, false, noteWarner) != null ||
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   824
                 useVarargs && instantiate(env, site, adjustVarargs(m2, m1, useVarargs), types.lowerBoundArgtypes(mtype1), null,
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   825
                                           allowBoxing, true, noteWarner) != null) &&
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   826
                !noteWarner.hasLint(Lint.LintCategory.UNCHECKED);
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   827
    }
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   828
    //where
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   829
    private Symbol adjustVarargs(Symbol to, Symbol from, boolean useVarargs) {
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   830
        List<Type> fromArgs = from.type.getParameterTypes();
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   831
        List<Type> toArgs = to.type.getParameterTypes();
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   832
        if (useVarargs &&
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   833
                (from.flags() & VARARGS) != 0 &&
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   834
                (to.flags() & VARARGS) != 0) {
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   835
            Type varargsTypeFrom = fromArgs.last();
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   836
            Type varargsTypeTo = toArgs.last();
7635
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   837
            ListBuffer<Type> args = ListBuffer.lb();
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   838
            if (toArgs.length() < fromArgs.length()) {
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   839
                //if we are checking a varargs method 'from' against another varargs
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   840
                //method 'to' (where arity of 'to' < arity of 'from') then expand signature
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   841
                //of 'to' to 'fit' arity of 'from' (this means adding fake formals to 'to'
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   842
                //until 'to' signature has the same arity as 'from')
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   843
                while (fromArgs.head != varargsTypeFrom) {
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   844
                    args.append(toArgs.head == varargsTypeTo ? types.elemtype(varargsTypeTo) : toArgs.head);
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   845
                    fromArgs = fromArgs.tail;
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   846
                    toArgs = toArgs.head == varargsTypeTo ?
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   847
                        toArgs :
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   848
                        toArgs.tail;
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   849
                }
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   850
            } else {
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   851
                //formal argument list is same as original list where last
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   852
                //argument (array type) is removed
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   853
                args.appendList(toArgs.reverse().tail.reverse());
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   854
            }
7635
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   855
            //append varargs element type as last synthetic formal
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
   856
            args.append(types.elemtype(varargsTypeTo));
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
   857
            Type mtype = types.createMethodTypeWithParameters(to.type, args.toList());
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
   858
            return new MethodSymbol(to.flags_field, to.name, mtype, to.owner);
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   859
        } else {
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   860
            return to;
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   861
        }
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
   862
    }
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   863
    //where
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   864
    Symbol ambiguityError(Symbol m1, Symbol m2) {
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   865
        if (((m1.flags() | m2.flags()) & CLASH) != 0) {
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   866
            return (m1.flags() & CLASH) == 0 ? m1 : m2;
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   867
        } else {
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   868
            return new AmbiguityError(m1, m2);
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   869
        }
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   870
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
    /** Find best qualified method matching given name, type and value
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
     *  arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
     *  @param site      The original type from where the selection
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
     *                   takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
     *  @param name      The method's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
     *  @param argtypes  The method's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
     *  @param typeargtypes The method's type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
    Symbol findMethod(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
                      Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
                      Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
                      List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
                      List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
                      boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
                      boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
                      boolean operator) {
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   891
        Symbol bestSoFar = methodNotFound;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
        return findMethod(env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
                          site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
                          name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
                          argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
                          typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
                          site.tsym.type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                          true,
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   899
                          bestSoFar,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
                          allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
                          useVarargs,
8634
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
   902
                          operator,
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
   903
                          new HashSet<TypeSymbol>());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
    private Symbol findMethod(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
                              Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
                              Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
                              List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
                              List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
                              Type intype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
                              boolean abstractok,
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
                              Symbol bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
                              boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
                              boolean useVarargs,
8634
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
   916
                              boolean operator,
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
   917
                              Set<TypeSymbol> seen) {
326
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   918
        for (Type ct = intype; ct.tag == CLASS || ct.tag == TYPEVAR; ct = types.supertype(ct)) {
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   919
            while (ct.tag == TYPEVAR)
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   920
                ct = ct.getUpperBound();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
            ClassSymbol c = (ClassSymbol)ct.tsym;
8634
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
   922
            if (!seen.add(c)) return bestSoFar;
1470
6ff8524783fa 6724345: incorrect method resolution for enum classes entered as source files
mcimadamore
parents: 1260
diff changeset
   923
            if ((c.flags() & (ABSTRACT | INTERFACE | ENUM)) == 0)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
                abstractok = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            for (Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
                 e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
                 e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
                //- System.out.println(" e " + e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
                if (e.sym.kind == MTH &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
                    (e.sym.flags_field & SYNTHETIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
                    bestSoFar = selectBest(env, site, argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
                                           e.sym, bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
                                           allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
                                           useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
                                           operator);
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
            }
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
   938
            if (name == names.init)
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
   939
                break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
            //- System.out.println(" - " + bestSoFar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
            if (abstractok) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
                Symbol concrete = methodNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
                if ((bestSoFar.flags() & ABSTRACT) == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                    concrete = bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
                for (List<Type> l = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                     l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                     l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
                    bestSoFar = findMethod(env, site, name, argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
                                           typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
                                           l.head, abstractok, bestSoFar,
8634
222829aedfe4 7024568: Very long method resolution causing OOM error
mcimadamore
parents: 8622
diff changeset
   951
                                           allowBoxing, useVarargs, operator, seen);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
                if (concrete != bestSoFar &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
                    concrete.kind < ERR  && bestSoFar.kind < ERR &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
                    types.isSubSignature(concrete.type, bestSoFar.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
                    bestSoFar = concrete;
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
    /** Find unqualified method matching given name, type and value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
     *  @param name      The method's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
     *  @param argtypes  The method's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
     *  @param typeargtypes  The method's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
    Symbol findFun(Env<AttrContext> env, Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
                   List<Type> argtypes, List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
                   boolean allowBoxing, boolean useVarargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
        Symbol bestSoFar = methodNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
        Env<AttrContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
        while (env1.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
            sym = findMethod(
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
                env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
                allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
                if (staticOnly &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
                    sym.kind == MTH &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
                    sym.owner.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
                    (sym.flags() & STATIC) == 0) return new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
                else return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
            } else if (sym.kind < bestSoFar.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
            env1 = env1.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
        sym = findMethod(env, syms.predefClass.type, name, argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
                         typeargtypes, allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
        if (sym.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
            return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
        Scope.Entry e = env.toplevel.namedImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
            Type origin = e.getOrigin().owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
            if (sym.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
                if (e.sym.owner.type != origin)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
                    sym = sym.clone(e.getOrigin().owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
                if (!isAccessible(env, origin, sym))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
                    sym = new AccessError(env, origin, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
                bestSoFar = selectBest(env, origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
                                       argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
                                       sym, bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
                                       allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
        if (bestSoFar.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
            return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
        e = env.toplevel.starImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
            Type origin = e.getOrigin().owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
            if (sym.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
                if (e.sym.owner.type != origin)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
                    sym = sym.clone(e.getOrigin().owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
                if (!isAccessible(env, origin, sym))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
                    sym = new AccessError(env, origin, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
                bestSoFar = selectBest(env, origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
                                       argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
                                       sym, bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
                                       allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
    /** Load toplevel or member class with given fully qualified name and
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
     *  verify that it is accessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
     *  @param name      The fully qualified name of the class to be loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
    Symbol loadClass(Env<AttrContext> env, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
            ClassSymbol c = reader.loadClass(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
            return isAccessible(env, c) ? c : new AccessError(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
        } catch (ClassReader.BadClassFile err) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
            throw err;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
            return typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
    /** Find qualified member type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
     *  @param site      The original type from where the selection takes
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
     *                   place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
     *  @param name      The type's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
     *  @param c         The class to search for the member type. This is
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
     *                   always a superclass or implemented interface of
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
     *                   site's class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
    Symbol findMemberType(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
                          Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
                          Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
                          TypeSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
        Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
        while (e.scope != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
            if (e.sym.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
                return isAccessible(env, site, e.sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
                    ? e.sym
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
                    : new AccessError(env, site, e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
            e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
        Type st = types.supertype(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
        if (st != null && st.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
            sym = findMemberType(env, site, name, st.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
            if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
        for (List<Type> l = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
             bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
            sym = findMemberType(env, site, name, l.head.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
            if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
                sym.owner != bestSoFar.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
                bestSoFar = new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
            else if (sym.kind < bestSoFar.kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
    /** Find a global type in given scope and load corresponding class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
     *  @param scope     The scope in which to look for the type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
     *  @param name      The type's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
    Symbol findGlobalType(Env<AttrContext> env, Scope scope, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
        for (Scope.Entry e = scope.lookup(name); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
            Symbol sym = loadClass(env, e.sym.flatName());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
            if (bestSoFar.kind == TYP && sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
                bestSoFar != sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
                return new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            else if (sym.kind < bestSoFar.kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
    /** Find an unqualified type symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
     *  @param name      The type's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
    Symbol findType(Env<AttrContext> env, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
        for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
            for (Scope.Entry e = env1.info.scope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
                 e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
                 e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
                if (e.sym.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
                    if (staticOnly &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
                        e.sym.type.tag == TYPEVAR &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
                        e.sym.owner.kind == TYP) return new StaticError(e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
                    return e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
            sym = findMemberType(env1, env1.enclClass.sym.type, name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
                                 env1.enclClass.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
            if (staticOnly && sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
                sym.type.tag == CLASS &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
                sym.type.getEnclosingType().tag == CLASS &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
                env1.enclClass.sym.type.isParameterized() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
                sym.type.getEnclosingType().isParameterized())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
                return new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
            else if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
            JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
            if ((encl.sym.flags() & STATIC) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
                staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
        if (env.tree.getTag() != JCTree.IMPORT) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
            sym = findGlobalType(env, env.toplevel.namedImportScope, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
            sym = findGlobalType(env, env.toplevel.packge.members(), name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
            sym = findGlobalType(env, env.toplevel.starImportScope, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
    /** Find an unqualified identifier which matches a specified kind set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
     *  @param name      The indentifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
     *  @param kind      Indicates the possible symbol kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
     *                   (a subset of VAL, TYP, PCK).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
    Symbol findIdent(Env<AttrContext> env, Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        if ((kind & VAR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
            sym = findVar(env, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
        if ((kind & TYP) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
            sym = findType(env, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
        if ((kind & PCK) != 0) return reader.enterPackage(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
        else return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
    /** Find an identifier in a package which matches a specified kind set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
     *  @param kind      Indicates the possible symbol kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
     *                   (a nonempty subset of TYP, PCK).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
    Symbol findIdentInPackage(Env<AttrContext> env, TypeSymbol pck,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
                              Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        Name fullname = TypeSymbol.formFullName(name, pck);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
        PackageSymbol pack = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
        if ((kind & PCK) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
            pack = reader.enterPackage(fullname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
            if (pack.exists()) return pack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
        if ((kind & TYP) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
            Symbol sym = loadClass(env, fullname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
                // don't allow programs to use flatnames
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
                if (name == sym.name) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
        return (pack != null) ? pack : bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
    /** Find an identifier among the members of a given type `site'.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
     *  @param site      The type containing the symbol to be found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
     *  @param kind      Indicates the possible symbol kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
     *                   (a subset of VAL, TYP).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
    Symbol findIdentInType(Env<AttrContext> env, Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
                           Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
        if ((kind & VAR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
            sym = findField(env, site, name, site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
        if ((kind & TYP) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            sym = findMemberType(env, site, name, site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
 *  Access checking
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
 *  The following methods convert ResolveErrors to ErrorSymbols, issuing
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
 *  an error message in the process
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
    /** If `sym' is a bad symbol: report error and return errSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
     *  else pass through unchanged,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
     *  additional arguments duplicate what has been used in trying to find the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
     *  symbol (--> flyweight pattern). This improves performance since we
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
     *  expect misses to happen frequently.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
     *  @param sym       The symbol that was found, or a ResolveError.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
     *  @param site      The original type from where the selection took place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
     *  @param name      The symbol's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
     *  @param argtypes  The invocation's value arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
     *                   if we looked for a method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
     *  @param typeargtypes  The invocation's type arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
     *                   if we looked for a method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
    Symbol access(Symbol sym,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
                  DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1266
                  Symbol location,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
                  Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
                  Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
                  boolean qualified,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
                  List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
                  List<Type> typeargtypes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
        if (sym.kind >= AMBIGUOUS) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1273
            ResolveError errSym = (ResolveError)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
            if (!site.isErroneous() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
                !Type.isErroneous(argtypes) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
                (typeargtypes==null || !Type.isErroneous(typeargtypes)))
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1277
                logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1278
            sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
        return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1283
    /** Same as original access(), but without location.
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1284
     */
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1285
    Symbol access(Symbol sym,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1286
                  DiagnosticPosition pos,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1287
                  Type site,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1288
                  Name name,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1289
                  boolean qualified,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1290
                  List<Type> argtypes,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1291
                  List<Type> typeargtypes) {
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1292
        return access(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes);
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1293
    }
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1294
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1295
    /** Same as original access(), but without type arguments and arguments.
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1296
     */
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1297
    Symbol access(Symbol sym,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1298
                  DiagnosticPosition pos,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1299
                  Symbol location,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1300
                  Type site,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1301
                  Name name,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1302
                  boolean qualified) {
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1303
        if (sym.kind >= AMBIGUOUS)
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1304
            return access(sym, pos, location, site, name, qualified, List.<Type>nil(), null);
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1305
        else
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1306
            return sym;
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1307
    }
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1308
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1309
    /** Same as original access(), but without location, type arguments and arguments.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
    Symbol access(Symbol sym,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
                  DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
                  Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
                  Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
                  boolean qualified) {
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1316
        return access(sym, pos, site.tsym, site, name, qualified);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
    /** Check that sym is not an abstract method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
    void checkNonAbstract(DiagnosticPosition pos, Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
        if ((sym.flags() & ABSTRACT) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
            log.error(pos, "abstract.cant.be.accessed.directly",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
                      kindName(sym), sym, sym.location());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
 *  Debugging
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
    /** print all scopes starting with scope s and proceeding outwards.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
     *  used for debugging.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
    public void printscopes(Scope s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
        while (s != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
            if (s.owner != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
                System.err.print(s.owner + ": ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
            for (Scope.Entry e = s.elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
                if ((e.sym.flags() & ABSTRACT) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
                    System.err.print("abstract ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
                System.err.print(e.sym + " ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
            System.err.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
            s = s.next;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
    void printscopes(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
        while (env.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
            System.err.println("------------------------------");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1351
            printscopes(env.info.scope);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
            env = env.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
    public void printscopes(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
        while (t.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
            printscopes(t.tsym.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
            t = types.supertype(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
 *  Name resolution
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
 *  Naming conventions are as for symbol lookup
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
 *  Unlike the find... methods these methods will report access errors
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
    /** Resolve an unqualified (non-method) identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
     *  @param env       The environment current at the identifier use.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
     *  @param kind      The set of admissible symbol kinds for the identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
    Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
                        Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
        return access(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
            findIdent(env, name, kind),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
            pos, env.enclClass.sym.type, name, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
    /** Resolve an unqualified method identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
    Symbol resolveMethod(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
                         Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
                         Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
                         List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
                         List<Type> typeargtypes) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1394
        Symbol sym = startResolution();
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1395
        List<MethodResolutionPhase> steps = methodResolutionSteps;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1396
        while (steps.nonEmpty() &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1397
               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1398
               sym.kind >= ERRONEOUS) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1399
            currentStep = steps.head;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1400
            sym = findFun(env, name, argtypes, typeargtypes,
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1401
                    steps.head.isBoxingRequired,
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1402
                    env.info.varArgs = steps.head.isVarargsRequired);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1403
            methodResolutionCache.put(steps.head, sym);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1404
            steps = steps.tail;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
        }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1406
        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1407
            MethodResolutionPhase errPhase =
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1408
                    firstErroneousResolutionPhase();
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1409
            sym = access(methodResolutionCache.get(errPhase),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1410
                    pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1411
            env.info.varArgs = errPhase.isVarargsRequired;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
        return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1416
    private Symbol startResolution() {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1417
        wrongMethod.clear();
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1418
        wrongMethods.clear();
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1419
        return methodNotFound;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1420
    }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1421
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
    /** Resolve a qualified method identifier
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
     *  @param site      The type of the qualifying expression, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
     *                   identifier is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1430
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1431
    Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1432
                                  Type site, Name name, List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
                                  List<Type> typeargtypes) {
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1434
        return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1435
    }
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1436
    Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1437
                                  Symbol location, Type site, Name name, List<Type> argtypes,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1438
                                  List<Type> typeargtypes) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1439
        Symbol sym = startResolution();
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1440
        List<MethodResolutionPhase> steps = methodResolutionSteps;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1441
        while (steps.nonEmpty() &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1442
               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1443
               sym.kind >= ERRONEOUS) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1444
            currentStep = steps.head;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1445
            sym = findMethod(env, site, name, argtypes, typeargtypes,
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1446
                    steps.head.isBoxingRequired(),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1447
                    env.info.varArgs = steps.head.isVarargsRequired(), false);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1448
            methodResolutionCache.put(steps.head, sym);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1449
            steps = steps.tail;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
        }
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1451
        if (sym.kind >= AMBIGUOUS) {
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
  1452
            if (site.tsym.isPolymorphicSignatureGeneric()) {
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1453
                //polymorphic receiver - synthesize new method symbol
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1454
                env.info.varArgs = false;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1455
                sym = findPolymorphicSignatureInstance(env,
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
  1456
                        site, name, null, argtypes);
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1457
            }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1458
            else {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1459
                //if nothing is found return the 'first' error
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1460
                MethodResolutionPhase errPhase =
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1461
                        firstErroneousResolutionPhase();
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1462
                sym = access(methodResolutionCache.get(errPhase),
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1463
                        pos, location, site, name, true, argtypes, typeargtypes);
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1464
                env.info.varArgs = errPhase.isVarargsRequired;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1465
            }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1466
        } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1467
            //non-instantiated polymorphic signature - synthesize new method symbol
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1468
            env.info.varArgs = false;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1469
            sym = findPolymorphicSignatureInstance(env,
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
  1470
                    site, name, (MethodSymbol)sym, argtypes);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1471
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
        return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1475
    /** Find or create an implicit method of exactly the given type (after erasure).
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1476
     *  Searches in a side table, not the main scope of the site.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1477
     *  This emulates the lookup process required by JSR 292 in JVM.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1478
     *  @param env       Attribution environment
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1479
     *  @param site      The original type from where the selection takes place.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1480
     *  @param name      The method's name.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1481
     *  @param spMethod  A template for the implicit method, or null.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1482
     *  @param argtypes  The required argument types.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1483
     *  @param typeargtypes  The required type arguments.
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1484
     */
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1485
    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1486
                                            Name name,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1487
                                            MethodSymbol spMethod,  // sig. poly. method or null if none
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
  1488
                                            List<Type> argtypes) {
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1489
        Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
  1490
                site, name, spMethod, argtypes);
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1491
        long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE |
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1492
                    (spMethod != null ?
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1493
                        spMethod.flags() & Flags.AccessFlags :
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1494
                        Flags.PUBLIC | Flags.STATIC);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1495
        Symbol m = null;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1496
        for (Scope.Entry e = polymorphicSignatureScope.lookup(name);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1497
             e.scope != null;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1498
             e = e.next()) {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1499
            Symbol sym = e.sym;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1500
            if (types.isSameType(mtype, sym.type) &&
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1501
                (sym.flags() & Flags.STATIC) == (flags & Flags.STATIC) &&
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1502
                types.isSameType(sym.owner.type, site)) {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1503
               m = sym;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1504
               break;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1505
            }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1506
        }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1507
        if (m == null) {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1508
            // create the desired method
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1509
            m = new MethodSymbol(flags, name, mtype, site.tsym);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1510
            polymorphicSignatureScope.enter(m);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1511
        }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1512
        return m;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1513
    }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  1514
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
    /** Resolve a qualified method identifier, throw a fatal error if not
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
     *  found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
     *  @param site      The type of the qualifying expression, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
     *                   identifier is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
    public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
                                        Type site, Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
                                        List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
                                        List<Type> typeargtypes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
        Symbol sym = resolveQualifiedMethod(
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1530
            pos, env, site.tsym, site, name, argtypes, typeargtypes);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
        if (sym.kind == MTH) return (MethodSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
        else throw new FatalError(
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
  1533
                 diags.fragment("fatal.err.cant.locate.meth",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
                                name));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
    /** Resolve constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
     *  @param env       The environment current at the constructor invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
     *  @param site      The type of class for which a constructor is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
     *  @param argtypes  The types of the constructor invocation's value
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
     *                   arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
     *  @param typeargtypes  The types of the constructor invocation's type
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
     *                   arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1546
    Symbol resolveConstructor(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
                              Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
                              Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
                              List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
                              List<Type> typeargtypes) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1551
        Symbol sym = startResolution();
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1552
        List<MethodResolutionPhase> steps = methodResolutionSteps;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1553
        while (steps.nonEmpty() &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1554
               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1555
               sym.kind >= ERRONEOUS) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1556
            currentStep = steps.head;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1557
            sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1558
                    steps.head.isBoxingRequired(),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1559
                    env.info.varArgs = steps.head.isVarargsRequired());
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1560
            methodResolutionCache.put(steps.head, sym);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1561
            steps = steps.tail;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
        }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1563
        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1564
            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1565
            sym = access(methodResolutionCache.get(errPhase),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1566
                    pos, site, names.init, true, argtypes, typeargtypes);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  1567
            env.info.varArgs = errPhase.isVarargsRequired();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1568
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
        return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1570
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1572
    /** Resolve constructor using diamond inference.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1573
     *  @param pos       The position to use for error reporting.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1574
     *  @param env       The environment current at the constructor invocation.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1575
     *  @param site      The type of class for which a constructor is searched.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1576
     *                   The scope of this class has been touched in attribution.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1577
     *  @param argtypes  The types of the constructor invocation's value
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1578
     *                   arguments.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1579
     *  @param typeargtypes  The types of the constructor invocation's type
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1580
     *                   arguments.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1581
     */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1582
    Symbol resolveDiamond(DiagnosticPosition pos,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1583
                              Env<AttrContext> env,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1584
                              Type site,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1585
                              List<Type> argtypes,
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1586
                              List<Type> typeargtypes) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1587
        Symbol sym = startResolution();
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1588
        List<MethodResolutionPhase> steps = methodResolutionSteps;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1589
        while (steps.nonEmpty() &&
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1590
               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1591
               sym.kind >= ERRONEOUS) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1592
            currentStep = steps.head;
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1593
            sym = resolveConstructor(pos, env, site, argtypes, typeargtypes,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1594
                    steps.head.isBoxingRequired(),
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1595
                    env.info.varArgs = steps.head.isVarargsRequired());
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1596
            methodResolutionCache.put(steps.head, sym);
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1597
            steps = steps.tail;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1598
        }
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1599
        if (sym.kind >= AMBIGUOUS) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1600
            final JCDiagnostic details = sym.kind == WRONG_MTH ?
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1601
                ((InapplicableSymbolError)sym).explanation :
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1602
                null;
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1603
            Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1604
                @Override
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1605
                JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1606
                        Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1607
                    String key = details == null ?
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1608
                        "cant.apply.diamond" :
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1609
                        "cant.apply.diamond.1";
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1610
                    return diags.create(dkind, log.currentSource(), pos, key,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1611
                            diags.fragment("diamond", site.tsym), details);
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1612
                }
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1613
            };
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1614
            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1615
            sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  1616
            env.info.varArgs = errPhase.isVarargsRequired();
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1617
        }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1618
        return sym;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1619
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  1620
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
    /** Resolve constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
     *  @param env       The environment current at the constructor invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
     *  @param site      The type of class for which a constructor is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
     *  @param argtypes  The types of the constructor invocation's value
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
     *                   arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
     *  @param typeargtypes  The types of the constructor invocation's type
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
     *                   arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
     *  @param allowBoxing Allow boxing and varargs conversions.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1631
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
    Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1633
                              Type site, List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
                              List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
                              boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
                              boolean useVarargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
        Symbol sym = findMethod(env, site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
                                names.init, argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
                                typeargtypes, allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
                                useVarargs, false);
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents: 8229
diff changeset
  1641
        chk.checkDeprecated(pos, env.info.scope.owner, sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
        return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
06bc494ca11e Initial load
duke
parents:
diff changeset
  1645
    /** Resolve a constructor, throw a fatal error if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
     *  @param site      The type to be constructed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
    public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
                                        Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
                                        List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
                                        List<Type> typeargtypes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
        Symbol sym = resolveConstructor(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
            pos, env, site, argtypes, typeargtypes);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
        if (sym.kind == MTH) return (MethodSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
        else throw new FatalError(
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
  1660
                 diags.fragment("fatal.err.cant.locate.ctor", site));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
    /** Resolve operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
     *  @param optag     The tag of the operation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
     *  @param env       The environment current at the operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
     *  @param argtypes  The types of the operands.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
    Symbol resolveOperator(DiagnosticPosition pos, int optag,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
                           Env<AttrContext> env, List<Type> argtypes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
        Name name = treeinfo.operatorName(optag);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
        Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
                                null, false, false, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
        if (boxingEnabled && sym.kind >= WRONG_MTHS)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
            sym = findMethod(env, syms.predefClass.type, name, argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
                             null, true, false, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
        return access(sym, pos, env.enclClass.sym.type, name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
                      false, argtypes, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
    /** Resolve operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
     *  @param optag     The tag of the operation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
     *  @param env       The environment current at the operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
     *  @param arg       The type of the operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
    Symbol resolveUnaryOperator(DiagnosticPosition pos, int optag, Env<AttrContext> env, Type arg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
        return resolveOperator(pos, optag, env, List.of(arg));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
    /** Resolve binary operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
     *  @param optag     The tag of the operation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
     *  @param env       The environment current at the operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
     *  @param left      The types of the left operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
     *  @param right     The types of the right operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
    Symbol resolveBinaryOperator(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
                                 int optag,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
                                 Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
                                 Type left,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
                                 Type right) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
        return resolveOperator(pos, optag, env, List.of(left, right));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
     * Resolve `c.name' where name == this or name == super.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
     * @param pos           The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
     * @param env           The environment current at the expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
     * @param c             The qualifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
     * @param name          The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
    Symbol resolveSelf(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
                       Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
                       TypeSymbol c,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1716
                       Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1717
        Env<AttrContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1718
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
        while (env1.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1720
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
            if (env1.enclClass.sym == c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
                Symbol sym = env1.info.scope.lookup(name).sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
                if (sym != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
                    if (staticOnly) sym = new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
                    return access(sym, pos, env.enclClass.sym.type,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
                                  name, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
            env1 = env1.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
        log.error(pos, "not.encl.class", c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
        return syms.errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
     * Resolve `c.this' for an enclosing class c that contains the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
     * named member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
     * @param pos           The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
     * @param env           The environment current at the expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
     * @param member        The member that must be contained in the result.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
    Symbol resolveSelfContaining(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
                                 Env<AttrContext> env,
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1745
                                 Symbol member,
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1746
                                 boolean isSuperCall) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
        Name name = names._this;
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1748
        Env<AttrContext> env1 = isSuperCall ? env.outer : env;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
        boolean staticOnly = false;
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1750
        if (env1 != null) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1751
            while (env1 != null && env1.outer != null) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1752
                if (isStatic(env1)) staticOnly = true;
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1753
                if (env1.enclClass.sym.isSubClass(member.owner, types)) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1754
                    Symbol sym = env1.info.scope.lookup(name).sym;
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1755
                    if (sym != null) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1756
                        if (staticOnly) sym = new StaticError(sym);
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1757
                        return access(sym, pos, env.enclClass.sym.type,
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1758
                                      name, true);
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1759
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
                }
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1761
                if ((env1.enclClass.sym.flags() & STATIC) != 0)
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1762
                    staticOnly = true;
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1763
                env1 = env1.outer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1766
        log.error(pos, "encl.class.required", member);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1767
        return syms.errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1768
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1769
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
     * Resolve an appropriate implicit this instance for t's container.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
     * JLS2 8.8.5.1 and 15.9.2
06bc494ca11e Initial load
duke
parents:
diff changeset
  1773
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
    Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) {
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1775
        return resolveImplicitThis(pos, env, t, false);
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1776
    }
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1777
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1778
    Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t, boolean isSuperCall) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
        Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
                         ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this)
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  1781
                         : resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
        if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
            log.error(pos, "cant.ref.before.ctor.called", "this");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
        return thisType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1785
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
 *  ResolveError classes, indicating error situations when accessing symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
    public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
        AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym);
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1793
        logResolveError(error, tree.pos(), type.getEnclosingType().tsym, type.getEnclosingType(), null, null, null);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1794
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1795
    //where
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1796
    private void logResolveError(ResolveError error,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1797
            DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1798
            Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1799
            Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1800
            Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1801
            List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1802
            List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1803
        JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1804
                pos, location, site, name, argtypes, typeargtypes);
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
  1805
        if (d != null) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
  1806
            d.setFlag(DiagnosticFlag.RESOLVE_ERROR);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1807
            log.report(d);
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
  1808
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1810
1534
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  1811
    private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args");
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  1812
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  1813
    public Object methodArguments(List<Type> argtypes) {
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  1814
        return argtypes.isEmpty() ? noArgs : argtypes;
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  1815
    }
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  1816
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1817
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1818
     * Root class for resolution errors. Subclass of ResolveError
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1819
     * represent a different kinds of resolution error - as such they must
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1820
     * specify how they map into concrete compiler diagnostics.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1821
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1822
    private abstract class ResolveError extends Symbol {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1823
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1824
        /** The name of the kind of error, for debugging only. */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
        final String debugName;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1827
        ResolveError(int kind, String debugName) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1828
            super(kind, 0, null, null, null);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1829
            this.debugName = debugName;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1830
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1831
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1832
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1833
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1836
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1837
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
        public String toString() {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1839
            return debugName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1840
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1842
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1843
        public boolean exists() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1844
            return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1845
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1847
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1848
         * Create an external representation for this erroneous symbol to be
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1849
         * used during attribution - by default this returns the symbol of a
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1850
         * brand new error type which stores the original type found
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1851
         * during resolution.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1852
         *
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1853
         * @param name     the name used during resolution
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1854
         * @param location the location from which the symbol is accessed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
         */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1856
        protected Symbol access(Name name, TypeSymbol location) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1857
            return types.createErrorType(name, location, syms.errSymbol.type).tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1860
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1861
         * Create a diagnostic representing this resolution error.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1862
         *
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1863
         * @param dkind     The kind of the diagnostic to be created (e.g error).
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1864
         * @param pos       The position to be used for error reporting.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1865
         * @param site      The original type from where the selection took place.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1866
         * @param name      The name of the symbol to be resolved.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1867
         * @param argtypes  The invocation's value arguments,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1868
         *                  if we looked for a method.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1869
         * @param typeargtypes  The invocation's type arguments,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1870
         *                      if we looked for a method.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1871
         */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1872
        abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1873
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1874
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1875
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1876
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1877
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1878
                List<Type> typeargtypes);
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  1879
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1880
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1881
         * A name designates an operator if it consists
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1882
         * of a non-empty sequence of operator symbols +-~!/*%&|^<>=
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  1883
         */
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  1884
        boolean isOperator(Name name) {
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  1885
            int i = 0;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1886
            while (i < name.getByteLength() &&
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1887
                   "+-~!*/%&|^<>=".indexOf(name.getByteAt(i)) >= 0) i++;
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1888
            return i > 0 && i == name.getByteLength();
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  1889
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1892
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1893
     * This class is the root class of all resolution errors caused by
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1894
     * an invalid symbol being found during resolution.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1895
     */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1896
    abstract class InvalidSymbolError extends ResolveError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1897
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1898
        /** The invalid symbol found during resolution */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1899
        Symbol sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1900
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1901
        InvalidSymbolError(int kind, Symbol sym, String debugName) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1902
            super(kind, debugName);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1903
            this.sym = sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1904
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1905
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1906
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1907
        public boolean exists() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1908
            return true;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1909
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1910
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1911
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1912
        public String toString() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1913
             return super.toString() + " wrongSym=" + sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1914
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1915
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1916
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1917
        public Symbol access(Name name, TypeSymbol location) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1918
            if (sym.kind >= AMBIGUOUS)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1919
                return ((ResolveError)sym).access(name, location);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1920
            else if ((sym.kind & ERRONEOUS) == 0 && (sym.kind & TYP) != 0)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1921
                return types.createErrorType(name, location, sym.type).tsym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1922
            else
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1923
                return sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1924
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1925
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1926
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1927
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1928
     * InvalidSymbolError error class indicating that a symbol matching a
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1929
     * given name does not exists in a given site.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1930
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1931
    class SymbolNotFoundError extends ResolveError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1932
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1933
        SymbolNotFoundError(int kind) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1934
            super(kind, "symbol not found error");
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1935
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1936
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1937
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1938
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1939
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1940
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1941
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1942
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1943
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1944
                List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1945
            argtypes = argtypes == null ? List.<Type>nil() : argtypes;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1946
            typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1947
            if (name == names.error)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1948
                return null;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1949
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1950
            if (isOperator(name)) {
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1951
                boolean isUnaryOp = argtypes.size() == 1;
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1952
                String key = argtypes.size() == 1 ?
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1953
                    "operator.cant.be.applied" :
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1954
                    "operator.cant.be.applied.1";
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1955
                Type first = argtypes.head;
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1956
                Type second = !isUnaryOp ? argtypes.tail.head : null;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  1957
                return diags.create(dkind, log.currentSource(), pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1958
                        key, name, first, second);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1959
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1960
            boolean hasLocation = false;
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  1961
            if (location == null) {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  1962
                location = site.tsym;
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  1963
            }
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1964
            if (!location.name.isEmpty()) {
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1965
                if (location.kind == PCK && !site.tsym.exists()) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  1966
                    return diags.create(dkind, log.currentSource(), pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1967
                        "doesnt.exist", location);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1968
                }
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1969
                hasLocation = !location.name.equals(names._this) &&
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1970
                        !location.name.equals(names._super);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1971
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1972
            boolean isConstructor = kind == ABSENT_MTH &&
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1973
                    name == names.table.names.init;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1974
            KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1975
            Name idname = isConstructor ? site.tsym.name : name;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1976
            String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1977
            if (hasLocation) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  1978
                return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1979
                        errKey, kindname, idname, //symbol kindname, name
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1980
                        typeargtypes, argtypes, //type parameters and arguments (if any)
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  1981
                        getLocationDiag(location, site)); //location kindname, type
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1982
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1983
            else {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  1984
                return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1985
                        errKey, kindname, idname, //symbol kindname, name
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1986
                        typeargtypes, argtypes); //type parameters and arguments (if any)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1987
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1988
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1989
        //where
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1990
        private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1991
            String key = "cant.resolve";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1992
            String suffix = hasLocation ? ".location" : "";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1993
            switch (kindname) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1994
                case METHOD:
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1995
                case CONSTRUCTOR: {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1996
                    suffix += ".args";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1997
                    suffix += hasTypeArgs ? ".params" : "";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1998
                }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1999
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2000
            return key + suffix;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2001
        }
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2002
        private JCDiagnostic getLocationDiag(Symbol location, Type site) {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2003
            if (location.kind == VAR) {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2004
                return diags.fragment("location.1",
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2005
                    kindName(location),
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2006
                    location,
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2007
                    location.type);
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2008
            } else {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2009
                return diags.fragment("location",
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2010
                    typeKindName(site),
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2011
                    site,
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2012
                    null);
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  2013
            }
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2014
        }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2015
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2016
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2017
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2018
     * InvalidSymbolError error class indicating that a given symbol
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2019
     * (either a method, a constructor or an operand) is not applicable
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2020
     * given an actual arguments/type argument list.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2021
     */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2022
    class InapplicableSymbolError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2023
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2024
        /** An auxiliary explanation set in case of instantiation errors. */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2025
        JCDiagnostic explanation;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2026
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2027
        InapplicableSymbolError(Symbol sym) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2028
            super(WRONG_MTH, sym, "inapplicable symbol error");
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2029
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2030
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2031
        /** Update sym and explanation and return this.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2032
         */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2033
        InapplicableSymbolError setWrongSym(Symbol sym, JCDiagnostic explanation) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2034
            this.sym = sym;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2035
            if (this.sym == sym && explanation != null)
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2036
                this.explanation = explanation; //update the details
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2037
            return this;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2038
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2039
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2040
        /** Update sym and return this.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2041
         */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2042
        InapplicableSymbolError setWrongSym(Symbol sym) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2043
            this.sym = sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2044
            return this;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2045
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2046
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2047
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2048
        public String toString() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2049
            return super.toString() + " explanation=" + explanation;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2050
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2051
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2052
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2053
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2054
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2055
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2056
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2057
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2058
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2059
                List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2060
            if (name == names.error)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2061
                return null;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2062
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2063
            if (isOperator(name)) {
8237
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2064
                boolean isUnaryOp = argtypes.size() == 1;
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2065
                String key = argtypes.size() == 1 ?
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2066
                    "operator.cant.be.applied" :
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2067
                    "operator.cant.be.applied.1";
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2068
                Type first = argtypes.head;
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2069
                Type second = !isUnaryOp ? argtypes.tail.head : null;
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2070
                return diags.create(dkind, log.currentSource(), pos,
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  2071
                        key, name, first, second);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2072
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2073
            else {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2074
                Symbol ws = sym.asMemberOf(site, types);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  2075
                return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2076
                          "cant.apply.symbol" + (explanation != null ? ".1" : ""),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2077
                          kindName(ws),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2078
                          ws.name == names.init ? ws.owner.name : ws.name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2079
                          methodArguments(ws.type.getParameterTypes()),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2080
                          methodArguments(argtypes),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2081
                          kindName(ws.owner),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2082
                          ws.owner.type,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2083
                          explanation);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2084
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2085
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2086
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2087
        void clear() {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2088
            explanation = null;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2089
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2090
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2091
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2092
        public Symbol access(Name name, TypeSymbol location) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2093
            return types.createErrorType(name, location, syms.errSymbol.type).tsym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2094
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2095
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2096
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2097
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2098
     * ResolveError error class indicating that a set of symbols
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2099
     * (either methods, constructors or operands) is not applicable
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2100
     * given an actual arguments/type argument list.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2101
     */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2102
    class InapplicableSymbolsError extends ResolveError {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2103
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2104
        private List<Candidate> candidates = List.nil();
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2105
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2106
        InapplicableSymbolsError(Symbol sym) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2107
            super(WRONG_MTHS, "inapplicable symbols");
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2108
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2109
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2110
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2111
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2112
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2113
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2114
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2115
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2116
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2117
                List<Type> typeargtypes) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2118
            if (candidates.nonEmpty()) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2119
                JCDiagnostic err = diags.create(dkind,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2120
                        log.currentSource(),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2121
                        pos,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2122
                        "cant.apply.symbols",
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2123
                        name == names.init ? KindName.CONSTRUCTOR : absentKind(kind),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2124
                        getName(),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2125
                        argtypes);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2126
                return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2127
            } else {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2128
                return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2129
                    location, site, name, argtypes, typeargtypes);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2130
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2131
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2132
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2133
        //where
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2134
        List<JCDiagnostic> candidateDetails(Type site) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2135
            List<JCDiagnostic> details = List.nil();
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2136
            for (Candidate c : candidates)
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2137
                details = details.prepend(c.getDiagnostic(site));
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2138
            return details.reverse();
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2139
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2140
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2141
        Symbol addCandidate(MethodResolutionPhase currentStep, Symbol sym, JCDiagnostic details) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2142
            Candidate c = new Candidate(currentStep, sym, details);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2143
            if (c.isValid() && !candidates.contains(c))
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2144
                candidates = candidates.append(c);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2145
            return this;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2146
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2147
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2148
        void clear() {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2149
            candidates = List.nil();
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2150
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2151
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2152
        private Name getName() {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2153
            Symbol sym = candidates.head.sym;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2154
            return sym.name == names.init ?
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2155
                sym.owner.name :
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2156
                sym.name;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2157
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2158
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2159
        private class Candidate {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2160
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2161
            final MethodResolutionPhase step;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2162
            final Symbol sym;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2163
            final JCDiagnostic details;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2164
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2165
            private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2166
                this.step = step;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2167
                this.sym = sym;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2168
                this.details = details;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2169
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2170
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2171
            JCDiagnostic getDiagnostic(Type site) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2172
                return diags.fragment("inapplicable.method",
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2173
                        Kinds.kindName(sym),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2174
                        sym.location(site, types),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2175
                        sym.asMemberOf(site, types),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2176
                        details);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2177
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2178
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2179
            @Override
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2180
            public boolean equals(Object o) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2181
                if (o instanceof Candidate) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2182
                    Symbol s1 = this.sym;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2183
                    Symbol s2 = ((Candidate)o).sym;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2184
                    if  ((s1 != s2 &&
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2185
                        (s1.overrides(s2, s1.owner.type.tsym, types, false) ||
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2186
                        (s2.overrides(s1, s2.owner.type.tsym, types, false)))) ||
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2187
                        ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner))
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2188
                        return true;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2189
                }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2190
                return false;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2191
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2192
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2193
            boolean isValid() {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2194
                return  (((sym.flags() & VARARGS) != 0 && step == VARARITY) ||
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2195
                          (sym.flags() & VARARGS) == 0 && step == (boxingEnabled ? BOX : BASIC));
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2196
            }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2197
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2198
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2199
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2200
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2201
     * An InvalidSymbolError error class indicating that a symbol is not
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2202
     * accessible from a given site
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2203
     */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2204
    class AccessError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2205
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2206
        private Env<AttrContext> env;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2207
        private Type site;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2208
06bc494ca11e Initial load
duke
parents:
diff changeset
  2209
        AccessError(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2210
            this(null, null, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2211
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2212
06bc494ca11e Initial load
duke
parents:
diff changeset
  2213
        AccessError(Env<AttrContext> env, Type site, Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2214
            super(HIDDEN, sym, "access error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2215
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2216
            this.site = site;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2217
            if (debugResolve)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2218
                log.error("proc.messager", sym + " @ " + site + " is inaccessible.");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2219
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2220
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2221
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2222
        public boolean exists() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2223
            return false;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2224
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2225
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2226
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2227
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2228
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2229
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2230
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2231
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2232
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2233
                List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2234
            if (sym.owner.type.tag == ERROR)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2235
                return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2236
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2237
            if (sym.name == names.init && sym.owner != site.tsym) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2238
                return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2239
                        pos, location, site, name, argtypes, typeargtypes);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2240
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2241
            else if ((sym.flags() & PUBLIC) != 0
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2242
                || (env != null && this.site != null
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2243
                    && !isAccessible(env, this.site))) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  2244
                return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2245
                        pos, "not.def.access.class.intf.cant.access",
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2246
                    sym, sym.location());
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2247
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2248
            else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  2249
                return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2250
                        pos, "report.access", sym,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2251
                        asFlagSet(sym.flags() & (PRIVATE | PROTECTED)),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2252
                        sym.location());
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2253
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2254
            else {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  2255
                return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2256
                        pos, "not.def.public.cant.access", sym, sym.location());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2257
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2258
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2259
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2260
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2261
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2262
     * InvalidSymbolError error class indicating that an instance member
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2263
     * has erroneously been accessed from a static context.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2264
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2265
    class StaticError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2266
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2267
        StaticError(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2268
            super(STATICERR, sym, "static error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2269
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2270
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2271
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2272
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2273
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2274
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2275
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2276
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2277
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2278
                List<Type> typeargtypes) {
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2279
            Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS)
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2280
                ? types.erasure(sym.type).tsym
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2281
                : sym);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  2282
            return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2283
                    "non-static.cant.be.ref", kindName(sym), errSym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2284
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2285
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2286
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2287
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2288
     * InvalidSymbolError error class indicating that a pair of symbols
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2289
     * (either methods, constructors or operands) are ambiguous
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2290
     * given an actual arguments/type argument list.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2291
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2292
    class AmbiguityError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2293
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2294
        /** The other maximally specific symbol */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2295
        Symbol sym2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2296
06bc494ca11e Initial load
duke
parents:
diff changeset
  2297
        AmbiguityError(Symbol sym1, Symbol sym2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2298
            super(AMBIGUOUS, sym1, "ambiguity error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2299
            this.sym2 = sym2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2300
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2301
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2302
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2303
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2304
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2305
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2306
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2307
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2308
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2309
                List<Type> typeargtypes) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2310
            AmbiguityError pair = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2311
            while (true) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2312
                if (pair.sym.kind == AMBIGUOUS)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2313
                    pair = (AmbiguityError)pair.sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2314
                else if (pair.sym2.kind == AMBIGUOUS)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2315
                    pair = (AmbiguityError)pair.sym2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2316
                else break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2317
            }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2318
            Name sname = pair.sym.name;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2319
            if (sname == names.init) sname = pair.sym.owner.name;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  2320
            return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2321
                      pos, "ref.ambiguous", sname,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2322
                      kindName(pair.sym),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2323
                      pair.sym,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2324
                      pair.sym.location(site, types),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2325
                      kindName(pair.sym2),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2326
                      pair.sym2,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2327
                      pair.sym2.location(site, types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2328
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2329
    }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2330
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2331
    enum MethodResolutionPhase {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2332
        BASIC(false, false),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2333
        BOX(true, false),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2334
        VARARITY(true, true);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2335
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2336
        boolean isBoxingRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2337
        boolean isVarargsRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2338
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2339
        MethodResolutionPhase(boolean isBoxingRequired, boolean isVarargsRequired) {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2340
           this.isBoxingRequired = isBoxingRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2341
           this.isVarargsRequired = isVarargsRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2342
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2343
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2344
        public boolean isBoxingRequired() {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2345
            return isBoxingRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2346
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2347
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2348
        public boolean isVarargsRequired() {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2349
            return isVarargsRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2350
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2351
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2352
        public boolean isApplicable(boolean boxingEnabled, boolean varargsEnabled) {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2353
            return (varargsEnabled || !isVarargsRequired) &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2354
                   (boxingEnabled || !isBoxingRequired);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2355
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2356
    }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2357
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2358
    private Map<MethodResolutionPhase, Symbol> methodResolutionCache =
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2359
        new HashMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.values().length);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2360
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2361
    final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2362
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2363
    private MethodResolutionPhase currentStep = null;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2364
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2365
    private MethodResolutionPhase firstErroneousResolutionPhase() {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2366
        MethodResolutionPhase bestSoFar = BASIC;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2367
        Symbol sym = methodNotFound;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2368
        List<MethodResolutionPhase> steps = methodResolutionSteps;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2369
        while (steps.nonEmpty() &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2370
               steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2371
               sym.kind >= WRONG_MTHS) {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2372
            sym = methodResolutionCache.get(steps.head);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2373
            bestSoFar = steps.head;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2374
            steps = steps.tail;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2375
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2376
        return bestSoFar;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  2377
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2378
}