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