langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
author ohrstrom
Tue, 18 Dec 2012 10:23:40 +0100
changeset 14957 ea7808ffcf6d
parent 14953 89a34297b198
child 15037 8ba16ac61b1a
permissions -rw-r--r--
8004657: Add hooks to javac to enable reporting dependency information. Reviewed-by: jjg, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 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
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    28
import com.sun.tools.javac.api.Formattable.LocalizedString;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.code.*;
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
    30
import com.sun.tools.javac.code.Symbol.*;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    31
import com.sun.tools.javac.code.Type.*;
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
    32
import com.sun.tools.javac.comp.Attr.ResultInfo;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
    33
import com.sun.tools.javac.comp.Check.CheckContext;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
    34
import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
    35
import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
    36
import com.sun.tools.javac.comp.DeferredAttr.DeferredType;
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
    37
import com.sun.tools.javac.comp.Infer.InferenceContext;
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
    38
import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
    39
import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.tree.*;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    42
import com.sun.tools.javac.tree.JCTree.*;
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
    43
import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    44
import com.sun.tools.javac.util.*;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    45
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    46
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    47
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    49
import java.util.Arrays;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    50
import java.util.Collection;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
    51
import java.util.EnumMap;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    52
import java.util.EnumSet;
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
    53
import java.util.Iterator;
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
    54
import java.util.LinkedHashMap;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
    55
import java.util.LinkedHashSet;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    56
import java.util.Map;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
    57
import java.util.Set;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    58
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    59
import javax.lang.model.element.ElementVisitor;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
import static com.sun.tools.javac.code.Flags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
    62
import static com.sun.tools.javac.code.Flags.BLOCK;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
import static com.sun.tools.javac.code.Kinds.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
    64
import static com.sun.tools.javac.code.Kinds.ERRONEOUS;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
    65
import static com.sun.tools.javac.code.TypeTag.*;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    66
import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
    67
