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