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