import static com.sun.tools.javac.tree.JCTree.Tag.*;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
    68
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
/** Helper class for name resolution, used mostly by the attribution phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    71
 *  <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
    72
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
public class Resolve {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    protected static final Context.Key<Resolve> resolveKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        new Context.Key<Resolve>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
    80
    Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    Symtab syms;
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
    83
    Attr attr;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
    84
    DeferredAttr deferredAttr;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    Infer infer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    ClassReader reader;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    TreeInfo treeinfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    Types types;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
    90
    JCDiagnostic.Factory diags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    public final boolean boxingEnabled; // = source.allowBoxing();
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    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
    93
    public final boolean allowMethodHandles;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
    94
    public final boolean allowDefaultMethods;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    private final boolean debugResolve;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
    96
    final EnumSet<VerboseResolutionMode> verboseResolutionMode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
    98
    Scope polymorphicSignatureScope;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
    99
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   100
    protected Resolve(Context context) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   101
        context.put(resolveKey, this);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   102
        syms = Symtab.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   103
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   104
        varNotFound = new
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   105
            SymbolNotFoundError(ABSENT_VAR);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   106
        methodNotFound = new
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   107
            SymbolNotFoundError(ABSENT_MTH);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   108
        typeNotFound = new
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   109
            SymbolNotFoundError(ABSENT_TYP);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   110
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   111
        names = Names.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   112
        log = Log.instance(context);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   113
        attr = Attr.instance(context);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   114
        deferredAttr = DeferredAttr.instance(context);
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   115
        chk = Check.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   116
        infer = Infer.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   117
        reader = ClassReader.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   118
        treeinfo = TreeInfo.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   119
        types = Types.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   120
        diags = JCDiagnostic.Factory.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   121
        Source source = Source.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   122
        boxingEnabled = source.allowBoxing();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   123
        varargsEnabled = source.allowVarargs();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   124
        Options options = Options.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   125
        debugResolve = options.isSet("debugresolve");
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   126
        verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   127
        Target target = Target.instance(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   128
        allowMethodHandles = target.hasMethodHandles();
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
   129
        allowDefaultMethods = source.allowDefaultMethods();
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   130
        polymorphicSignatureScope = new Scope(syms.noSymbol);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   131
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   132
        inapplicableMethodException = new InapplicableMethodException(diags);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   133
    }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   134
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   135
    /** error symbols, which are returned when resolution fails
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   136
     */
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   137
    private final SymbolNotFoundError varNotFound;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   138
    private final SymbolNotFoundError methodNotFound;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   139
    private final SymbolNotFoundError typeNotFound;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   140
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   141
    public static Resolve instance(Context context) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   142
        Resolve instance = context.get(resolveKey);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   143
        if (instance == null)
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   144
            instance = new Resolve(context);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   145
        return instance;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   146
    }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   147
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   148
    // <editor-fold defaultstate="collapsed" desc="Verbose resolution diagnostics support">
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   149
    enum VerboseResolutionMode {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   150
        SUCCESS("success"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   151
        FAILURE("failure"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   152
        APPLICABLE("applicable"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   153
        INAPPLICABLE("inapplicable"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   154
        DEFERRED_INST("deferred-inference"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   155
        PREDEF("predef"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   156
        OBJECT_INIT("object-init"),
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   157
        INTERNAL("internal");
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   158
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14724
diff changeset
   159
        final String opt;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   160
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   161
        private VerboseResolutionMode(String opt) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   162
            this.opt = opt;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   163
        }
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   164
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   165
        static EnumSet<VerboseResolutionMode> getVerboseResolutionMode(Options opts) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   166
            String s = opts.get("verboseResolution");
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   167
            EnumSet<VerboseResolutionMode> res = EnumSet.noneOf(VerboseResolutionMode.class);
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   168
            if (s == null) return res;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   169
            if (s.contains("all")) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   170
                res = EnumSet.allOf(VerboseResolutionMode.class);
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   171
            }
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   172
            Collection<String> args = Arrays.asList(s.split(","));
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   173
            for (VerboseResolutionMode mode : values()) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   174
                if (args.contains(mode.opt)) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   175
                    res.add(mode);
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   176
                } else if (args.contains("-" + mode.opt)) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   177
                    res.remove(mode);
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   178
                }
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   179
            }
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   180
            return res;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   181
        }
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   182
    }
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
   183
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   184
    void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   185
            List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   186
        boolean success = bestSoFar.kind < ERRONEOUS;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   187
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   188
        if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   189
            return;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   190
        } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   191
            return;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   192
        }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   193
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   194
        if (bestSoFar.name == names.init &&
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   195
                bestSoFar.owner == syms.objectType.tsym &&
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   196
                !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   197
            return; //skip diags for Object constructor resolution
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   198
        } else if (site == syms.predefClass.type &&
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   199
                !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   200
            return; //skip spurious diags for predef symbols (i.e. operators)
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   201
        } else if (currentResolutionContext.internalResolution &&
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   202
                !verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   203
            return;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   204
        }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   205
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   206
        int pos = 0;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   207
        int mostSpecificPos = -1;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   208
        ListBuffer<JCDiagnostic> subDiags = ListBuffer.lb();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   209
        for (Candidate c : currentResolutionContext.candidates) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   210
            if (currentResolutionContext.step != c.step ||
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   211
                    (c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE)) ||
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   212
                    (!c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   213
                continue;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   214
            } else {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   215
                subDiags.append(c.isApplicable() ?
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   216
                        getVerboseApplicableCandidateDiag(pos, c.sym, c.mtype) :
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   217
                        getVerboseInapplicableCandidateDiag(pos, c.sym, c.details));
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   218
                if (c.sym == bestSoFar)
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   219
                    mostSpecificPos = pos;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   220
                pos++;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   221
            }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   222
        }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   223
        String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1";
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   224
        List<Type> argtypes2 = Type.map(argtypes,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   225
                    deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, bestSoFar, currentResolutionContext.step));
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   226
        JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   227
                site.tsym, mostSpecificPos, currentResolutionContext.step,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   228
                methodArguments(argtypes2),
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   229
                methodArguments(typeargtypes));
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   230
        JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList());
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   231
        log.report(d);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   234
    JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   235
        JCDiagnostic subDiag = null;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   236
        if (sym.type.hasTag(FORALL)) {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
   237
            subDiag = diags.fragment("partial.inst.sig", inst);
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   238
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   240
        String key = subDiag == null ?
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   241
                "applicable.method.found" :
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   242
                "applicable.method.found.1";
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   243
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   244
        return diags.fragment(key, pos, sym, subDiag);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   247
    JCDiagnostic getVerboseInapplicableCandidateDiag(int pos, Symbol sym, JCDiagnostic subDiag) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   248
        return diags.fragment("not.applicable.method.found", pos, sym, subDiag);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   249
    }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
   250
    // </editor-fold>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
 * Identifier resolution
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    /** An environment is "static" if its static level is greater than
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     *  the one of its outer environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     */
14056
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 14052
diff changeset
   259
    protected static boolean isStatic(Env<AttrContext> env) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        return env.info.staticLevel > env.outer.info.staticLevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    /** An environment is an "initializer" if it is a constructor or
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     *  an instance initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    static boolean isInitializer(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        Symbol owner = env.info.scope.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        return owner.isConstructor() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            owner.owner.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            (owner.kind == VAR ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
             owner.kind == MTH && (owner.flags() & BLOCK) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            (owner.flags() & STATIC) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /** Is class accessible in given evironment?
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     *  @param env    The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     *  @param c      The class whose accessibility is checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    public boolean isAccessible(Env<AttrContext> env, TypeSymbol c) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   280
        return isAccessible(env, c, false);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   281
    }
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   282
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   283
    public boolean isAccessible(Env<AttrContext> env, TypeSymbol c, boolean checkInner) {
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   284
        boolean isAccessible = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        switch ((short)(c.flags() & AccessFlags)) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   286
            case PRIVATE:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   287
                isAccessible =
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   288
                    env.enclClass.sym.outermostClass() ==
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   289
                    c.owner.outermostClass();
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   290
                break;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   291
            case 0:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   292
                isAccessible =
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   293
                    env.toplevel.packge == c.owner // fast special case
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   294
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   295
                    env.toplevel.packge == c.packge()
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   296
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   297
                    // Hack: this case is added since synthesized default constructors
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   298
                    // of anonymous classes should be allowed to access
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   299
                    // classes which would be inaccessible otherwise.
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   300
                    env.enclMethod != null &&
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   301
                    (env.enclMethod.mods.flags & ANONCONSTR) != 0;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   302
                break;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   303
            default: // error recovery
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   304
            case PUBLIC:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   305
                isAccessible = true;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   306
                break;
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   307
            case PROTECTED:
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   308
                isAccessible =
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   309
                    env.toplevel.packge == c.owner // fast special case
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   310
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   311
                    env.toplevel.packge == c.packge()
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   312
                    ||
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   313
                    isInnerSubClass(env.enclClass.sym, c.owner);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   314
                break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        }
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   316
        return (checkInner == false || c.type.getEnclosingType() == Type.noType) ?
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   317
            isAccessible :
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 7635
diff changeset
   318
            isAccessible && isAccessible(env, c.type.getEnclosingType(), checkInner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        /** Is given class a subclass of given base class, or an inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
         *  of a subclass?
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
         *  Return null if no such class exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
         *  @param c     The class which is the subclass or is contained in it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
         *  @param base  The base class
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        private boolean isInnerSubClass(ClassSymbol c, Symbol base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            while (c != null && !c.isSubClass(base, types)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                c = c.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            return c != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    boolean isAccessible(Env<AttrContext> env, Type t) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   335
        return isAccessible(env, t, false);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   336
    }
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   337
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   338
    boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   339
        return (t.hasTag(ARRAY))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            ? isAccessible(env, types.elemtype(t))
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   341
            : isAccessible(env, t.tsym, checkInner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    /** Is symbol accessible as a member of given type in given evironment?
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     *  @param env    The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     *  @param site   The type of which the tested symbol is regarded
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     *                as a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     *  @param sym    The symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym) {
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   351
        return isAccessible(env, site, sym, false);
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   352
    }
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   353
    public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        if (sym.name == names.init && sym.owner != site.tsym) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        switch ((short)(sym.flags() & AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                (env.enclClass.sym == sym.owner // fast special case
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                 env.enclClass.sym.outermostClass() ==
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                 sym.owner.outermostClass())
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
                &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                sym.isInheritedIn(site.tsym, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
                (env.toplevel.packge == sym.owner.owner // fast special case
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                 env.toplevel.packge == sym.packge())
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                &&
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   370
                isAccessible(env, site, checkInner)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
                &&
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   372
                sym.isInheritedIn(site.tsym, types)
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   373
                &&
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   374
                notOverriddenIn(site, sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                (env.toplevel.packge == sym.owner.owner // fast special case
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
                 env.toplevel.packge == sym.packge()
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                 isProtectedAccessible(sym, env.enclClass.sym, site)
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                 // OK to select instance method or field from 'super' or type name
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
                 // (but type names should be disallowed elsewhere!)
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
                 env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP)
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                &&
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   387
                isAccessible(env, site, checkInner)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                &&
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   389
                notOverriddenIn(site, sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        default: // this case includes erroneous combinations as well
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 6721
diff changeset
   391
            return isAccessible(env, site, checkInner) && notOverriddenIn(site, sym);
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   392
        }
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   393
    }
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   394
    //where
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   395
    /* `sym' is accessible only if not overridden by
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   396
     * another symbol which is a member of `site'
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   397
     * (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
   398
     * 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
   399
     * cannot be overridden (e.g. MH.invokeExact(Object[])).
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   400
     */
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   401
    private boolean notOverriddenIn(Type site, Symbol sym) {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   402
        if (sym.kind != MTH || sym.isConstructor() || sym.isStatic())
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   403
            return true;
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   404
        else {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
   405
            Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
   406
            return (s2 == null || s2 == sym || sym.owner == s2.owner ||
3372
544ec1ab333c 6846972: cannot access member of raw type when erasure change overriding into overloading
mcimadamore
parents: 3143
diff changeset
   407
                    !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        /** Is given protected symbol accessible if it is selected from given site
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
         *  and the selection takes place in given class?
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
         *  @param sym     The symbol with protected access
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
         *  @param c       The class where the access takes place
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
         *  @site          The type of the qualifier
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        private
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            while (c != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
                   !(c.isSubClass(sym.owner, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                     (c.flags() & INTERFACE) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
                     // In JLS 2e 6.6.2.1, the subclass restriction applies
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                     // only to instance fields and methods -- types are excluded
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                     // regardless of whether they are declared 'static' or not.
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
                     ((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types))))
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
                c = c.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            return c != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   430
    /**
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   431
     * Performs a recursive scan of a type looking for accessibility problems
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   432
     * from current attribution environment
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   433
     */
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   434
    void checkAccessibleType(Env<AttrContext> env, Type t) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   435
        accessibilityChecker.visit(t, env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   436
    }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   437
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   438
    /**
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   439
     * Accessibility type-visitor
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   440
     */
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   441
    Types.SimpleVisitor<Void, Env<AttrContext>> accessibilityChecker =
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   442
            new Types.SimpleVisitor<Void, Env<AttrContext>>() {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   443
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   444
        void visit(List<Type> ts, Env<AttrContext> env) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   445
            for (Type t : ts) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   446
                visit(t, env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   447
            }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   448
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   449
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   450
        public Void visitType(Type t, Env<AttrContext> env) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   451
            return null;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   452
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   453
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   454
        @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   455
        public Void visitArrayType(ArrayType t, Env<AttrContext> env) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   456
            visit(t.elemtype, env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   457
            return null;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   458
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   459
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   460
        @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   461
        public Void visitClassType(ClassType t, Env<AttrContext> env) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   462
            visit(t.getTypeArguments(), env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   463
            if (!isAccessible(env, t, true)) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   464
                accessBase(new AccessError(t.tsym), env.tree.pos(), env.enclClass.sym, t, t.tsym.name, true);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   465
            }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   466
            return null;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   467
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   468
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   469
        @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   470
        public Void visitWildcardType(WildcardType t, Env<AttrContext> env) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   471
            visit(t.type, env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   472
            return null;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   473
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   474
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   475
        @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   476
        public Void visitMethodType(MethodType t, Env<AttrContext> env) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   477
            visit(t.getParameterTypes(), env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   478
            visit(t.getReturnType(), env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   479
            visit(t.getThrownTypes(), env);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   480
            return null;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   481
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   482
    };
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   483
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
    /** Try to instantiate the type of a method so that it fits
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
     *  given type arguments and argument types. If succesful, return
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
     *  the method's instantiated type, else return null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
     *  The instantiation will take into account an additional leading
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
     *  formal parameter if the method is an instance method seen as a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
     *  of un underdetermined site In this case, we treat site as an additional
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
     *  parameter and the parameters of the class containing the method as
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
     *  additional type variables that get instantiated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
     *  @param env         The current environment
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
     *  @param site        The type of which the method is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
     *  @param m           The method symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
     *  @param argtypes    The invocation's given value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
     *  @param typeargtypes    The invocation's given type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    Type rawInstantiate(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                        Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
                        Symbol m,
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
   504
                        ResultInfo resultInfo,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                        List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
                        List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                        boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                        boolean useVarargs,
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
   509
                        Warner warn) throws Infer.InferenceException {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
   510
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        Type mt = types.memberType(site, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        // tvars is the list of formal type variables for which type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        // need to inferred.
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
   514
        List<Type> tvars = List.nil();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        if (typeargtypes == null) typeargtypes = List.nil();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   516
        if (!mt.hasTag(FORALL) && typeargtypes.nonEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            // This is not a polymorphic method, but typeargs are supplied
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 9302
diff changeset
   518
            // which is fine, see JLS 15.12.2.1
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   519
        } else if (mt.hasTag(FORALL) && typeargtypes.nonEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
            ForAll pmt = (ForAll) mt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            if (typeargtypes.length() != pmt.tvars.length())
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   522
                throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            // Check type arguments are within bounds
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            List<Type> formals = pmt.tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            List<Type> actuals = typeargtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            while (formals.nonEmpty() && actuals.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                List<Type> bounds = types.subst(types.getBounds((TypeVar)formals.head),
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
                                                pmt.tvars, typeargtypes);
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
                for (; bounds.nonEmpty(); bounds = bounds.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
                    if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn))
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   531
                        throw inapplicableMethodException.setMessage("explicit.param.do.not.conform.to.bounds",actuals.head, bounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                formals = formals.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
                actuals = actuals.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            mt = types.subst(pmt.qtype, pmt.tvars, typeargtypes);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   536
        } else if (mt.hasTag(FORALL)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            ForAll pmt = (ForAll) mt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            List<Type> tvars1 = types.newInstances(pmt.tvars);
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            tvars = tvars.appendList(tvars1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            mt = types.subst(pmt.qtype, pmt.tvars, tvars1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        // find out whether we need to go the slow route via infer
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
   544
        boolean instNeeded = tvars.tail != null; /*inlined: tvars.nonEmpty()*/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        for (List<Type> l = argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
             l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded;
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
             l = l.tail) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   548
            if (l.head.hasTag(FORALL)) instNeeded = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        if (instNeeded)
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
   552
            return infer.instantiateMethod(env,
5489
e7af65bf7577 6730476: invalid "unchecked generic array" warning
mcimadamore
parents: 5321
diff changeset
   553
                                    tvars,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                                    (MethodType)mt,
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
   555
                                    resultInfo,
5846
6df0e6bcb388 6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents: 5520
diff changeset
   556
                                    m,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
                                    argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
                                    allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
                                    useVarargs,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   560
                                    currentResolutionContext,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
                                    warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   562
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   563
        checkRawArgumentsAcceptable(env, m, argtypes, mt.getParameterTypes(),
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   564
                                allowBoxing, useVarargs, warn);
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   565
        return mt;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   568
    Type checkMethod(Env<AttrContext> env,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   569
                     Type site,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   570
                     Symbol m,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   571
                     ResultInfo resultInfo,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   572
                     List<Type> argtypes,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   573
                     List<Type> typeargtypes,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   574
                     Warner warn) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   575
        MethodResolutionContext prevContext = currentResolutionContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   576
        try {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   577
            currentResolutionContext = new MethodResolutionContext();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   578
            currentResolutionContext.attrMode = DeferredAttr.AttrMode.CHECK;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   579
            MethodResolutionPhase step = currentResolutionContext.step = env.info.pendingResolutionPhase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   580
            return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   581
                    step.isBoxingRequired(), step.isVarargsRequired(), warn);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   582
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   583
        finally {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   584
            currentResolutionContext = prevContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   585
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   586
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   587
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
    /** Same but returns null instead throwing a NoInstanceException
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
    Type instantiate(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
                     Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
                     Symbol m,
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
   593
                     ResultInfo resultInfo,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
                     List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
                     List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                     boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                     boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                     Warner warn) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        try {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
   600
            return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
                                  allowBoxing, useVarargs, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   602
        } catch (InapplicableMethodException ex) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
    /** Check if a parameter list accepts a list of args.
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
     */
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   609
    boolean argumentsAcceptable(Env<AttrContext> env,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   610
                                Symbol msym,
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   611
                                List<Type> argtypes,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                                List<Type> formals,
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                                boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                                boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                                Warner warn) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   616
        try {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   617
            checkRawArgumentsAcceptable(env, msym, argtypes, formals, allowBoxing, useVarargs, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   618
            return true;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   619
        } catch (InapplicableMethodException ex) {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   620
            return false;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   621
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   622
    }
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   623
    /**
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   624
     * A check handler is used by the main method applicability routine in order
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   625
     * to handle specific method applicability failures. It is assumed that a class
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   626
     * implementing this interface should throw exceptions that are a subtype of
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   627
     * InapplicableMethodException (see below). Such exception will terminate the
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   628
     * method applicability check and propagate important info outwards (for the
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   629
     * purpose of generating better diagnostics).
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   630
     */
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   631
    interface MethodCheckHandler {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   632
        /* The number of actuals and formals differ */
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   633
        InapplicableMethodException arityMismatch();
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   634
        /* An actual argument type does not conform to the corresponding formal type */
13438
83729994273a 7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents: 12915
diff changeset
   635
        InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details);
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   636
        /* The element type of a varargs is not accessible in the current context */
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   637
        InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   638
    }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   639
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   640
    /**
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   641
     * Basic method check handler used within Resolve - all methods end up
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   642
     * throwing InapplicableMethodException; a diagnostic fragment that describes
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   643
     * the cause as to why the method is not applicable is set on the exception
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   644
     * before it is thrown.
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   645
     */
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   646
    MethodCheckHandler resolveHandler = new MethodCheckHandler() {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   647
            public InapplicableMethodException arityMismatch() {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   648
                return inapplicableMethodException.setMessage("arg.length.mismatch");
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   649
            }
13438
83729994273a 7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents: 12915
diff changeset
   650
            public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) {
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   651
                String key = varargs ?
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   652
                        "varargs.argument.mismatch" :
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   653
                        "no.conforming.assignment.exists";
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   654
                return inapplicableMethodException.setMessage(key,
13438
83729994273a 7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents: 12915
diff changeset
   655
                        details);
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   656
            }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   657
            public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   658
                return inapplicableMethodException.setMessage("inaccessible.varargs.type",
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   659
                        expected, Kinds.kindName(location), location);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   660
            }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   661
    };
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   662
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   663
    void checkRawArgumentsAcceptable(Env<AttrContext> env,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   664
                                Symbol msym,
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   665
                                List<Type> argtypes,
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   666
                                List<Type> formals,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   667
                                boolean allowBoxing,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   668
                                boolean useVarargs,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   669
                                Warner warn) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   670
        checkRawArgumentsAcceptable(env, msym, currentResolutionContext.attrMode(), infer.emptyContext, argtypes, formals,
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   671
                allowBoxing, useVarargs, warn, resolveHandler);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   672
    }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   673
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   674
    /**
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   675
     * Main method applicability routine. Given a list of actual types A,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   676
     * a list of formal types F, determines whether the types in A are
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   677
     * compatible (by method invocation conversion) with the types in F.
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   678
     *
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   679
     * Since this routine is shared between overload resolution and method
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   680
     * type-inference, a (possibly empty) inference context is used to convert
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   681
     * formal types to the corresponding 'undet' form ahead of a compatibility
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   682
     * check so that constraints can be propagated and collected.
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   683
     *
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   684
     * Moreover, if one or more types in A is a deferred type, this routine uses
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   685
     * DeferredAttr in order to perform deferred attribution. If one or more actual
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   686
     * deferred types are stuck, they are placed in a queue and revisited later
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   687
     * after the remainder of the arguments have been seen. If this is not sufficient
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   688
     * to 'unstuck' the argument, a cyclic inference error is called out.
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   689
     *
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   690
     * A method check handler (see above) is used in order to report errors.
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   691
     */
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   692
    void checkRawArgumentsAcceptable(final Env<AttrContext> env,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   693
                                Symbol msym,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   694
                                DeferredAttr.AttrMode mode,
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   695
                                final Infer.InferenceContext inferenceContext,
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   696
                                List<Type> argtypes,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   697
                                List<Type> formals,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   698
                                boolean allowBoxing,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   699
                                boolean useVarargs,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   700
                                Warner warn,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   701
                                final MethodCheckHandler handler) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
        Type varargsFormal = useVarargs ? formals.last() : null;
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   703
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   704
        if (varargsFormal == null &&
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   705
                argtypes.size() != formals.size()) {
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   706
            throw handler.arityMismatch(); // not enough args
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   707
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   708
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   709
        DeferredAttr.DeferredAttrContext deferredAttrContext =
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   710
                deferredAttr.new DeferredAttrContext(mode, msym, currentResolutionContext.step, inferenceContext);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   711
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        while (argtypes.nonEmpty() && formals.head != varargsFormal) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   713
            ResultInfo mresult = methodCheckResult(formals.head, allowBoxing, false, inferenceContext, deferredAttrContext, handler, warn);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   714
            mresult.check(null, argtypes.head);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            argtypes = argtypes.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            formals = formals.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
        }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   718
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   719
        if (formals.head != varargsFormal) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   720
            throw handler.arityMismatch(); // not enough args
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   721
        }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   722
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   723
        if (useVarargs) {
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   724
            //note: if applicability check is triggered by most specific test,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 10950
diff changeset
   725
            //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5)
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   726
            final Type elt = types.elemtype(varargsFormal);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   727
            ResultInfo mresult = methodCheckResult(elt, allowBoxing, true, inferenceContext, deferredAttrContext, handler, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   728
            while (argtypes.nonEmpty()) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   729
                mresult.check(null, argtypes.head);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   730
                argtypes = argtypes.tail;
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   731
            }
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   732
            //check varargs element type accessibility
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   733
            varargsAccessible(env, elt, handler, inferenceContext);
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   734
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   735
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   736
        deferredAttrContext.complete();
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   737
    }
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   738
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   739
    void varargsAccessible(final Env<AttrContext> env, final Type t, final Resolve.MethodCheckHandler handler, final InferenceContext inferenceContext) {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   740
        if (inferenceContext.free(t)) {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   741
            inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   742
                @Override
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   743
                public void typesInferred(InferenceContext inferenceContext) {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   744
                    varargsAccessible(env, inferenceContext.asInstType(t, types), handler, inferenceContext);
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   745
                }
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   746
            });
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   747
        } else {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   748
            if (!isAccessible(env, t)) {
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   749
                Symbol location = env.enclClass.sym;
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   750
                throw handler.inaccessibleVarargs(location, t);
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   751
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
    }
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   754
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   755
    /**
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   756
     * Check context to be used during method applicability checks. A method check
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   757
     * context might contain inference variables.
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   758
     */
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   759
    abstract class MethodCheckContext implements CheckContext {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   760
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   761
        MethodCheckHandler handler;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   762
        boolean useVarargs;
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   763
        Infer.InferenceContext inferenceContext;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   764
        DeferredAttrContext deferredAttrContext;
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   765
        Warner rsWarner;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   766
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   767
        public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   768
                Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) {
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   769
            this.handler = handler;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   770
            this.useVarargs = useVarargs;
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   771
            this.inferenceContext = inferenceContext;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   772
            this.deferredAttrContext = deferredAttrContext;
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   773
            this.rsWarner = rsWarner;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   774
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   775
13438
83729994273a 7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents: 12915
diff changeset
   776
        public void report(DiagnosticPosition pos, JCDiagnostic details) {
83729994273a 7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents: 12915
diff changeset
   777
            throw handler.argumentMismatch(useVarargs, details);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   778
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   779
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   780
        public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   781
            return rsWarner;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   782
        }
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   783
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   784
        public InferenceContext inferenceContext() {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   785
            return inferenceContext;
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   786
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   787
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   788
        public DeferredAttrContext deferredAttrContext() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   789
            return deferredAttrContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   790
        }
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   791
    }
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   792
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   793
    /**
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   794
     * Subclass of method check context class that implements strict method conversion.
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   795
     * Strict method conversion checks compatibility between types using subtyping tests.
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   796
     */
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   797
    class StrictMethodContext extends MethodCheckContext {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   798
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   799
        public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   800
                Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   801
            super(handler, useVarargs, inferenceContext, deferredAttrContext, rsWarner);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   802
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   803
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   804
        public boolean compatible(Type found, Type req, Warner warn) {
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   805
            return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   806
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   807
    }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   808
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   809
    /**
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   810
     * Subclass of method check context class that implements loose method conversion.
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   811
     * Loose method conversion checks compatibility between types using method conversion tests.
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   812
     */
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   813
    class LooseMethodContext extends MethodCheckContext {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   814
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   815
        public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   816
                Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   817
            super(handler, useVarargs, inferenceContext, deferredAttrContext, rsWarner);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   818
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   819
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   820
        public boolean compatible(Type found, Type req, Warner warn) {
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   821
            return types.isConvertible(found, inferenceContext.asFree(req, types), warn);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   822
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   823
    }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   824
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   825
    /**
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   826
     * Create a method check context to be used during method applicability check
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   827
     */
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   828
    ResultInfo methodCheckResult(Type to, boolean allowBoxing, boolean useVarargs,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   829
            Infer.InferenceContext inferenceContext, DeferredAttr.DeferredAttrContext deferredAttrContext,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   830
            MethodCheckHandler methodHandler, Warner rsWarner) {
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   831
        MethodCheckContext checkContext = allowBoxing ?
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   832
                new LooseMethodContext(methodHandler, useVarargs, inferenceContext, deferredAttrContext, rsWarner) :
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   833
                new StrictMethodContext(methodHandler, useVarargs, inferenceContext, deferredAttrContext, rsWarner);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   834
        return new MethodResultInfo(to, checkContext, deferredAttrContext);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   835
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   836
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   837
    class MethodResultInfo extends ResultInfo {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   838
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   839
        DeferredAttr.DeferredAttrContext deferredAttrContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   840
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   841
        public MethodResultInfo(Type pt, CheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   842
            attr.super(VAL, pt, checkContext);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   843
            this.deferredAttrContext = deferredAttrContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   844
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   845
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   846
        @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   847
        protected Type check(DiagnosticPosition pos, Type found) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   848
            if (found.hasTag(DEFERRED)) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   849
                DeferredType dt = (DeferredType)found;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   850
                return dt.check(this);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   851
            } else {
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 14047
diff changeset
   852
                return super.check(pos, chk.checkNonVoid(pos, types.capture(types.upperBound(found.baseType()))));
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8228
diff changeset
   853
            }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   854
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   855
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   856
        @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   857
        protected MethodResultInfo dup(Type newPt) {
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   858
            return new MethodResultInfo(newPt, checkContext, deferredAttrContext);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   859
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   860
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   861
        @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   862
        protected ResultInfo dup(CheckContext newContext) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   863
            return new MethodResultInfo(pt, newContext, deferredAttrContext);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
   864
        }
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   865
    }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   866
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   867
    public static class InapplicableMethodException extends RuntimeException {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   868
        private static final long serialVersionUID = 0;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   869
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   870
        JCDiagnostic diagnostic;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   871
        JCDiagnostic.Factory diags;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   872
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   873
        InapplicableMethodException(JCDiagnostic.Factory diags) {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   874
            this.diagnostic = null;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   875
            this.diags = diags;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   876
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   877
        InapplicableMethodException setMessage() {
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   878
            return setMessage((JCDiagnostic)null);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   879
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   880
        InapplicableMethodException setMessage(String key) {
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   881
            return setMessage(key != null ? diags.fragment(key) : null);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   882
        }
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   883
        InapplicableMethodException setMessage(String key, Object... args) {
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 14045
diff changeset
   884
            return setMessage(key != null ? diags.fragment(key, args) : null);
12334
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   885
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   886
        InapplicableMethodException setMessage(JCDiagnostic diag) {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   887
            this.diagnostic = diag;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   888
            return this;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   889
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   890
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   891
        public JCDiagnostic getDiagnostic() {
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   892
            return diagnostic;
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   893
        }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   894
    }
29e1bfdcba4e 7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents: 12082
diff changeset
   895
    private final InapplicableMethodException inapplicableMethodException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
 *  Symbol lookup
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
 *  the following naming conventions for arguments are used
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
 *       env      is the environment where the symbol was mentioned
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
 *       site     is the type of which the symbol is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
 *       name     is the symbol's name
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
 *                if no arguments are given
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
 *       argtypes are the value arguments, if we search for a method
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
 *  If no symbol was found, a ResolveError detailing the problem is returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
    /** Find field. Synthetic fields are always skipped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
     *  @param env     The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
     *  @param site    The original type from where the selection takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
     *  @param name    The name of the field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
     *  @param c       The class to search for the field. This is always
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
     *                 a superclass or implemented interface of site's class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
    Symbol findField(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
                     Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
                     Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
                     TypeSymbol c) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   921
        while (c.type.hasTag(TYPEVAR))
326
d51f30ce6796 6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents: 10
diff changeset
   922
            c = c.type.getUpperBound().tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
        Symbol bestSoFar = varNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
        Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
        while (e.scope != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
            if (e.sym.kind == VAR && (e.sym.flags_field & SYNTHETIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
                return isAccessible(env, site, e.sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
                    ? e.sym : new AccessError(env, site, e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
            e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
        Type st = types.supertype(c.type);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
   934
        if (st != null && (st.hasTag(CLASS) || st.hasTag(TYPEVAR))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
            sym = findField(env, site, name, st.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
            if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
        for (List<Type> l = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
             bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
            sym = findField(env, site, name, l.head.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
            if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
                sym.owner != bestSoFar.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                bestSoFar = new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
            else if (sym.kind < bestSoFar.kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
    /** Resolve a field identifier, throw a fatal error if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
     *  @param site      The type of the qualifying expression, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
     *                   identifier is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
    public VarSymbol resolveInternalField(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
                                          Type site, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
        Symbol sym = findField(env, site, name, site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
        if (sym.kind == VAR) return (VarSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
        else throw new FatalError(
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 939
diff changeset
   963
                 diags.fragment("fatal.err.cant.locate.field",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
                                name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
    /** Find unqualified variable or field with given name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
     *  Synthetic fields always skipped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
     *  @param env     The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
     *  @param name    The name of the variable or field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
    Symbol findVar(Env<AttrContext> env, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
        Symbol bestSoFar = varNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
        Env<AttrContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
        while (env1.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
            Scope.Entry e = env1.info.scope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
            while (e.scope != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
                   (e.sym.kind != VAR ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
                    (e.sym.flags_field & SYNTHETIC) != 0))
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
                e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
            sym = (e.scope != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
                ? e.sym
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
                : findField(
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
                    env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
                if (staticOnly &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
                    sym.kind == VAR &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
                    sym.owner.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
                    (sym.flags() & STATIC) == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
                    return new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
                    return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
            } else if (sym.kind < bestSoFar.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
            env1 = env1.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
        sym = findField(env, syms.predefClass.type, name, syms.predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
        if (sym.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
            return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
        if (bestSoFar.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
            return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
        Scope.Entry e = env.toplevel.namedImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
            Type origin = e.getOrigin().owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
            if (sym.kind == VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
                if (e.sym.owner.type != origin)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
                    sym = sym.clone(e.getOrigin().owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
                return isAccessible(env, origin, sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
                    ? sym : new AccessError(env, origin, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
        Symbol origin = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
        e = env.toplevel.starImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
            if (sym.kind != VAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
            // invariant: sym.kind == VAR
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
            if (bestSoFar.kind < AMBIGUOUS && sym.owner != bestSoFar.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
                return new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            else if (bestSoFar.kind >= VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
                origin = e.getOrigin().owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
                bestSoFar = isAccessible(env, origin.type, sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
                    ? sym : new AccessError(env, origin.type, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
        if (bestSoFar.kind == VAR && bestSoFar.owner.type != origin.type)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
            return bestSoFar.clone(origin);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
            return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
    Warner noteWarner = new Warner();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
    /** Select the best method for a call site among two choices.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
     *  @param env              The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
     *  @param site             The original type from where the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
     *                          selection takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
     *  @param argtypes         The invocation's value arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
     *  @param typeargtypes     The invocation's type arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
     *  @param sym              Proposed new best match.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
     *  @param bestSoFar        Previously found best match.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
     */
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1056
    @SuppressWarnings("fallthrough")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
    Symbol selectBest(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
                      Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
                      List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
                      List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                      Symbol sym,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
                      Symbol bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
                      boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
                      boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
                      boolean operator) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1066
        if (sym.kind == ERR ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1067
                !sym.isInheritedIn(site.tsym, types) ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1068
                (useVarargs && (sym.flags() & VARARGS) == 0)) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1069
            return bestSoFar;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1070
        }
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
  1071
        Assert.check(sym.kind < AMBIGUOUS);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
        try {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12335
diff changeset
  1073
            Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1074
                               allowBoxing, useVarargs, types.noWarnings);
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  1075
            if (!operator)
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  1076
                currentResolutionContext.addApplicableCandidate(sym, mt);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  1077
        } catch (InapplicableMethodException ex) {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  1078
            if (!operator)
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  1079
                currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
            switch (bestSoFar.kind) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1081
                case ABSENT_MTH:
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1082
                    return new InapplicableSymbolError(currentResolutionContext);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1083
                case WRONG_MTH:
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1084
                    if (operator) return bestSoFar;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1085
                    bestSoFar = new InapplicableSymbolsError(currentResolutionContext);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1086
                default:
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1087
                    return bestSoFar;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
        if (!isAccessible(env, site, sym)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
            return (bestSoFar.kind == ABSENT_MTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
                ? new AccessError(env, site, sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
                : bestSoFar;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  1094
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
        return (bestSoFar.kind > AMBIGUOUS)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
            ? sym
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1097
            : mostSpecific(argtypes, sym, bestSoFar, env, site,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
                           allowBoxing && operator, useVarargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
    /* Return the most specific of the two methods for a call,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
     *  given that both are accessible and applicable.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
     *  @param m1               A new candidate for most specific.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
     *  @param m2               The previous most specific candidate.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
     *  @param env              The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
     *  @param site             The original type from where the selection
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
     *                          takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
     */
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1111
    Symbol mostSpecific(List<Type> argtypes, Symbol m1,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
                        Symbol m2,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
                        Env<AttrContext> env,
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1114
                        final Type site,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
                        boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
                        boolean useVarargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
        switch (m2.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
        case MTH:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
            if (m1 == m2) return m1;
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1120
            boolean m1SignatureMoreSpecific =
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1121
                    signatureMoreSpecific(argtypes, env, site, m1, m2, allowBoxing, useVarargs);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1122
            boolean m2SignatureMoreSpecific =
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1123
                    signatureMoreSpecific(argtypes, env, site, m2, m1, allowBoxing, useVarargs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
            if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) {
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1125
                Type mt1 = types.memberType(site, m1);
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1126
                Type mt2 = types.memberType(site, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
                if (!types.overrideEquivalent(mt1, mt2))
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1128
                    return ambiguityError(m1, m2);
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1129
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
                // same signature; select (a) the non-bridge method, or
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
                // (b) the one that overrides the other, or (c) the concrete
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
                // one, or (d) merge both abstract signatures
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1133
                if ((m1.flags() & BRIDGE) != (m2.flags() & BRIDGE))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
                    return ((m1.flags() & BRIDGE) != 0) ? m2 : m1;
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1135
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
                // if one overrides or hides the other, use it
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
                TypeSymbol m1Owner = (TypeSymbol)m1.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
                TypeSymbol m2Owner = (TypeSymbol)m2.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
                if (types.asSuper(m1Owner.type, m2Owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
                    ((m1.owner.flags_field & INTERFACE) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
                     (m2.owner.flags_field & INTERFACE) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
                    m1.overrides(m2, m1Owner, types, false))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                    return m1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
                if (types.asSuper(m2Owner.type, m1Owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                    ((m2.owner.flags_field & INTERFACE) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
                     (m1.owner.flags_field & INTERFACE) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
                    m2.overrides(m1, m2Owner, types, false))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
                    return m2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
                boolean m1Abstract = (m1.flags() & ABSTRACT) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
                boolean m2Abstract = (m2.flags() & ABSTRACT) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
                if (m1Abstract && !m2Abstract) return m2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
                if (m2Abstract && !m1Abstract) return m1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
                // both abstract or both concrete
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
                if (!m1Abstract && !m2Abstract)
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1155
                    return ambiguityError(m1, m2);
1529
a076d4cd3048 6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents: 1528
diff changeset
  1156
                // 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
  1157
                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
  1158
                                       m2.erasure(types).getParameterTypes()))
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1159
                    return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
                // both abstract, neither overridden; merge throws clause and result type
10197
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1161
                Type mst = mostSpecificReturnType(mt1, mt2);
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1162
                if (mst == null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
                    // Theoretically, this can't happen, but it is possible
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
                    // due to error recovery or mixing incompatible class files
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1165
                    return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
                }
10197
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1167
                Symbol mostSpecific = mst == mt1 ? m1 : m2;
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
  1168
                List<Type> allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes());
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
  1169
                Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown);
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1170
                MethodSymbol result = new MethodSymbol(
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1171
                        mostSpecific.flags(),
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1172
                        mostSpecific.name,
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
  1173
                        newSig,
2511
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1174
                        mostSpecific.owner) {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1175
                    @Override
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1176
                    public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1177
                        if (origin == site.tsym)
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1178
                            return this;
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1179
                        else
1ccb94d04005 6400189: raw types and inference
mcimadamore
parents: 1649
diff changeset
  1180
                            return super.implementation(origin, types, checkResult);
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1181
                        }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1182
                    };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
                return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
            if (m1SignatureMoreSpecific) return m1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
            if (m2SignatureMoreSpecific) return m2;
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1187
            return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
        case AMBIGUOUS:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
            AmbiguityError e = (AmbiguityError)m2;
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1190
            Symbol err1 = mostSpecific(argtypes, m1, e.sym, env, site, allowBoxing, useVarargs);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1191
            Symbol err2 = mostSpecific(argtypes, m1, e.sym2, env, site, allowBoxing, useVarargs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
            if (err1 == err2) return err1;
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1193
            if (err1 == e.sym && err2 == e.sym2) return m2;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
            if (err1 instanceof AmbiguityError &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
                err2 instanceof AmbiguityError &&
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  1196
                ((AmbiguityError)err1).sym == ((AmbiguityError)err2).sym)
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1197
                return ambiguityError(m1, m2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
            else
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1199
                return ambiguityError(err1, err2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
    }
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1204
    //where
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1205
    private boolean signatureMoreSpecific(List<Type> actuals, Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1206
        Symbol m12 = adjustVarargs(m1, m2, useVarargs);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1207
        Symbol m22 = adjustVarargs(m2, m1, useVarargs);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1208
        Type mtype1 = types.memberType(site, m12);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1209
        Type mtype2 = types.memberType(site, m22);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1210
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1211
        //check if invocation is more specific
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1212
        if (invocationMoreSpecific(env, site, m22, mtype1.getParameterTypes(), allowBoxing, useVarargs)) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1213
            return true;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1214
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1215
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1216
        //perform structural check
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1217
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1218
        List<Type> formals1 = mtype1.getParameterTypes();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1219
        Type lastFormal1 = formals1.last();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1220
        List<Type> formals2 = mtype2.getParameterTypes();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1221
        Type lastFormal2 = formals2.last();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1222
        ListBuffer<Type> newFormals = ListBuffer.lb();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1223
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1224
        boolean hasStructuralPoly = false;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1225
        for (Type actual : actuals) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1226
            //perform formal argument adaptation in case actuals > formals (varargs)
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1227
            Type f1 = formals1.isEmpty() ?
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1228
                    lastFormal1 : formals1.head;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1229
            Type f2 = formals2.isEmpty() ?
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1230
                    lastFormal2 : formals2.head;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1231
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1232
            //is this a structural actual argument?
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1233
            boolean isStructuralPoly = actual.hasTag(DEFERRED) &&
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1234
                    (((DeferredType)actual).tree.hasTag(LAMBDA) ||
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1235
                    ((DeferredType)actual).tree.hasTag(REFERENCE));
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1236
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1237
            Type newFormal = f1;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1238
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1239
            if (isStructuralPoly) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1240
                //for structural arguments only - check that corresponding formals
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1241
                //are related - if so replace formal with <null>
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1242
                hasStructuralPoly = true;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1243
                DeferredType dt = (DeferredType)actual;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1244
                Type t1 = deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, m1, currentResolutionContext.step).apply(dt);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1245
                Type t2 = deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, m2, currentResolutionContext.step).apply(dt);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1246
                if (t1.isErroneous() || t2.isErroneous() || !isStructuralSubtype(t1, t2)) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1247
                    //not structural subtypes - simply fail
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1248
                    return false;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1249
                } else {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1250
                    newFormal = syms.botType;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1251
                }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1252
            }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1253
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1254
            newFormals.append(newFormal);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1255
            if (newFormals.length() > mtype2.getParameterTypes().length()) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1256
                //expand m2's type so as to fit the new formal arity (varargs)
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1257
                m22.type = types.createMethodTypeWithParameters(m22.type, m22.type.getParameterTypes().append(f2));
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1258
            }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1259
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1260
            formals1 = formals1.isEmpty() ? formals1 : formals1.tail;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1261
            formals2 = formals2.isEmpty() ? formals2 : formals2.tail;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1262
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1263
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1264
        if (!hasStructuralPoly) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1265
            //if no structural actual was found, we're done
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1266
            return false;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1267
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1268
        //perform additional adaptation if actuals < formals (varargs)
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1269
        for (Type t : formals1) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1270
            newFormals.append(t);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1271
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1272
        //check if invocation (with tweaked args) is more specific
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1273
        return invocationMoreSpecific(env, site, m22, newFormals.toList(), allowBoxing, useVarargs);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1274
    }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1275
    //where
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1276
    private boolean invocationMoreSpecific(Env<AttrContext> env, Type site, Symbol m2, List<Type> argtypes1, boolean allowBoxing, boolean useVarargs) {
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1277
        noteWarner.clear();
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1278
        Type mst = instantiate(env, site, m2, null,
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1279
                types.lowerBounds(argtypes1), null,
9720
bc06a797f393 7042566: Regression: new ambiguity between varargs method
mcimadamore
parents: 9303
diff changeset
  1280
                allowBoxing, false, noteWarner);
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1281
        return mst != null &&
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1282
                !noteWarner.hasLint(Lint.LintCategory.UNCHECKED);
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1283
    }
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1284
    //where
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1285
    private Symbol adjustVarargs(Symbol to, Symbol from, boolean useVarargs) {
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1286
        List<Type> fromArgs = from.type.getParameterTypes();
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1287
        List<Type> toArgs = to.type.getParameterTypes();
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1288
        if (useVarargs &&
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1289
                (from.flags() & VARARGS) != 0 &&
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1290
                (to.flags() & VARARGS) != 0) {
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1291
            Type varargsTypeFrom = fromArgs.last();
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1292
            Type varargsTypeTo = toArgs.last();
7635
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1293
            ListBuffer<Type> args = ListBuffer.lb();
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1294
            if (toArgs.length() < fromArgs.length()) {
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1295
                //if we are checking a varargs method 'from' against another varargs
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1296
                //method 'to' (where arity of 'to' < arity of 'from') then expand signature
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1297
                //of 'to' to 'fit' arity of 'from' (this means adding fake formals to 'to'
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1298
                //until 'to' signature has the same arity as 'from')
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1299
                while (fromArgs.head != varargsTypeFrom) {
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1300
                    args.append(toArgs.head == varargsTypeTo ? types.elemtype(varargsTypeTo) : toArgs.head);
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1301
                    fromArgs = fromArgs.tail;
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1302
                    toArgs = toArgs.head == varargsTypeTo ?
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1303
                        toArgs :
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1304
                        toArgs.tail;
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1305
                }
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1306
            } else {
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1307
                //formal argument list is same as original list where last
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1308
                //argument (array type) is removed
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1309
                args.appendList(toArgs.reverse().tail.reverse());
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1310
            }
7635
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1311
            //append varargs element type as last synthetic formal
e0a3aeefe4e7 6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents: 7623
diff changeset
  1312
            args.append(types.elemtype(varargsTypeTo));
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8239
diff changeset
  1313
            Type mtype = types.createMethodTypeWithParameters(to.type, args.toList());
9720
bc06a797f393 7042566: Regression: new ambiguity between varargs method
mcimadamore
parents: 9303
diff changeset
  1314
            return new MethodSymbol(to.flags_field & ~VARARGS, to.name, mtype, to.owner);
7623
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1315
        } else {
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1316
            return to;
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1317
        }
66d98f7ba8c7 5088429: varargs overloading problem
mcimadamore
parents: 7209
diff changeset
  1318
    }
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1319
    //where
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1320
    boolean isStructuralSubtype(Type s, Type t) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1321
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1322
        Type ret_s = types.findDescriptorType(s).getReturnType();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1323
        Type ret_t = types.findDescriptorType(t).getReturnType();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1324
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1325
        //covariant most specific check for function descriptor return type
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1326
        if (!types.isSubtype(ret_s, ret_t)) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1327
            return false;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1328
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1329
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1330
        List<Type> args_s = types.findDescriptorType(s).getParameterTypes();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1331
        List<Type> args_t = types.findDescriptorType(t).getParameterTypes();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1332
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1333
        //arity must be identical
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1334
        if (args_s.length() != args_t.length()) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1335
            return false;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1336
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1337
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1338
        //invariant most specific check for function descriptor parameter types
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1339
        if (!types.isSameTypes(args_t, args_s)) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1340
            return false;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1341
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1342
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1343
        return true;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1344
    }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1345
    //where
10197
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1346
    Type mostSpecificReturnType(Type mt1, Type mt2) {
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1347
        Type rt1 = mt1.getReturnType();
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1348
        Type rt2 = mt2.getReturnType();
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1349
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1350
        if (mt1.hasTag(FORALL) && mt2.hasTag(FORALL)) {
10197
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1351
            //if both are generic methods, adjust return type ahead of subtyping check
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1352
            rt1 = types.subst(rt1, mt1.getTypeArguments(), mt2.getTypeArguments());
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1353
        }
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1354
        //first use subtyping, then return type substitutability
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1355
        if (types.isSubtype(rt1, rt2)) {
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1356
            return mt1;
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1357
        } else if (types.isSubtype(rt2, rt1)) {
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1358
            return mt2;
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1359
        } else if (types.returnTypeSubstitutable(mt1, mt2)) {
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1360
            return mt1;
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1361
        } else if (types.returnTypeSubstitutable(mt2, mt1)) {
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1362
            return mt2;
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1363
        } else {
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1364
            return null;
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1365
        }
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1366
    }
28afe0fb34c8 7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents: 9720
diff changeset
  1367
    //where
8228
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1368
    Symbol ambiguityError(Symbol m1, Symbol m2) {
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1369
        if (((m1.flags() | m2.flags()) & CLASH) != 0) {
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1370
            return (m1.flags() & CLASH) == 0 ? m1 : m2;
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1371
        } else {
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1372
            return new AmbiguityError(m1, m2);
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1373
        }
4e6ee38974b2 6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents: 8045
diff changeset
  1374
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1376
    Symbol findMethodInScope(Env<AttrContext> env,
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1377
            Type site,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1378
            Name name,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1379
            List<Type> argtypes,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1380
            List<Type> typeargtypes,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1381
            Scope sc,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1382
            Symbol bestSoFar,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1383
            boolean allowBoxing,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1384
            boolean useVarargs,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1385
            boolean operator,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1386
            boolean abstractok) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1387
        for (Symbol s : sc.getElementsByName(name, new LookupFilter(abstractok))) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1388
            bestSoFar = selectBest(env, site, argtypes, typeargtypes, s,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1389
                    bestSoFar, allowBoxing, useVarargs, operator);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1390
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1391
        return bestSoFar;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1392
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1393
    //where
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1394
        class LookupFilter implements Filter<Symbol> {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1395
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1396
            boolean abstractOk;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1397
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1398
            LookupFilter(boolean abstractOk) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1399
                this.abstractOk = abstractOk;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1400
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1401
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1402
            public boolean accepts(Symbol s) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1403
                long flags = s.flags();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1404
                return s.kind == MTH &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1405
                        (flags & SYNTHETIC) == 0 &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1406
                        (abstractOk ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1407
                        (flags & DEFAULT) != 0 ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1408
                        (flags & ABSTRACT) == 0);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1409
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1410
        };
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1411
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
    /** Find best qualified method matching given name, type and value
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
     *  arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
     *  @param site      The original type from where the selection
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
     *                   takes place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
     *  @param name      The method's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
     *  @param argtypes  The method's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
     *  @param typeargtypes The method's type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
    Symbol findMethod(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
                      Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
                      Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
                      List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
                      List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
                      boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
                      boolean useVarargs,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1430
                      boolean operator) {
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
  1431
        Symbol bestSoFar = methodNotFound;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
  1432
        bestSoFar = findMethod(env,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
                          site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
                          name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
                          argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
                          typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
                          site.tsym.type,
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
  1438
                          bestSoFar,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
                          allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
                          useVarargs,
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1441
                          operator);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
  1442
        reportVerboseResolutionDiagnostic(env.tree.pos(), name, site, argtypes, typeargtypes, bestSoFar);
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
  1443
        return bestSoFar;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
    private Symbol findMethod(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
                              Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
                              Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
                              List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
                              List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
                              Type intype,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
                              Symbol bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
                              boolean allowBoxing,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
                              boolean useVarargs,
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1455
                              boolean operator) {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1456
        @SuppressWarnings({"unchecked","rawtypes"})
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1457
        List<Type>[] itypes = (List<Type>[])new List[] { List.<Type>nil(), List.<Type>nil() };
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1458
        InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK;
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1459
        for (TypeSymbol s : superclasses(intype)) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1460
            bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1461
                    s.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1462
            if (name == names.init) return bestSoFar;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1463
            iphase = (iphase == null) ? null : iphase.update(s, this);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1464
            if (iphase != null) {
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1465
                for (Type itype : types.interfaces(s.type)) {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1466
                    itypes[iphase.ordinal()] = types.union(types.closure(itype), itypes[iphase.ordinal()]);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
            }
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1469
        }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1470
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1471
        Symbol concrete = bestSoFar.kind < ERR &&
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1472
                (bestSoFar.flags() & ABSTRACT) == 0 ?
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1473
                bestSoFar : methodNotFound;
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1474
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1475
        for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1476
            if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethods) break;
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1477
            //keep searching for abstract methods
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1478
            for (Type itype : itypes[iphase2.ordinal()]) {
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1479
                if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1480
                if (iphase2 == InterfaceLookupPhase.DEFAULT_OK &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1481
                        (itype.tsym.flags() & DEFAULT) == 0) continue;
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  1482
                bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1483
                        itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1484
                if (concrete != bestSoFar &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1485
                        concrete.kind < ERR  && bestSoFar.kind < ERR &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1486
                        types.isSubSignature(concrete.type, bestSoFar.type)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1487
                    //this is an hack - as javac does not do full membership checks
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1488
                    //most specific ends up comparing abstract methods that might have
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1489
                    //been implemented by some concrete method in a subclass and,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1490
                    //because of raw override, it is possible for an abstract method
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1491
                    //to be more specific than the concrete method - so we need
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1492
                    //to explicitly call that out (see CR 6178365)
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1493
                    bestSoFar = concrete;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1494
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1500
    enum InterfaceLookupPhase {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1501
        ABSTRACT_OK() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1502
            @Override
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1503
            InterfaceLookupPhase update(Symbol s, Resolve rs) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1504
                //We should not look for abstract methods if receiver is a concrete class
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1505
                //(as concrete classes are expected to implement all abstracts coming
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1506
                //from superinterfaces)
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1507
                if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1508
                    return this;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1509
                } else if (rs.allowDefaultMethods) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1510
                    return DEFAULT_OK;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1511
                } else {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1512
                    return null;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1513
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1514
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1515
        },
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1516
        DEFAULT_OK() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1517
            @Override
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1518
            InterfaceLookupPhase update(Symbol s, Resolve rs) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1519
                return this;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1520
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1521
        };
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1522
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1523
        abstract InterfaceLookupPhase update(Symbol s, Resolve rs);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1524
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1525
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1526
    /**
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1527
     * Return an Iterable object to scan the superclasses of a given type.
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1528
     * It's crucial that the scan is done lazily, as we don't want to accidentally
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1529
     * access more supertypes than strictly needed (as this could trigger completion
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1530
     * errors if some of the not-needed supertypes are missing/ill-formed).
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1531
     */
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1532
    Iterable<TypeSymbol> superclasses(final Type intype) {
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1533
        return new Iterable<TypeSymbol>() {
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1534
            public Iterator<TypeSymbol> iterator() {
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1535
                return new Iterator<TypeSymbol>() {
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1536
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1537
                    List<TypeSymbol> seen = List.nil();
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1538
                    TypeSymbol currentSym = symbolFor(intype);
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1539
                    TypeSymbol prevSym = null;
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1540
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1541
                    public boolean hasNext() {
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1542
                        if (currentSym == syms.noSymbol) {
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1543
                            currentSym = symbolFor(types.supertype(prevSym.type));
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1544
                        }
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1545
                        return currentSym != null;
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1546
                    }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1547
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1548
                    public TypeSymbol next() {
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1549
                        prevSym = currentSym;
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1550
                        currentSym = syms.noSymbol;
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1551
                        Assert.check(prevSym != null || prevSym != syms.noSymbol);
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1552
                        return prevSym;
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1553
                    }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1554
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1555
                    public void remove() {
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1556
                        throw new UnsupportedOperationException();
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1557
                    }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1558
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1559
                    TypeSymbol symbolFor(Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1560
                        if (!t.hasTag(CLASS) &&
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1561
                                !t.hasTag(TYPEVAR)) {
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1562
                            return null;
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1563
                        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1564
                        while (t.hasTag(TYPEVAR))
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1565
                            t = t.getUpperBound();
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1566
                        if (seen.contains(t.tsym)) {
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1567
                            //degenerate case in which we have a circular
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1568
                            //class hierarchy - because of ill-formed classfiles
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1569
                            return null;
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1570
                        }
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1571
                        seen = seen.prepend(t.tsym);
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14051
diff changeset
  1572
                        return t.tsym;
14045
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1573
                    }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1574
                };
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1575
            }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1576
        };
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1577
    }
c66c0a81c4ab 7193913: Cleanup Resolve.findMethod
mcimadamore
parents: 13844
diff changeset
  1578
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1579
    /** Find unqualified method matching given name, type and value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1581
     *  @param name      The method's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1582
     *  @param argtypes  The method's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1583
     *  @param typeargtypes  The method's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1584
     *  @param allowBoxing Allow boxing conversions of arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1585
     *  @param useVarargs Box trailing arguments into an array for varargs.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1586
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1587
    Symbol findFun(Env<AttrContext> env, Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1588
                   List<Type> argtypes, List<Type> typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1589
                   boolean allowBoxing, boolean useVarargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1590
        Symbol bestSoFar = methodNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1591
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
        Env<AttrContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1594
        while (env1.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1595
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1596
            sym = findMethod(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1597
                env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1598
                allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1599
            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1600
                if (staticOnly &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1601
                    sym.kind == MTH &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1602
                    sym.owner.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1603
                    (sym.flags() & STATIC) == 0) return new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1604
                else return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1605
            } else if (sym.kind < bestSoFar.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1606
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1609
            env1 = env1.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
        sym = findMethod(env, syms.predefClass.type, name, argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
                         typeargtypes, allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
        if (sym.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1615
            return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
        Scope.Entry e = env.toplevel.namedImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
            Type origin = e.getOrigin().owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
            if (sym.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
                if (e.sym.owner.type != origin)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
                    sym = sym.clone(e.getOrigin().owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
                if (!isAccessible(env, origin, sym))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
                    sym = new AccessError(env, origin, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
                bestSoFar = selectBest(env, origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
                                       argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
                                       sym, bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
                                       allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1631
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
        if (bestSoFar.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1633
            return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
        e = env.toplevel.starImportScope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
        for (; e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
            sym = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
            Type origin = e.getOrigin().owner.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
            if (sym.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
                if (e.sym.owner.type != origin)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
                    sym = sym.clone(e.getOrigin().owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
                if (!isAccessible(env, origin, sym))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
                    sym = new AccessError(env, origin, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
                bestSoFar = selectBest(env, origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1645
                                       argtypes, typeargtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
                                       sym, bestSoFar,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
                                       allowBoxing, useVarargs, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
    /** Load toplevel or member class with given fully qualified name and
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
     *  verify that it is accessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
     *  @param name      The fully qualified name of the class to be loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
    Symbol loadClass(Env<AttrContext> env, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
            ClassSymbol c = reader.loadClass(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
            return isAccessible(env, c) ? c : new AccessError(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
        } catch (ClassReader.BadClassFile err) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
            throw err;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
            return typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
    /** Find qualified member type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
     *  @param site      The original type from where the selection takes
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
     *                   place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
     *  @param name      The type's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
     *  @param c         The class to search for the member type. This is
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
     *                   always a superclass or implemented interface of
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
     *                   site's class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
    Symbol findMemberType(Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
                          Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
                          Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
                          TypeSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
        Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
        while (e.scope != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
            if (e.sym.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
                return isAccessible(env, site, e.sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
                    ? e.sym
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
                    : new AccessError(env, site, e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
            e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
        Type st = types.supertype(c.type);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1694
        if (st != null && st.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
            sym = findMemberType(env, site, name, st.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
            if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
        for (List<Type> l = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
             bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
            sym = findMemberType(env, site, name, l.head.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
            if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
                sym.owner != bestSoFar.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
                bestSoFar = new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
            else if (sym.kind < bestSoFar.kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
    /** Find a global type in given scope and load corresponding class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
     *  @param scope     The scope in which to look for the type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
     *  @param name      The type's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1716
    Symbol findGlobalType(Env<AttrContext> env, Scope scope, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1717
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1718
        for (Scope.Entry e = scope.lookup(name); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
            Symbol sym = loadClass(env, e.sym.flatName());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1720
            if (bestSoFar.kind == TYP && sym.kind == TYP &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
                bestSoFar != sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
                return new AmbiguityError(bestSoFar, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
            else if (sym.kind < bestSoFar.kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
                bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
    /** Find an unqualified type symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
     *  @param name      The type's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
    Symbol findType(Env<AttrContext> env, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
        for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
            for (Scope.Entry e = env1.info.scope.lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
                 e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
                 e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
                if (e.sym.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
                    if (staticOnly &&
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1744
                        e.sym.type.hasTag(TYPEVAR) &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
                        e.sym.owner.kind == TYP) return new StaticError(e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
                    return e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
06bc494ca11e Initial load
duke
parents:
diff changeset
  1750
            sym = findMemberType(env1, env1.enclClass.sym.type, name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1751
                                 env1.enclClass.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
            if (staticOnly && sym.kind == TYP &&
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1753
                sym.type.hasTag(CLASS) &&
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  1754
                sym.type.getEnclosingType().hasTag(CLASS) &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
                env1.enclClass.sym.type.isParameterized() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
                sym.type.getEnclosingType().isParameterized())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1757
                return new StaticError(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
            else if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
            JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
            if ((encl.sym.flags() & STATIC) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
                staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
  1766
        if (!env.tree.hasTag(IMPORT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1767
            sym = findGlobalType(env, env.toplevel.namedImportScope, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1768
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1769
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
            sym = findGlobalType(env, env.toplevel.packge.members(), name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1773
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
06bc494ca11e Initial load
duke
parents:
diff changeset
  1775
            sym = findGlobalType(env, env.toplevel.starImportScope, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1777
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1778
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
    /** Find an unqualified identifier which matches a specified kind set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
     *  @param env       The current environment.
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14446
diff changeset
  1785
     *  @param name      The identifier's name.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
     *  @param kind      Indicates the possible symbol kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
     *                   (a subset of VAL, TYP, PCK).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
    Symbol findIdent(Env<AttrContext> env, Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
06bc494ca11e Initial load
duke
parents:
diff changeset
  1793
        if ((kind & VAR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1794
            sym = findVar(env, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1795
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1796
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1797
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
        if ((kind & TYP) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
            sym = findType(env, name);
14957
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1801
            if (sym.kind==TYP) {
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1802
                 reportDependence(env.enclClass.sym, sym);
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1803
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1806
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1807
06bc494ca11e Initial load
duke
parents:
diff changeset
  1808
        if ((kind & PCK) != 0) return reader.enterPackage(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
        else return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1810
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1811
14957
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1812
    /** Report dependencies.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1813
     * @param from The enclosing class sym
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1814
     * @param to   The found identifier that the class depends on.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1815
     */
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1816
    public void reportDependence(Symbol from, Symbol to) {
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1817
        // Override if you want to collect the reported dependencies.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1818
    }
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14953
diff changeset
  1819
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1820
    /** Find an identifier in a package which matches a specified kind set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1821
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1822
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1823
     *  @param kind      Indicates the possible symbol kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
     *                   (a nonempty subset of TYP, PCK).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
    Symbol findIdentInPackage(Env<AttrContext> env, TypeSymbol pck,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1827
                              Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1828
        Name fullname = TypeSymbol.formFullName(name, pck);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1829
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1830
        PackageSymbol pack = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1831
        if ((kind & PCK) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1832
            pack = reader.enterPackage(fullname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1833
            if (pack.exists()) return pack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
        if ((kind & TYP) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1836
            Symbol sym = loadClass(env, fullname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1837
            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
                // don't allow programs to use flatnames
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
                if (name == sym.name) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1840
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
        return (pack != null) ? pack : bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1844
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1845
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
    /** Find an identifier among the members of a given type `site'.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1847
     *  @param env       The current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1848
     *  @param site      The type containing the symbol to be found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1849
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1850
     *  @param kind      Indicates the possible symbol kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
     *                   (a subset of VAL, TYP).
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
    Symbol findIdentInType(Env<AttrContext> env, Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
                           Name name, int kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
        Symbol bestSoFar = typeNotFound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
        Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1857
        if ((kind & VAR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
            sym = findField(env, site, name, site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
06bc494ca11e Initial load
duke
parents:
diff changeset
  1863
        if ((kind & TYP) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1864
            sym = findMemberType(env, site, name, site.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1865
            if (sym.exists()) return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1866
            else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1867
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1868
        return bestSoFar;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1870
06bc494ca11e Initial load
duke
parents:
diff changeset
  1871
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1872
 *  Access checking
06bc494ca11e Initial load
duke
parents:
diff changeset
  1873
 *  The following methods convert ResolveErrors to ErrorSymbols, issuing
06bc494ca11e Initial load
duke
parents:
diff changeset
  1874
 *  an error message in the process
06bc494ca11e Initial load
duke
parents:
diff changeset
  1875
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1876
06bc494ca11e Initial load
duke
parents:
diff changeset
  1877
    /** If `sym' is a bad symbol: report error and return errSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
  1878
     *  else pass through unchanged,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1879
     *  additional arguments duplicate what has been used in trying to find the
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13438
diff changeset
  1880
     *  symbol {@literal (--> flyweight pattern)}. This improves performance since we
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1881
     *  expect misses to happen frequently.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1883
     *  @param sym       The symbol that was found, or a ResolveError.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1884
     *  @param pos       The position to use for error reporting.
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1885
     *  @param location  The symbol the served as a context for this lookup
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1886
     *  @param site      The original type from where the selection took place.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1887
     *  @param name      The symbol's name.
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1888
     *  @param qualified Did we get here through a qualified expression resolution?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1889
     *  @param argtypes  The invocation's value arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
     *                   if we looked for a method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
     *  @param typeargtypes  The invocation's type arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1892
     *                   if we looked for a method.
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1893
     *  @param logResolveHelper helper class used to log resolve errors
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1894
     */
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1895
    Symbol accessInternal(Symbol sym,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1896
                  DiagnosticPosition pos,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1897
                  Symbol location,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1898
                  Type site,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1899
                  Name name,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1900
                  boolean qualified,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1901
                  List<Type> argtypes,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1902
                  List<Type> typeargtypes,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1903
                  LogResolveHelper logResolveHelper) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1904
        if (sym.kind >= AMBIGUOUS) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1905
            ResolveError errSym = (ResolveError)sym;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1906
            sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1907
            argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1908
            if (logResolveHelper.resolveDiagnosticNeeded(site, argtypes, typeargtypes)) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1909
                logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1910
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1911
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1912
        return sym;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1913
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1914
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1915
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1916
     * Variant of the generalized access routine, to be used for generating method
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1917
     * resolution diagnostics
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1918
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1919
    Symbol accessMethod(Symbol sym,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1920
                  DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1921
                  Symbol location,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1922
                  Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1923
                  Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1924
                  boolean qualified,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1925
                  List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1926
                  List<Type> typeargtypes) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1927
        return accessInternal(sym, pos, location, site, name, qualified, argtypes, typeargtypes, methodLogResolveHelper);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1928
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1929
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1930
    /** Same as original accessMethod(), but without location.
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1931
     */
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1932
    Symbol accessMethod(Symbol sym,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1933
                  DiagnosticPosition pos,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1934
                  Type site,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1935
                  Name name,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1936
                  boolean qualified,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1937
                  List<Type> argtypes,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1938
                  List<Type> typeargtypes) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1939
        return accessMethod(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes);
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1940
    }
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1941
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1942
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1943
     * Variant of the generalized access routine, to be used for generating variable,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1944
     * type resolution diagnostics
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1945
     */
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1946
    Symbol accessBase(Symbol sym,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1947
                  DiagnosticPosition pos,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1948
                  Symbol location,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1949
                  Type site,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1950
                  Name name,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1951
                  boolean qualified) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1952
        return accessInternal(sym, pos, location, site, name, qualified, List.<Type>nil(), null, basicLogResolveHelper);
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1953
    }
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  1954
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1955
    /** Same as original accessBase(), but without location.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1956
     */
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1957
    Symbol accessBase(Symbol sym,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1958
                  DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1959
                  Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1960
                  Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1961
                  boolean qualified) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1962
        return accessBase(sym, pos, site.tsym, site, name, qualified);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1963
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1964
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1965
    interface LogResolveHelper {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1966
        boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1967
        List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1968
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1969
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1970
    LogResolveHelper basicLogResolveHelper = new LogResolveHelper() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1971
        public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1972
            return !site.isErroneous();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1973
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1974
        public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1975
            return argtypes;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1976
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1977
    };
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1978
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1979
    LogResolveHelper methodLogResolveHelper = new LogResolveHelper() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1980
        public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1981
            return !site.isErroneous() &&
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1982
                        !Type.isErroneous(argtypes) &&
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1983
                        (typeargtypes == null || !Type.isErroneous(typeargtypes));
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1984
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  1985
        public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) {
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1986
            return (syms.operatorNames.contains(name)) ?
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1987
                    argtypes :
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1988
                    Type.map(argtypes, new ResolveDeferredRecoveryMap(accessedSym));
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1989
        }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1990
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1991
        class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1992
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1993
            public ResolveDeferredRecoveryMap(Symbol msym) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1994
                deferredAttr.super(AttrMode.SPECULATIVE, msym, currentResolutionContext.step);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1995
            }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1996
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1997
            @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1998
            protected Type typeOf(DeferredType dt) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  1999
                Type res = super.typeOf(dt);
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2000
                if (!res.isErroneous()) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2001
                    switch (TreeInfo.skipParens(dt.tree).getTag()) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2002
                        case LAMBDA:
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2003
                        case REFERENCE:
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2004
                            return dt;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2005
                        case CONDEXPR:
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2006
                            return res == Type.recoveryType ?
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2007
                                    dt : res;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2008
                    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2009
                }
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2010
                return res;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2011
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2012
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2013
    };
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2014
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2015
    /** Check that sym is not an abstract method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2016
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2017
    void checkNonAbstract(DiagnosticPosition pos, Symbol sym) {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2018
        if ((sym.flags() & ABSTRACT) != 0 && (sym.flags() & DEFAULT) == 0)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2019
            log.error(pos, "abstract.cant.be.accessed.directly",
06bc494ca11e Initial load
duke
parents:
diff changeset
  2020
                      kindName(sym), sym, sym.location());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2021
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2022
06bc494ca11e Initial load
duke
parents:
diff changeset
  2023
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  2024
 *  Debugging
06bc494ca11e Initial load
duke
parents:
diff changeset
  2025
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  2026
06bc494ca11e Initial load
duke
parents:
diff changeset
  2027
    /** print all scopes starting with scope s and proceeding outwards.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2028
     *  used for debugging.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2029
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2030
    public void printscopes(Scope s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2031
        while (s != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2032
            if (s.owner != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2033
                System.err.print(s.owner + ": ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2034
            for (Scope.Entry e = s.elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2035
                if ((e.sym.flags() & ABSTRACT) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2036
                    System.err.print("abstract ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2037
                System.err.print(e.sym + " ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2038
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2039
            System.err.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2040
            s = s.next;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2041
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2042
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2043
06bc494ca11e Initial load
duke
parents:
diff changeset
  2044
    void printscopes(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2045
        while (env.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2046
            System.err.println("------------------------------");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2047
            printscopes(env.info.scope);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2048
            env = env.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2049
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2050
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2051
06bc494ca11e Initial load
duke
parents:
diff changeset
  2052
    public void printscopes(Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  2053
        while (t.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2054
            printscopes(t.tsym.members());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2055
            t = types.supertype(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2056
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2057
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2058
06bc494ca11e Initial load
duke
parents:
diff changeset
  2059
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  2060
 *  Name resolution
06bc494ca11e Initial load
duke
parents:
diff changeset
  2061
 *  Naming conventions are as for symbol lookup
06bc494ca11e Initial load
duke
parents:
diff changeset
  2062
 *  Unlike the find... methods these methods will report access errors
06bc494ca11e Initial load
duke
parents:
diff changeset
  2063
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  2064
06bc494ca11e Initial load
duke
parents:
diff changeset
  2065
    /** Resolve an unqualified (non-method) identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2066
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2067
     *  @param env       The environment current at the identifier use.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2068
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2069
     *  @param kind      The set of admissible symbol kinds for the identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2070
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2071
    Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2072
                        Name name, int kind) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2073
        return accessBase(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2074
            findIdent(env, name, kind),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2075
            pos, env.enclClass.sym.type, name, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2076
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2077
06bc494ca11e Initial load
duke
parents:
diff changeset
  2078
    /** Resolve an unqualified method identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2079
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2080
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2081
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2082
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2083
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2084
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2085
    Symbol resolveMethod(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2086
                         Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2087
                         Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2088
                         List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2089
                         List<Type> typeargtypes) {
14446
88145bb2ddcd 8002286: Regression: Fix for 8000931 causes a JCK test failure
mcimadamore
parents: 14444
diff changeset
  2090
        return lookupMethod(env, pos, env.enclClass.sym, new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2091
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2092
            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2093
                return findFun(env, name, argtypes, typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2094
                        phase.isBoxingRequired(),
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2095
                        phase.isVarargsRequired());
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2096
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2097
        });
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2098
    }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  2099
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2100
    /** Resolve a qualified method identifier
06bc494ca11e Initial load
duke
parents:
diff changeset
  2101
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2102
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2103
     *  @param site      The type of the qualifying expression, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
  2104
     *                   identifier is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2105
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2106
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2107
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2109
    Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2110
                                  Type site, Name name, List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2111
                                  List<Type> typeargtypes) {
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2112
        return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2113
    }
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2114
    Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2115
                                  Symbol location, Type site, Name name, List<Type> argtypes,
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2116
                                  List<Type> typeargtypes) {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2117
        return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2118
    }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2119
    private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2120
                                  DiagnosticPosition pos, Env<AttrContext> env,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2121
                                  Symbol location, Type site, Name name, List<Type> argtypes,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2122
                                  List<Type> typeargtypes) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2123
        return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2124
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2125
            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2126
                return findMethod(env, site, name, argtypes, typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2127
                        phase.isBoxingRequired(),
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2128
                        phase.isVarargsRequired(), false);
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2129
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2130
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2131
            Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2132
                if (sym.kind >= AMBIGUOUS) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2133
                    sym = super.access(env, pos, location, sym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2134
                } else if (allowMethodHandles) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2135
                    MethodSymbol msym = (MethodSymbol)sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2136
                    if (msym.isSignaturePolymorphic(types)) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2137
                        return findPolymorphicSignatureInstance(env, sym, argtypes);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2138
                    }
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2139
                }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2140
                return sym;
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2141
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2142
        });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2144
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2145
    /** 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
  2146
     *  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
  2147
     *  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
  2148
     *  @param env       Attribution environment
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2149
     *  @param spMethod  signature polymorphic method - i.e. MH.invokeExact
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2150
     *  @param argtypes  The required argument types
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2151
     */
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2152
    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2153
                                            final Symbol spMethod,
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 8032
diff changeset
  2154
                                            List<Type> argtypes) {
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2155
        Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2156
                (MethodSymbol)spMethod, currentResolutionContext, argtypes);
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2157
        for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) {
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2158
            if (types.isSameType(mtype, sym.type)) {
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2159
               return sym;
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2160
            }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2161
        }
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2162
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2163
        // create the desired method
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2164
        long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags;
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2165
        Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2166
            @Override
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2167
            public Symbol baseSymbol() {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2168
                return spMethod;
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2169
            }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2170
        };
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2171
        polymorphicSignatureScope.enter(msym);
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
  2172
        return msym;
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2173
    }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6356
diff changeset
  2174
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2175
    /** Resolve a qualified method identifier, throw a fatal error if not
06bc494ca11e Initial load
duke
parents:
diff changeset
  2176
     *  found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2177
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2178
     *  @param env       The environment current at the method invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2179
     *  @param site      The type of the qualifying expression, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
  2180
     *                   identifier is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2181
     *  @param name      The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2182
     *  @param argtypes  The types of the invocation's value arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2183
     *  @param typeargtypes  The types of the invocation's type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2184
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2185
    public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2186
                                        Type site, Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2187
                                        List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2188
                                        List<Type> typeargtypes) {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2189
        MethodResolutionContext resolveContext = new MethodResolutionContext();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2190
        resolveContext.internalResolution = true;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2191
        Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2192
                site, name, argtypes, typeargtypes);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2193
        if (sym.kind == MTH) return (MethodSymbol)sym;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2194
        else throw new FatalError(
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2195
                 diags.fragment("fatal.err.cant.locate.meth",
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2196
                                name));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2198
06bc494ca11e Initial load
duke
parents:
diff changeset
  2199
    /** Resolve constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2200
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2201
     *  @param env       The environment current at the constructor invocation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2202
     *  @param site      The type of class for which a constructor is searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2203
     *  @param argtypes  The types of the constructor invocation's value
06bc494ca11e Initial load
duke
parents:
diff changeset
  2204
     *                   arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2205
     *  @param typeargtypes  The types of the constructor invocation's type
06bc494ca11e Initial load
duke
parents:
diff changeset
  2206
     *                   arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2207
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2208
    Symbol resolveConstructor(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2209
                              Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2210
                              Type site,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2211
                              List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2212
                              List<Type> typeargtypes) {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2213
        return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2214
    }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2215
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2216
    private Symbol resolveConstructor(MethodResolutionContext resolveContext,
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2217
                              final DiagnosticPosition pos,
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2218
                              Env<AttrContext> env,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2219
                              Type site,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2220
                              List<Type> argtypes,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2221
                              List<Type> typeargtypes) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2222
        return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2223
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2224
            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2225
                return findConstructor(pos, env, site, argtypes, typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2226
                        phase.isBoxingRequired(),
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2227
                        phase.isVarargsRequired());
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2228
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2229
        });
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2230
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2231
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2232
    /** Resolve a constructor, throw a fatal error if not found.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2233
     *  @param pos       The position to use for error reporting.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2234
     *  @param env       The environment current at the method invocation.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2235
     *  @param site      The type to be constructed.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2236
     *  @param argtypes  The types of the invocation's value arguments.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2237
     *  @param typeargtypes  The types of the invocation's type arguments.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2238
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2239
    public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2240
                                        Type site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2241
                                        List<Type> argtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2242
                                        List<Type> typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2243
        MethodResolutionContext resolveContext = new MethodResolutionContext();
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2244
        resolveContext.internalResolution = true;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2245
        Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2246
        if (sym.kind == MTH) return (MethodSymbol)sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2247
        else throw new FatalError(
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2248
                 diags.fragment("fatal.err.cant.locate.ctor", site));
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2249
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2250
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2251
    Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2252
                              Type site, List<Type> argtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2253
                              List<Type> typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2254
                              boolean allowBoxing,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2255
                              boolean useVarargs) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2256
        Symbol sym = findMethod(env, site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2257
                                    names.init, argtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2258
                                    typeargtypes, allowBoxing,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2259
                                    useVarargs, false);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2260
        chk.checkDeprecated(pos, env.info.scope.owner, sym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2261
        return sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2262
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2263
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2264
    /** Resolve constructor using diamond inference.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2265
     *  @param pos       The position to use for error reporting.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2266
     *  @param env       The environment current at the constructor invocation.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2267
     *  @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
  2268
     *                   The scope of this class has been touched in attribution.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2269
     *  @param argtypes  The types of the constructor invocation's value
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2270
     *                   arguments.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2271
     *  @param typeargtypes  The types of the constructor invocation's type
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2272
     *                   arguments.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2273
     */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2274
    Symbol resolveDiamond(DiagnosticPosition pos,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2275
                              Env<AttrContext> env,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2276
                              Type site,
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2277
                              List<Type> argtypes,
6344
f190fb7fdd2d 6975275: diamond implementation needs some cleanup
mcimadamore
parents: 6151
diff changeset
  2278
                              List<Type> typeargtypes) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2279
        return lookupMethod(env, pos, site.tsym, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2280
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2281
            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2282
                return findDiamond(env, site, argtypes, typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2283
                        phase.isBoxingRequired(),
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2284
                        phase.isVarargsRequired());
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2285
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2286
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2287
            Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2288
                if (sym.kind >= AMBIGUOUS) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2289
                    final JCDiagnostic details = sym.kind == WRONG_MTH ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2290
                                    ((InapplicableSymbolError)sym).errCandidate().details :
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2291
                                    null;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2292
                    sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2293
                        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2294
                        JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2295
                                Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2296
                            String key = details == null ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2297
                                "cant.apply.diamond" :
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2298
                                "cant.apply.diamond.1";
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2299
                            return diags.create(dkind, log.currentSource(), pos, key,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2300
                                    diags.fragment("diamond", site.tsym), details);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2301
                        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2302
                    };
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2303
                    sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2304
                    env.info.pendingResolutionPhase = currentResolutionContext.step;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2305
                }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2306
                return sym;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2307
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2308
        });
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2309
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 3372
diff changeset
  2310
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2311
    /** This method scans all the constructor symbol in a given class scope -
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2312
     *  assuming that the original scope contains a constructor of the kind:
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13438
diff changeset
  2313
     *  {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo,
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2314
     *  a method check is executed against the modified constructor type:
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13438
diff changeset
  2315
     *  {@code <X,Y>Foo<X,Y>(X x, Y y)}. This is crucial in order to enable diamond
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2316
     *  inference. The inferred return type of the synthetic constructor IS
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2317
     *  the inferred type for the diamond operator.
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2318
     */
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2319
    private Symbol findDiamond(Env<AttrContext> env,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2320
                              Type site,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2321
                              List<Type> argtypes,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2322
                              List<Type> typeargtypes,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2323
                              boolean allowBoxing,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2324
                              boolean useVarargs) {
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2325
        Symbol bestSoFar = methodNotFound;
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2326
        for (Scope.Entry e = site.tsym.members().lookup(names.init);
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2327
             e.scope != null;
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2328
             e = e.next()) {
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2329
            final Symbol sym = e.sym;
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2330
            //- System.out.println(" e " + e.sym);
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2331
            if (sym.kind == MTH &&
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2332
                (sym.flags_field & SYNTHETIC) == 0) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  2333
                    List<Type> oldParams = e.sym.type.hasTag(FORALL) ?
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2334
                            ((ForAll)sym.type).tvars :
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2335
                            List.<Type>nil();
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2336
                    Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams),
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2337
                            types.createMethodTypeWithReturn(sym.type.asMethodType(), site));
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2338
                    MethodSymbol newConstr = new MethodSymbol(sym.flags(), names.init, constrType, site.tsym) {
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2339
                        @Override
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2340
                        public Symbol baseSymbol() {
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2341
                            return sym;
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2342
                        }
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2343
                    };
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2344
                    bestSoFar = selectBest(env, site, argtypes, typeargtypes,
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14048
diff changeset
  2345
                            newConstr,
12078
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2346
                            bestSoFar,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2347
                            allowBoxing,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2348
                            useVarargs,
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2349
                            false);
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2350
            }
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2351
        }
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2352
        return bestSoFar;
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2353
    }
