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