7470e05d486b 7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents: 12076
diff changeset
  2354
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2355
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2356
06bc494ca11e Initial load
duke
parents:
diff changeset
  2357
    /** Resolve operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2358
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2359
     *  @param optag     The tag of the operation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2360
     *  @param env       The environment current at the operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2361
     *  @param argtypes  The types of the operands.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2362
     */
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
  2363
    Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2364
                           Env<AttrContext> env, List<Type> argtypes) {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2365
        MethodResolutionContext prevResolutionContext = currentResolutionContext;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2366
        try {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2367
            currentResolutionContext = new MethodResolutionContext();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2368
            Name name = treeinfo.operatorName(optag);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2369
            Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2370
                                    null, false, false, true);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2371
            if (boxingEnabled && sym.kind >= WRONG_MTHS)
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2372
                sym = findMethod(env, syms.predefClass.type, name, argtypes,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2373
                                 null, true, false, true);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2374
            return accessMethod(sym, pos, env.enclClass.sym.type, name,
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2375
                          false, argtypes, null);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2376
        }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2377
        finally {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2378
            currentResolutionContext = prevResolutionContext;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  2379
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2381
06bc494ca11e Initial load
duke
parents:
diff changeset
  2382
    /** Resolve operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2383
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2384
     *  @param optag     The tag of the operation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2385
     *  @param env       The environment current at the operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2386
     *  @param arg       The type of the operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2387
     */
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
  2388
    Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2389
        return resolveOperator(pos, optag, env, List.of(arg));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2390
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2391
06bc494ca11e Initial load
duke
parents:
diff changeset
  2392
    /** Resolve binary operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2393
     *  @param pos       The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2394
     *  @param optag     The tag of the operation tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2395
     *  @param env       The environment current at the operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2396
     *  @param left      The types of the left operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2397
     *  @param right     The types of the right operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2398
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2399
    Symbol resolveBinaryOperator(DiagnosticPosition pos,
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
  2400
                                 JCTree.Tag optag,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2401
                                 Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2402
                                 Type left,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2403
                                 Type right) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2404
        return resolveOperator(pos, optag, env, List.of(left, right));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2405
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2406
06bc494ca11e Initial load
duke
parents:
diff changeset
  2407
    /**
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2408
     * Resolution of member references is typically done as a single
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2409
     * overload resolution step, where the argument types A are inferred from
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2410
     * the target functional descriptor.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2411
     *
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2412
     * If the member reference is a method reference with a type qualifier,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2413
     * a two-step lookup process is performed. The first step uses the
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2414
     * expected argument list A, while the second step discards the first
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2415
     * type from A (which is treated as a receiver type).
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2416
     *
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2417
     * There are two cases in which inference is performed: (i) if the member
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2418
     * reference is a constructor reference and the qualifier type is raw - in
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2419
     * which case diamond inference is used to infer a parameterization for the
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2420
     * type qualifier; (ii) if the member reference is an unbound reference
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2421
     * where the type qualifier is raw - in that case, during the unbound lookup
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2422
     * the receiver argument type is used to infer an instantiation for the raw
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2423
     * qualifier type.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2424
     *
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2425
     * When a multi-step resolution process is exploited, it is an error
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2426
     * if two candidates are found (ambiguity).
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2427
     *
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2428
     * This routine returns a pair (T,S), where S is the member reference symbol,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2429
     * and T is the type of the class in which S is defined. This is necessary as
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2430
     * the type T might be dynamically inferred (i.e. if constructor reference
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2431
     * has a raw qualifier).
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2432
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2433
    Pair<Symbol, ReferenceLookupHelper> resolveMemberReference(DiagnosticPosition pos,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2434
                                  Env<AttrContext> env,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2435
                                  JCMemberReference referenceTree,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2436
                                  Type site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2437
                                  Name name, List<Type> argtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2438
                                  List<Type> typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2439
                                  boolean boxingAllowed) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2440
        MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2441
        //step 1 - bound lookup
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2442
        ReferenceLookupHelper boundLookupHelper = name.equals(names.init) ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2443
                new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase) :
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2444
                new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2445
        Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup());
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2446
        Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, boundLookupHelper);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2447
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2448
        //step 2 - unbound lookup
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2449
        ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup();
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2450
        Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup());
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2451
        Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, unboundLookupHelper);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2452
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2453
        //merge results
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2454
        Pair<Symbol, ReferenceLookupHelper> res;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2455
        if (unboundSym.kind != MTH) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2456
            res = new Pair<Symbol, ReferenceLookupHelper>(boundSym, boundLookupHelper);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2457
            env.info.pendingResolutionPhase = boundEnv.info.pendingResolutionPhase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2458
        } else if (boundSym.kind == MTH) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2459
            res = new Pair<Symbol, ReferenceLookupHelper>(ambiguityError(boundSym, unboundSym), boundLookupHelper);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2460
            env.info.pendingResolutionPhase = boundEnv.info.pendingResolutionPhase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2461
        } else {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2462
            res = new Pair<Symbol, ReferenceLookupHelper>(unboundSym, unboundLookupHelper);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2463
            env.info.pendingResolutionPhase = unboundEnv.info.pendingResolutionPhase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2464
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2465
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2466
        return res;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2467
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2468
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2469
    /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2470
     * Helper for defining custom method-like lookup logic; a lookup helper
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2471
     * provides hooks for (i) the actual lookup logic and (ii) accessing the
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2472
     * lookup result (this step might result in compiler diagnostics to be generated)
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2473
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2474
    abstract class LookupHelper {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2475
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2476
        /** name of the symbol to lookup */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2477
        Name name;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2478
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2479
        /** location in which the lookup takes place */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2480
        Type site;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2481
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2482
        /** actual types used during the lookup */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2483
        List<Type> argtypes;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2484
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2485
        /** type arguments used during the lookup */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2486
        List<Type> typeargtypes;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2487
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2488
        /** Max overload resolution phase handled by this helper */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2489
        MethodResolutionPhase maxPhase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2490
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2491
        LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2492
            this.name = name;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2493
            this.site = site;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2494
            this.argtypes = argtypes;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2495
            this.typeargtypes = typeargtypes;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2496
            this.maxPhase = maxPhase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2497
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2498
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2499
        /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2500
         * Should lookup stop at given phase with given result
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2501
         */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2502
        protected boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2503
            return phase.ordinal() > maxPhase.ordinal() ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2504
                    sym.kind < ERRONEOUS || sym.kind == AMBIGUOUS;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2505
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2506
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2507
        /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2508
         * Search for a symbol under a given overload resolution phase - this method
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2509
         * is usually called several times, once per each overload resolution phase
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2510
         */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2511
        abstract Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2512
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2513
        /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2514
         * Validate the result of the lookup
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2515
         */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2516
        abstract Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2517
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2518
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2519
    abstract class BasicLookupHelper extends LookupHelper {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2520
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2521
        BasicLookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2522
            super(name, site, argtypes, typeargtypes, MethodResolutionPhase.VARARITY);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2523
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2524
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2525
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2526
        Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2527
            if (sym.kind >= AMBIGUOUS) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2528
                //if nothing is found return the 'first' error
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2529
                sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2530
            }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2531
            return sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2532
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2533
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2534
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2535
    /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2536
     * Helper class for member reference lookup. A reference lookup helper
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2537
     * defines the basic logic for member reference lookup; a method gives
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2538
     * access to an 'unbound' helper used to perform an unbound member
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2539
     * reference lookup.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2540
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2541
    abstract class ReferenceLookupHelper extends LookupHelper {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2542
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2543
        /** The member reference tree */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2544
        JCMemberReference referenceTree;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2545
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2546
        ReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2547
                List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2548
            super(name, site, argtypes, typeargtypes, maxPhase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2549
            this.referenceTree = referenceTree;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2550
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2551
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2552
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2553
        /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2554
         * Returns an unbound version of this lookup helper. By default, this
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2555
         * method returns an dummy lookup helper.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2556
         */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2557
        ReferenceLookupHelper unboundLookup() {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2558
            //dummy loopkup helper that always return 'methodNotFound'
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2559
            return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2560
                @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2561
                ReferenceLookupHelper unboundLookup() {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2562
                    return this;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2563
                }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2564
                @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2565
                Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2566
                    return methodNotFound;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2567
                }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2568
                @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2569
                ReferenceKind referenceKind(Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2570
                    Assert.error();
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2571
                    return null;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2572
                }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2573
            };
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2574
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2575
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2576
        /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2577
         * Get the kind of the member reference
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2578
         */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2579
        abstract JCMemberReference.ReferenceKind referenceKind(Symbol sym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2580
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2581
        Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2582
            //skip error reporting
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2583
            return sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2584
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2585
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2586
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2587
    /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2588
     * Helper class for method reference lookup. The lookup logic is based
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2589
     * upon Resolve.findMethod; in certain cases, this helper class has a
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2590
     * corresponding unbound helper class (see UnboundMethodReferenceLookupHelper).
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2591
     * In such cases, non-static lookup results are thrown away.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2592
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2593
    class MethodReferenceLookupHelper extends ReferenceLookupHelper {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2594
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2595
        MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2596
                List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2597
            super(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2598
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2599
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2600
        protected Symbol lookupReferenceInternal(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2601
            return findMethod(env, site, name, argtypes, typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2602
                    phase.isBoxingRequired(), phase.isVarargsRequired(), syms.operatorNames.contains(name));
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2603
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2604
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2605
        protected Symbol adjustLookupResult(Env<AttrContext> env, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2606
            return !TreeInfo.isStaticSelector(referenceTree.expr, names) ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2607
                        sym.kind != MTH ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2608
                        sym.isStatic() ? sym : new StaticError(sym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2609
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2610
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2611
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2612
        final Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2613
            return adjustLookupResult(env, lookupReferenceInternal(env, phase));
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2614
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2615
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2616
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2617
        ReferenceLookupHelper unboundLookup() {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2618
            if (TreeInfo.isStaticSelector(referenceTree.expr, names) &&
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2619
                    argtypes.nonEmpty() &&
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2620
                    types.isSubtypeUnchecked(argtypes.head, site)) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2621
                return new UnboundMethodReferenceLookupHelper(referenceTree, name,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2622
                        site, argtypes, typeargtypes, maxPhase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2623
            } else {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2624
                return super.unboundLookup();
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2625
            }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2626
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2627
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2628
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2629
        ReferenceKind referenceKind(Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2630
            if (sym.isStatic()) {
14724
b542db73539a 8004101: Add checks for method reference well-formedness
mcimadamore
parents: 14547
diff changeset
  2631
                return ReferenceKind.STATIC;
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2632
            } else {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2633
                Name selName = TreeInfo.name(referenceTree.getQualifierExpression());
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2634
                return selName != null && selName == names._super ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2635
                        ReferenceKind.SUPER :
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2636
                        ReferenceKind.BOUND;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2637
            }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2638
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2639
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2640
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2641
    /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2642
     * Helper class for unbound method reference lookup. Essentially the same
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2643
     * as the basic method reference lookup helper; main difference is that static
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2644
     * lookup results are thrown away. If qualifier type is raw, an attempt to
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2645
     * infer a parameterized type is made using the first actual argument (that
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2646
     * would otherwise be ignored during the lookup).
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2647
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2648
    class UnboundMethodReferenceLookupHelper extends MethodReferenceLookupHelper {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2649
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2650
        UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2651
                List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2652
            super(referenceTree, name,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2653
                    site.isRaw() ? types.asSuper(argtypes.head, site.tsym) : site,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2654
                    argtypes.tail, typeargtypes, maxPhase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2655
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2656
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2657
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2658
        protected Symbol adjustLookupResult(Env<AttrContext> env, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2659
            return sym.kind != MTH || !sym.isStatic() ? sym : new StaticError(sym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2660
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2661
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2662
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2663
        ReferenceLookupHelper unboundLookup() {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2664
            return this;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2665
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2666
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2667
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2668
        ReferenceKind referenceKind(Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2669
            return ReferenceKind.UNBOUND;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2670
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2671
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2672
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2673
    /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2674
     * Helper class for constructor reference lookup. The lookup logic is based
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2675
     * upon either Resolve.findMethod or Resolve.findDiamond - depending on
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2676
     * whether the constructor reference needs diamond inference (this is the case
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2677
     * if the qualifier type is raw). A special erroneous symbol is returned
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2678
     * if the lookup returns the constructor of an inner class and there's no
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2679
     * enclosing instance in scope.
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2680
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2681
    class ConstructorReferenceLookupHelper extends ReferenceLookupHelper {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2682
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2683
        boolean needsInference;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2684
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2685
        ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2686
                List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2687
            super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2688
            if (site.isRaw()) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2689
                this.site = new ClassType(site.getEnclosingType(), site.tsym.type.getTypeArguments(), site.tsym);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2690
                needsInference = true;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2691
            }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2692
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2693
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2694
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2695
        protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2696
            Symbol sym = needsInference ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2697
                findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) :
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2698
                findMethod(env, site, name, argtypes, typeargtypes,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2699
                        phase.isBoxingRequired(), phase.isVarargsRequired(), syms.operatorNames.contains(name));
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2700
            return sym.kind != MTH ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2701
                          site.getEnclosingType().hasTag(NONE) ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2702
                          hasEnclosingInstance(env, site) ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2703
                          sym : new InvalidSymbolError(Kinds.MISSING_ENCL, sym, null) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2704
                    @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2705
                    JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2706
                       return diags.create(dkind, log.currentSource(), pos,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2707
                            "cant.access.inner.cls.constr", site.tsym.name, argtypes, site.getEnclosingType());
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2708
                    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2709
                };
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2710
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2711
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2712
        @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2713
        ReferenceKind referenceKind(Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2714
            return site.getEnclosingType().hasTag(NONE) ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2715
                    ReferenceKind.TOPLEVEL : ReferenceKind.IMPLICIT_INNER;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2716
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2717
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2718
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2719
    /**
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2720
     * Main overload resolution routine. On each overload resolution step, a
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2721
     * lookup helper class is used to perform the method/constructor lookup;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2722
     * at the end of the lookup, the helper is used to validate the results
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2723
     * (this last step might trigger overload resolution diagnostics).
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2724
     */
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2725
    Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, LookupHelper lookupHelper) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2726
        return lookupMethod(env, pos, location, new MethodResolutionContext(), lookupHelper);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2727
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2728
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2729
    Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location,
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2730
            MethodResolutionContext resolveContext, LookupHelper lookupHelper) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2731
        MethodResolutionContext prevResolutionContext = currentResolutionContext;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2732
        try {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2733
            Symbol bestSoFar = methodNotFound;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2734
            currentResolutionContext = resolveContext;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2735
            for (MethodResolutionPhase phase : methodResolutionSteps) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2736
                if (!phase.isApplicable(boxingEnabled, varargsEnabled) ||
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2737
                        lookupHelper.shouldStop(bestSoFar, phase)) break;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2738
                MethodResolutionPhase prevPhase = currentResolutionContext.step;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2739
                Symbol prevBest = bestSoFar;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2740
                currentResolutionContext.step = phase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2741
                bestSoFar = phase.mergeResults(bestSoFar, lookupHelper.lookup(env, phase));
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2742
                env.info.pendingResolutionPhase = (prevBest == bestSoFar) ? prevPhase : phase;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2743
            }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2744
            return lookupHelper.access(env, pos, location, bestSoFar);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2745
        } finally {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2746
            currentResolutionContext = prevResolutionContext;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2747
        }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2748
    }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2749
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  2750
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2751
     * Resolve `c.name' where name == this or name == super.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2752
     * @param pos           The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2753
     * @param env           The environment current at the expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2754
     * @param c             The qualifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2755
     * @param name          The identifier's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2756
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2757
    Symbol resolveSelf(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2758
                       Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2759
                       TypeSymbol c,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2760
                       Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2761
        Env<AttrContext> env1 = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2762
        boolean staticOnly = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2763
        while (env1.outer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2764
            if (isStatic(env1)) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2765
            if (env1.enclClass.sym == c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2766
                Symbol sym = env1.info.scope.lookup(name).sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2767
                if (sym != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2768
                    if (staticOnly) sym = new StaticError(sym);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  2769
                    return accessBase(sym, pos, env.enclClass.sym.type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2770
                                  name, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2771
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2772
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2773
            if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2774
            env1 = env1.outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2775
        }
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2776
        if (allowDefaultMethods && c.isInterface() &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2777
                name == names._super && !isStatic(env) &&
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  2778
                types.isDirectSuperInterface(c, env.enclClass.sym)) {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2779
            //this might be a default super call if one of the superinterfaces is 'c'
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2780
            for (Type t : pruneInterfaces(env.enclClass.type)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2781
                if (t.tsym == c) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2782
                    env.info.defaultSuperCallSite = t;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2783
                    return new VarSymbol(0, names._super,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2784
                            types.asSuper(env.enclClass.type, c), env.enclClass.sym);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2785
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2786
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2787
            //find a direct superinterface that is a subtype of 'c'
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2788
            for (Type i : types.interfaces(env.enclClass.type)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2789
                if (i.tsym.isSubClass(c, types) && i.tsym != c) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2790
                    log.error(pos, "illegal.default.super.call", c,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2791
                            diags.fragment("redundant.supertype", c, i));
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2792
                    return syms.errSymbol;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2793
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2794
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2795
            Assert.error();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2796
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2797
        log.error(pos, "not.encl.class", c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2798
        return syms.errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2799
    }
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2800
    //where
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2801
    private List<Type> pruneInterfaces(Type t) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2802
        ListBuffer<Type> result = ListBuffer.lb();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2803
        for (Type t1 : types.interfaces(t)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2804
            boolean shouldAdd = true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2805
            for (Type t2 : types.interfaces(t)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2806
                if (t1 != t2 && types.isSubtypeNoCapture(t2, t1)) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2807
                    shouldAdd = false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2808
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2809
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2810
            if (shouldAdd) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2811
                result.append(t1);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2812
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2813
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2814
        return result.toList();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2815
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  2816
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2817
06bc494ca11e Initial load
duke
parents:
diff changeset
  2818
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  2819
     * Resolve `c.this' for an enclosing class c that contains the
06bc494ca11e Initial load
duke
parents:
diff changeset
  2820
     * named member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2821
     * @param pos           The position to use for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2822
     * @param env           The environment current at the expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2823
     * @param member        The member that must be contained in the result.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2824
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2825
    Symbol resolveSelfContaining(DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2826
                                 Env<AttrContext> env,
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2827
                                 Symbol member,
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2828
                                 boolean isSuperCall) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2829
        Symbol sym = resolveSelfContainingInternal(env, member, isSuperCall);
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2830
        if (sym == null) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2831
            log.error(pos, "encl.class.required", member);
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2832
            return syms.errSymbol;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2833
        } else {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2834
            return accessBase(sym, pos, env.enclClass.sym.type, sym.name, true);
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2835
        }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2836
    }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2837
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2838
    boolean hasEnclosingInstance(Env<AttrContext> env, Type type) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2839
        Symbol encl = resolveSelfContainingInternal(env, type.tsym, false);
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2840
        return encl != null && encl.kind < ERRONEOUS;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2841
    }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2842
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2843
    private Symbol resolveSelfContainingInternal(Env<AttrContext> env,
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2844
                                 Symbol member,
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2845
                                 boolean isSuperCall) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2846
        Name name = names._this;
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2847
        Env<AttrContext> env1 = isSuperCall ? env.outer : env;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2848
        boolean staticOnly = false;
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2849
        if (env1 != null) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2850
            while (env1 != null && env1.outer != null) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2851
                if (isStatic(env1)) staticOnly = true;
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2852
                if (env1.enclClass.sym.isSubClass(member.owner, types)) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2853
                    Symbol sym = env1.info.scope.lookup(name).sym;
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2854
                    if (sym != null) {
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2855
                        if (staticOnly) sym = new StaticError(sym);
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2856
                        return sym;
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2857
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2858
                }
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2859
                if ((env1.enclClass.sym.flags() & STATIC) != 0)
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2860
                    staticOnly = true;
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2861
                env1 = env1.outer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2862
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2863
        }
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2864
        return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2865
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2866
06bc494ca11e Initial load
duke
parents:
diff changeset
  2867
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  2868
     * Resolve an appropriate implicit this instance for t's container.
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 9302
diff changeset
  2869
     * JLS 8.8.5.1 and 15.9.2
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2870
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2871
    Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) {
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2872
        return resolveImplicitThis(pos, env, t, false);
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2873
    }
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2874
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2875
    Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t, boolean isSuperCall) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2876
        Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2877
                         ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this)
8622
4f032629a0fd 6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents: 8430
diff changeset
  2878
                         : resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2879
        if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2880
            log.error(pos, "cant.ref.before.ctor.called", "this");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2881
        return thisType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2882
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2883
06bc494ca11e Initial load
duke
parents:
diff changeset
  2884
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  2885
 *  ResolveError classes, indicating error situations when accessing symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  2886
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  2887
12082
32bdf6ef6388 7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents: 12078
diff changeset
  2888
    //used by TransTypes when checking target type of synthetic cast
32bdf6ef6388 7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents: 12078
diff changeset
  2889
    public void logAccessErrorInternal(Env<AttrContext> env, JCTree tree, Type type) {
32bdf6ef6388 7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents: 12078
diff changeset
  2890
        AccessError error = new AccessError(env, env.enclClass.type, type.tsym);
32bdf6ef6388 7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents: 12078
diff changeset
  2891
        logResolveError(error, tree.pos(), env.enclClass.sym, env.enclClass.type, null, null, null);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2892
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2893
    //where
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2894
    private void logResolveError(ResolveError error,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2895
            DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2896
            Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2897
            Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2898
            Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2899
            List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2900
            List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2901
        JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2902
                pos, location, site, name, argtypes, typeargtypes);
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
  2903
        if (d != null) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
  2904
            d.setFlag(DiagnosticFlag.RESOLVE_ERROR);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2905
            log.report(d);
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6344
diff changeset
  2906
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2907
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2908
1534
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  2909
    private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args");
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  2910
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  2911
    public Object methodArguments(List<Type> argtypes) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2912
        if (argtypes == null || argtypes.isEmpty()) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2913
            return noArgs;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2914
        } else {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2915
            ListBuffer<Object> diagArgs = ListBuffer.lb();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2916
            for (Type t : argtypes) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  2917
                if (t.hasTag(DEFERRED)) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2918
                    diagArgs.append(((DeferredAttr.DeferredType)t).tree);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2919
                } else {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2920
                    diagArgs.append(t);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2921
                }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2922
            }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2923
            return diagArgs;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  2924
        }
1534
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  2925
    }
e923a41e84cc 6758789: Some method resolution diagnostic should be improved
mcimadamore
parents: 1533
diff changeset
  2926
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2927
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2928
     * Root class for resolution errors. Subclass of ResolveError
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2929
     * represent a different kinds of resolution error - as such they must
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2930
     * specify how they map into concrete compiler diagnostics.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2931
     */
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  2932
    abstract class ResolveError extends Symbol {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2933
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2934
        /** The name of the kind of error, for debugging only. */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2935
        final String debugName;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2936
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2937
        ResolveError(int kind, String debugName) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2938
            super(kind, 0, null, null, null);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2939
            this.debugName = debugName;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2940
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2941
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2942
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2943
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2944
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2945
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2946
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2947
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2948
        public String toString() {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2949
            return debugName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2950
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2951
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2952
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2953
        public boolean exists() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2954
            return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2955
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2956
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2957
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2958
         * Create an external representation for this erroneous symbol to be
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2959
         * used during attribution - by default this returns the symbol of a
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2960
         * brand new error type which stores the original type found
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2961
         * during resolution.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2962
         *
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2963
         * @param name     the name used during resolution
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2964
         * @param location the location from which the symbol is accessed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2965
         */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2966
        protected Symbol access(Name name, TypeSymbol location) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2967
            return types.createErrorType(name, location, syms.errSymbol.type).tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2968
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2969
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2970
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2971
         * Create a diagnostic representing this resolution error.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2972
         *
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2973
         * @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
  2974
         * @param pos       The position to be used for error reporting.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2975
         * @param site      The original type from where the selection took place.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2976
         * @param name      The name of the symbol to be resolved.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2977
         * @param argtypes  The invocation's value arguments,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2978
         *                  if we looked for a method.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2979
         * @param typeargtypes  The invocation's type arguments,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2980
         *                      if we looked for a method.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2981
         */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2982
        abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2983
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  2984
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2985
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2986
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2987
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2988
                List<Type> typeargtypes);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2989
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2990
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2991
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2992
     * 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
  2993
     * an invalid symbol being found during resolution.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2994
     */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2995
    abstract class InvalidSymbolError extends ResolveError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2996
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2997
        /** The invalid symbol found during resolution */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2998
        Symbol sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  2999
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3000
        InvalidSymbolError(int kind, Symbol sym, String debugName) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3001
            super(kind, debugName);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3002
            this.sym = sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3003
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3004
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3005
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3006
        public boolean exists() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3007
            return true;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3008
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3009
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3010
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3011
        public String toString() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3012
             return super.toString() + " wrongSym=" + sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3013
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3014
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3015
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3016
        public Symbol access(Name name, TypeSymbol location) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3017
            if (sym.kind >= AMBIGUOUS)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3018
                return ((ResolveError)sym).access(name, location);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3019
            else if ((sym.kind & ERRONEOUS) == 0 && (sym.kind & TYP) != 0)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3020
                return types.createErrorType(name, location, sym.type).tsym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3021
            else
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3022
                return sym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3023
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3024
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3025
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3026
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3027
     * InvalidSymbolError error class indicating that a symbol matching a
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3028
     * given name does not exists in a given site.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3029
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3030
    class SymbolNotFoundError extends ResolveError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3031
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3032
        SymbolNotFoundError(int kind) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3033
            super(kind, "symbol not found error");
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3034
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3035
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3036
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3037
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3038
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3039
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3040
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3041
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3042
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3043
                List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3044
            argtypes = argtypes == null ? List.<Type>nil() : argtypes;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3045
            typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3046
            if (name == names.error)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3047
                return null;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3048
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3049
            if (syms.operatorNames.contains(name)) {
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3050
                boolean isUnaryOp = argtypes.size() == 1;
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3051
                String key = argtypes.size() == 1 ?
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3052
                    "operator.cant.be.applied" :
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3053
                    "operator.cant.be.applied.1";
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3054
                Type first = argtypes.head;
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3055
                Type second = !isUnaryOp ? argtypes.tail.head : null;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3056
                return diags.create(dkind, log.currentSource(), pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3057
                        key, name, first, second);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3058
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3059
            boolean hasLocation = false;
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3060
            if (location == null) {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3061
                location = site.tsym;
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3062
            }
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3063
            if (!location.name.isEmpty()) {
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3064
                if (location.kind == PCK && !site.tsym.exists()) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3065
                    return diags.create(dkind, log.currentSource(), pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3066
                        "doesnt.exist", location);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3067
                }
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3068
                hasLocation = !location.name.equals(names._this) &&
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3069
                        !location.name.equals(names._super);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3070
            }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3071
            boolean isConstructor = kind == ABSENT_MTH && name == names.init;
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3072
            KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3073
            Name idname = isConstructor ? site.tsym.name : name;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3074
            String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3075
            if (hasLocation) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3076
                return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3077
                        errKey, kindname, idname, //symbol kindname, name
14953
89a34297b198 8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents: 14801
diff changeset
  3078
                        typeargtypes, args(argtypes), //type parameters and arguments (if any)
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3079
                        getLocationDiag(location, site)); //location kindname, type
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3080
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3081
            else {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3082
                return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3083
                        errKey, kindname, idname, //symbol kindname, name
14953
89a34297b198 8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents: 14801
diff changeset
  3084
                        typeargtypes, args(argtypes)); //type parameters and arguments (if any)
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3085
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3086
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3087
        //where
14953
89a34297b198 8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents: 14801
diff changeset
  3088
        private Object args(List<Type> args) {
89a34297b198 8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents: 14801
diff changeset
  3089
            return args.isEmpty() ? args : methodArguments(args);
89a34297b198 8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents: 14801
diff changeset
  3090
        }
89a34297b198 8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents: 14801
diff changeset
  3091
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3092
        private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3093
            String key = "cant.resolve";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3094
            String suffix = hasLocation ? ".location" : "";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3095
            switch (kindname) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3096
                case METHOD:
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3097
                case CONSTRUCTOR: {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3098
                    suffix += ".args";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3099
                    suffix += hasTypeArgs ? ".params" : "";
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3100
                }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3101
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3102
            return key + suffix;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3103
        }
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3104
        private JCDiagnostic getLocationDiag(Symbol location, Type site) {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3105
            if (location.kind == VAR) {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3106
                return diags.fragment("location.1",
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3107
                    kindName(location),
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3108
                    location,
8239
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3109
                    location.type);
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3110
            } else {
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3111
                return diags.fragment("location",
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3112
                    typeKindName(site),
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3113
                    site,
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3114
                    null);
d2c934e951e2 7014715: javac returns different error code for certain failure(s)
mcimadamore
parents: 8237
diff changeset
  3115
            }
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3116
        }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3117
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3118
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3119
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3120
     * InvalidSymbolError error class indicating that a given symbol
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3121
     * (either a method, a constructor or an operand) is not applicable
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3122
     * given an actual arguments/type argument list.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3123
     */
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3124
    class InapplicableSymbolError extends ResolveError {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3125
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3126
        protected MethodResolutionContext resolveContext;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3127
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3128
        InapplicableSymbolError(MethodResolutionContext context) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3129
            this(WRONG_MTH, "inapplicable symbol error", context);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3130
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3131
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3132
        protected InapplicableSymbolError(int kind, String debugName, MethodResolutionContext context) {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3133
            super(kind, debugName);
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3134
            this.resolveContext = context;
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3135
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3136
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3137
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3138
        public String toString() {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3139
            return super.toString();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3140
        }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3141
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3142
        @Override
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3143
        public boolean exists() {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3144
            return true;
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3145
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3146
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3147
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3148
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3149
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3150
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3151
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3152
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3153
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3154
                List<Type> typeargtypes) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3155
            if (name == names.error)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3156
                return null;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3157
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3158
            if (syms.operatorNames.contains(name)) {
8237
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3159
                boolean isUnaryOp = argtypes.size() == 1;
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3160
                String key = argtypes.size() == 1 ?
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3161
                    "operator.cant.be.applied" :
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3162
                    "operator.cant.be.applied.1";
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3163
                Type first = argtypes.head;
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3164
                Type second = !isUnaryOp ? argtypes.tail.head : null;
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3165
                return diags.create(dkind, log.currentSource(), pos,
d5ef8db7ad09 5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents: 8236
diff changeset
  3166
                        key, name, first, second);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3167
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3168
            else {
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3169
                Candidate c = errCandidate();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3170
                Symbol ws = c.sym.asMemberOf(site, types);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3171
                return diags.create(dkind, log.currentSource(), pos,
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3172
                          "cant.apply.symbol",
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3173
                          kindName(ws),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3174
                          ws.name == names.init ? ws.owner.name : ws.name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3175
                          methodArguments(ws.type.getParameterTypes()),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3176
                          methodArguments(argtypes),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3177
                          kindName(ws.owner),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3178
                          ws.owner.type,
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3179
                          c.details);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3180
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3181
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3182
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3183
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3184
        public Symbol access(Name name, TypeSymbol location) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3185
            return types.createErrorType(name, location, syms.errSymbol.type).tsym;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3186
        }
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3187
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3188
        private Candidate errCandidate() {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3189
            Candidate bestSoFar = null;
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3190
            for (Candidate c : resolveContext.candidates) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3191
                if (c.isApplicable()) continue;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3192
                bestSoFar = c;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3193
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3194
            Assert.checkNonNull(bestSoFar);
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3195
            return bestSoFar;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3196
        }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3197
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3198
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3199
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3200
     * ResolveError error class indicating that a set of symbols
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3201
     * (either methods, constructors or operands) is not applicable
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3202
     * given an actual arguments/type argument list.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3203
     */
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3204
    class InapplicableSymbolsError extends InapplicableSymbolError {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3205
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3206
        InapplicableSymbolsError(MethodResolutionContext context) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3207
            super(WRONG_MTHS, "inapplicable symbols", context);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3208
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3209
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3210
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3211
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3212
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3213
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3214
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3215
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3216
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3217
                List<Type> typeargtypes) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3218
            if (!resolveContext.candidates.isEmpty()) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3219
                JCDiagnostic err = diags.create(dkind,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3220
                        log.currentSource(),
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3221
                        pos,
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3222
                        "cant.apply.symbols",
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3223
                        name == names.init ? KindName.CONSTRUCTOR : absentKind(kind),
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3224
                        name == names.init ? site.tsym.name : name,
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
  3225
                        methodArguments(argtypes));
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3226
                return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3227
            } else {
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3228
                return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3229
                    location, site, name, argtypes, typeargtypes);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3230
            }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3231
        }
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3232
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3233
        //where
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3234
        List<JCDiagnostic> candidateDetails(Type site) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3235
            Map<Symbol, JCDiagnostic> details = new LinkedHashMap<Symbol, JCDiagnostic>();
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3236
            for (Candidate c : resolveContext.candidates) {
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3237
                if (c.isApplicable()) continue;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3238
                JCDiagnostic detailDiag = diags.fragment("inapplicable.method",
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3239
                        Kinds.kindName(c.sym),
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3240
                        c.sym.location(site, types),
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3241
                        c.sym.asMemberOf(site, types),
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3242
                        c.details);
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3243
                details.put(c.sym, detailDiag);
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3244
            }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3245
            return List.from(details.values());
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3246
        }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3247
    }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3248
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3249
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3250
     * An InvalidSymbolError error class indicating that a symbol is not
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3251
     * accessible from a given site
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3252
     */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3253
    class AccessError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3254
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3255
        private Env<AttrContext> env;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3256
        private Type site;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3257
06bc494ca11e Initial load
duke
parents:
diff changeset
  3258
        AccessError(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3259
            this(null, null, sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  3260
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3261
06bc494ca11e Initial load
duke
parents:
diff changeset
  3262
        AccessError(Env<AttrContext> env, Type site, Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3263
            super(HIDDEN, sym, "access error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  3264
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3265
            this.site = site;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3266
            if (debugResolve)
06bc494ca11e Initial load
duke
parents:
diff changeset
  3267
                log.error("proc.messager", sym + " @ " + site + " is inaccessible.");
06bc494ca11e Initial load
duke
parents:
diff changeset
  3268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3269
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3270
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3271
        public boolean exists() {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3272
            return false;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3273
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3274
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3275
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3276
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3277
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3278
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3279
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3280
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3281
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3282
                List<Type> typeargtypes) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  3283
            if (sym.owner.type.hasTag(ERROR))
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3284
                return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3285
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3286
            if (sym.name == names.init && sym.owner != site.tsym) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3287
                return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3288
                        pos, location, site, name, argtypes, typeargtypes);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3289
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3290
            else if ((sym.flags() & PUBLIC) != 0
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3291
                || (env != null && this.site != null
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3292
                    && !isAccessible(env, this.site))) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3293
                return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3294
                        pos, "not.def.access.class.intf.cant.access",
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3295
                    sym, sym.location());
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3296
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3297
            else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3298
                return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3299
                        pos, "report.access", sym,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3300
                        asFlagSet(sym.flags() & (PRIVATE | PROTECTED)),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3301
                        sym.location());
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3302
            }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3303
            else {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3304
                return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3305
                        pos, "not.def.public.cant.access", sym, sym.location());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3306
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3307
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3308
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3309
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3310
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3311
     * InvalidSymbolError error class indicating that an instance member
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3312
     * has erroneously been accessed from a static context.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3313
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3314
    class StaticError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3315
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3316
        StaticError(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3317
            super(STATICERR, sym, "static error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  3318
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3319
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3320
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3321
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3322
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3323
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3324
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3325
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3326
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3327
                List<Type> typeargtypes) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14062
diff changeset
  3328
            Symbol errSym = ((sym.kind == TYP && sym.type.hasTag(CLASS))
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  3329
                ? types.erasure(sym.type).tsym
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  3330
                : sym);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5857
diff changeset
  3331
            return diags.create(dkind, log.currentSource(), pos,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3332
                    "non-static.cant.be.ref", kindName(sym), errSym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3333
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3335
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3336
    /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3337
     * InvalidSymbolError error class indicating that a pair of symbols
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3338
     * (either methods, constructors or operands) are ambiguous
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3339
     * given an actual arguments/type argument list.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3340
     */
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3341
    class AmbiguityError extends InvalidSymbolError {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3342
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3343
        /** The other maximally specific symbol */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3344
        Symbol sym2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3345
06bc494ca11e Initial load
duke
parents:
diff changeset
  3346
        AmbiguityError(Symbol sym1, Symbol sym2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3347
            super(AMBIGUOUS, sym1, "ambiguity error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  3348
            this.sym2 = sym2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3349
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3350
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3351
        @Override
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3352
        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3353
                DiagnosticPosition pos,
8045
df2ca0edfbaa 6968793: issues with diagnostics
mcimadamore
parents: 8036
diff changeset
  3354
                Symbol location,
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3355
                Type site,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3356
                Name name,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3357
                List<Type> argtypes,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3358
                List<Type> typeargtypes) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3359
            AmbiguityError pair = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3360
            while (true) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3361
                if (pair.sym.kind == AMBIGUOUS)
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3362
                    pair = (AmbiguityError)pair.sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3363
                else if (pair.sym2.kind == AMBIGUOUS)
06bc494ca11e Initial load
duke
parents:
diff changeset
  3364
                    pair = (AmbiguityError)pair.sym2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3365
                else break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3366
            }
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3367
            Name sname = pair.sym.name;
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3368
            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
  3369
            return diags.create(dkind, log.currentSource(),
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3370
                      pos, "ref.ambiguous", sname,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3371
                      kindName(pair.sym),
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3372
                      pair.sym,
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 3140
diff changeset
  3373
                      pair.sym.location(site, types),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3374
                      kindName(pair.sym2),
06bc494ca11e Initial load
duke
parents:
diff changeset
  3375
                      pair.sym2,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3376
                      pair.sym2.location(site, types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  3377
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3378
    }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3379
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3380
    enum MethodResolutionPhase {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3381
        BASIC(false, false),
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3382
        BOX(true, false),
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3383
        VARARITY(true, true) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3384
            @Override
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3385
            public Symbol mergeResults(Symbol bestSoFar, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3386
                switch (sym.kind) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3387
                    case WRONG_MTH:
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3388
                        return (bestSoFar.kind == WRONG_MTH || bestSoFar.kind == WRONG_MTHS) ?
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3389
                            bestSoFar :
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3390
                            sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3391
                    case ABSENT_MTH:
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3392
                        return bestSoFar;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3393
                    default:
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3394
                        return sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3395
                }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3396
            }
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3397
        };
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3398
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14724
diff changeset
  3399
        final boolean isBoxingRequired;
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14724
diff changeset
  3400
        final boolean isVarargsRequired;
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3401
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3402
        MethodResolutionPhase(boolean isBoxingRequired, boolean isVarargsRequired) {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3403
           this.isBoxingRequired = isBoxingRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3404
           this.isVarargsRequired = isVarargsRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3405
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3406
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3407
        public boolean isBoxingRequired() {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3408
            return isBoxingRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3409
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3410
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3411
        public boolean isVarargsRequired() {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3412
            return isVarargsRequired;
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3413
        }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3414
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3415
        public boolean isApplicable(boolean boxingEnabled, boolean varargsEnabled) {
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3416
            return (varargsEnabled || !isVarargsRequired) &&
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3417
                   (boxingEnabled || !isBoxingRequired);
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3418
        }
14444
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3419
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3420
        public Symbol mergeResults(Symbol prev, Symbol sym) {
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3421
            return sym;
2069262b27c5 8000931: Cleanup Resolve.java
mcimadamore
parents: 14443
diff changeset
  3422
        }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3423
    }
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3424
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3425
    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
  3426
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3427
    /**
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3428
     * A resolution context is used to keep track of intermediate results of
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3429
     * overload resolution, such as list of method that are not applicable
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3430
     * (used to generate more precise diagnostics) and so on. Resolution contexts
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3431
     * can be nested - this means that when each overload resolution routine should
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3432
     * work within the resolution context it created.
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3433
     */
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3434
    class MethodResolutionContext {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3435
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3436
        private List<Candidate> candidates = List.nil();
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3437
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3438
        MethodResolutionPhase step = null;
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3439
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3440
        private boolean internalResolution = false;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3441
        private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
  3442
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3443
        void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3444
            Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3445
            candidates = candidates.append(c);
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3446
        }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3447
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3448
        void addApplicableCandidate(Symbol sym, Type mtype) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3449
            Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3450
            candidates = candidates.append(c);
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3451
        }
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10812
diff changeset
  3452
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3453
        /**
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3454
         * This class represents an overload resolution candidate. There are two
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3455
         * kinds of candidates: applicable methods and inapplicable methods;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3456
         * applicable methods have a pointer to the instantiated method type,
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3457
         * while inapplicable candidates contain further details about the
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3458
         * reason why the method has been considered inapplicable.
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3459
         */
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3460
        class Candidate {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3461
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3462
            final MethodResolutionPhase step;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3463
            final Symbol sym;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3464
            final JCDiagnostic details;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3465
            final Type mtype;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3466
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3467
            private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details, Type mtype) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3468
                this.step = step;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3469
                this.sym = sym;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3470
                this.details = details;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3471
                this.mtype = mtype;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3472
            }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3473
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3474
            @Override
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3475
            public boolean equals(Object o) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3476
                if (o instanceof Candidate) {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3477
                    Symbol s1 = this.sym;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3478
                    Symbol s2 = ((Candidate)o).sym;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3479
                    if  ((s1 != s2 &&
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3480
                            (s1.overrides(s2, s1.owner.type.tsym, types, false) ||
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3481
                            (s2.overrides(s1, s2.owner.type.tsym, types, false)))) ||
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  3482
                            ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner))
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3483
                        return true;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3484
                }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3485
                return false;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3486
            }
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3487
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3488
            boolean isApplicable() {
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3489
                return mtype != null;
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3490
            }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3491
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3492
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3493
        DeferredAttr.AttrMode attrMode() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3494
            return attrMode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3495
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3496
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3497
        boolean internal() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3498
            return internalResolution;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14056
diff changeset
  3499
        }
1533
6a9a2f681d24 6746184: javac fails to compile call to public varargs method
mcimadamore
parents: 1529
diff changeset
  3500
    }
12076
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3501
1b7560bd1760 7132880: Resolve should support nested resolution contexts
mcimadamore
parents: 11707
diff changeset
  3502
    MethodResolutionContext currentResolutionContext = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3503
}