author | sadayapalam |
Tue, 21 Nov 2017 13:27:12 +0530 | |
changeset 47870 | 924591048898 |
parent 47248 | 22d665f53a4a |
child 48054 | 702043a4cdeb |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45413
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, 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 |
||
28 |
import java.util.*; |
|
29 |
||
30 |
import com.sun.tools.javac.code.*; |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
31 |
import com.sun.tools.javac.code.Attribute.TypeCompound; |
10 | 32 |
import com.sun.tools.javac.code.Symbol.*; |
45413
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
33 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
10 | 34 |
import com.sun.tools.javac.tree.*; |
35 |
import com.sun.tools.javac.tree.JCTree.*; |
|
33711
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
36 |
import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; |
10 | 37 |
import com.sun.tools.javac.util.*; |
38 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
39 |
import com.sun.tools.javac.util.List; |
|
40 |
||
41 |
import static com.sun.tools.javac.code.Flags.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27124
diff
changeset
|
42 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
43 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
44 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
45 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
46 |
import static com.sun.tools.javac.code.TypeTag.VOID; |
16968 | 47 |
import static com.sun.tools.javac.comp.CompileStates.CompileState; |
10 | 48 |
|
49 |
/** This pass translates Generic Java to conventional Java. |
|
50 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
51 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
52 |
* If you write code that depends on this, you do so at your own risk. |
10 | 53 |
* This code and its internal interfaces are subject to change or |
54 |
* deletion without notice.</b> |
|
55 |
*/ |
|
56 |
public class TransTypes extends TreeTranslator { |
|
57 |
/** The context key for the TransTypes phase. */ |
|
22163 | 58 |
protected static final Context.Key<TransTypes> transTypesKey = new Context.Key<>(); |
10 | 59 |
|
60 |
/** Get the instance for this context. */ |
|
61 |
public static TransTypes instance(Context context) { |
|
62 |
TransTypes instance = context.get(transTypesKey); |
|
63 |
if (instance == null) |
|
64 |
instance = new TransTypes(context); |
|
65 |
return instance; |
|
66 |
} |
|
67 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
735
diff
changeset
|
68 |
private Names names; |
10 | 69 |
private Log log; |
70 |
private Symtab syms; |
|
71 |
private TreeMaker make; |
|
72 |
private Enter enter; |
|
73 |
private Types types; |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
74 |
private Annotate annotate; |
47248 | 75 |
private Attr attr; |
10 | 76 |
private final Resolve resolve; |
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
77 |
private final CompileStates compileStates; |
10 | 78 |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
79 |
/** Switch: is complex graph inference supported? */ |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
80 |
private final boolean allowGraphInference; |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
81 |
|
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
82 |
/** Switch: are default methods supported? */ |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
83 |
private final boolean allowInterfaceBridges; |
16968 | 84 |
|
10 | 85 |
protected TransTypes(Context context) { |
86 |
context.put(transTypesKey, this); |
|
16968 | 87 |
compileStates = CompileStates.instance(context); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
735
diff
changeset
|
88 |
names = Names.instance(context); |
10 | 89 |
log = Log.instance(context); |
90 |
syms = Symtab.instance(context); |
|
91 |
enter = Enter.instance(context); |
|
33367 | 92 |
bridgeSpans = new HashMap<>(); |
10 | 93 |
types = Types.instance(context); |
94 |
make = TreeMaker.instance(context); |
|
95 |
resolve = Resolve.instance(context); |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
96 |
Source source = Source.instance(context); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
97 |
allowInterfaceBridges = source.allowDefaultMethods(); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
98 |
allowGraphInference = source.allowGraphInference(); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
99 |
annotate = Annotate.instance(context); |
47248 | 100 |
attr = Attr.instance(context); |
10 | 101 |
} |
102 |
||
33367 | 103 |
/** A hashtable mapping bridge methods to the pair of methods they bridge. |
104 |
* The bridge overrides the first of the pair after type erasure and deflects |
|
105 |
* to the second of the pair (which differs in type erasure from the one |
|
106 |
* it overrides thereby necessitating the bridge) |
|
10 | 107 |
*/ |
33367 | 108 |
Map<MethodSymbol, Pair<MethodSymbol, MethodSymbol>> bridgeSpans; |
10 | 109 |
|
110 |
/** Construct an attributed tree for a cast of expression to target type, |
|
111 |
* unless it already has precisely that type. |
|
112 |
* @param tree The expression tree. |
|
113 |
* @param target The target type. |
|
114 |
*/ |
|
115 |
JCExpression cast(JCExpression tree, Type target) { |
|
116 |
int oldpos = make.pos; |
|
117 |
make.at(tree.pos); |
|
118 |
if (!types.isSameType(tree.type, target)) { |
|
119 |
if (!resolve.isAccessible(env, target.tsym)) |
|
12082
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
8032
diff
changeset
|
120 |
resolve.logAccessErrorInternal(env, tree, target); |
10 | 121 |
tree = make.TypeCast(make.Type(target), tree).setType(target); |
122 |
} |
|
123 |
make.pos = oldpos; |
|
124 |
return tree; |
|
125 |
} |
|
126 |
||
127 |
/** Construct an attributed tree to coerce an expression to some erased |
|
128 |
* target type, unless the expression is already assignable to that type. |
|
129 |
* If target type is a constant type, use its base type instead. |
|
130 |
* @param tree The expression tree. |
|
131 |
* @param target The target type. |
|
132 |
*/ |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
133 |
public JCExpression coerce(Env<AttrContext> env, JCExpression tree, Type target) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
134 |
Env<AttrContext> prevEnv = this.env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
135 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
136 |
this.env = env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
137 |
return coerce(tree, target); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
138 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
139 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
140 |
this.env = prevEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
141 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
142 |
} |
10 | 143 |
JCExpression coerce(JCExpression tree, Type target) { |
144 |
Type btarget = target.baseType(); |
|
145 |
if (tree.type.isPrimitive() == target.isPrimitive()) { |
|
14547 | 146 |
return types.isAssignable(tree.type, btarget, types.noWarnings) |
10 | 147 |
? tree |
148 |
: cast(tree, btarget); |
|
149 |
} |
|
150 |
return tree; |
|
151 |
} |
|
152 |
||
153 |
/** Given an erased reference type, assume this type as the tree's type. |
|
154 |
* Then, coerce to some given target type unless target type is null. |
|
155 |
* This operation is used in situations like the following: |
|
156 |
* |
|
14259 | 157 |
* <pre>{@code |
10 | 158 |
* class Cell<A> { A value; } |
159 |
* ... |
|
160 |
* Cell<Integer> cell; |
|
161 |
* Integer x = cell.value; |
|
14259 | 162 |
* }</pre> |
10 | 163 |
* |
164 |
* Since the erasure of Cell.value is Object, but the type |
|
165 |
* of cell.value in the assignment is Integer, we need to |
|
166 |
* adjust the original type of cell.value to Object, and insert |
|
167 |
* a cast to Integer. That is, the last assignment becomes: |
|
168 |
* |
|
14259 | 169 |
* <pre>{@code |
10 | 170 |
* Integer x = (Integer)cell.value; |
14259 | 171 |
* }</pre> |
10 | 172 |
* |
173 |
* @param tree The expression tree whose type might need adjustment. |
|
174 |
* @param erasedType The expression's type after erasure. |
|
175 |
* @param target The target type, which is usually the erasure of the |
|
176 |
* expression's original type. |
|
177 |
*/ |
|
178 |
JCExpression retype(JCExpression tree, Type erasedType, Type target) { |
|
179 |
// System.err.println("retype " + tree + " to " + erasedType);//DEBUG |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
180 |
if (!erasedType.isPrimitive()) { |
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
181 |
if (target != null && target.isPrimitive()) { |
10 | 182 |
target = erasure(tree.type); |
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
183 |
} |
10 | 184 |
tree.type = erasedType; |
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
185 |
if (target != null) { |
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
186 |
return coerce(tree, target); |
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
187 |
} |
10 | 188 |
} |
189 |
return tree; |
|
190 |
} |
|
191 |
||
192 |
/** Translate method argument list, casting each argument |
|
193 |
* to its corresponding type in a list of target types. |
|
194 |
* @param _args The method argument list. |
|
195 |
* @param parameters The list of target types. |
|
196 |
* @param varargsElement The erasure of the varargs element type, |
|
197 |
* or null if translating a non-varargs invocation |
|
198 |
*/ |
|
199 |
<T extends JCTree> List<T> translateArgs(List<T> _args, |
|
200 |
List<Type> parameters, |
|
201 |
Type varargsElement) { |
|
202 |
if (parameters.isEmpty()) return _args; |
|
203 |
List<T> args = _args; |
|
204 |
while (parameters.tail.nonEmpty()) { |
|
205 |
args.head = translate(args.head, parameters.head); |
|
206 |
args = args.tail; |
|
207 |
parameters = parameters.tail; |
|
208 |
} |
|
209 |
Type parameter = parameters.head; |
|
8032 | 210 |
Assert.check(varargsElement != null || args.length() == 1); |
10 | 211 |
if (varargsElement != null) { |
212 |
while (args.nonEmpty()) { |
|
213 |
args.head = translate(args.head, varargsElement); |
|
214 |
args = args.tail; |
|
215 |
} |
|
216 |
} else { |
|
217 |
args.head = translate(args.head, parameter); |
|
218 |
} |
|
219 |
return _args; |
|
220 |
} |
|
221 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
222 |
public <T extends JCTree> List<T> translateArgs(List<T> _args, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
223 |
List<Type> parameters, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
224 |
Type varargsElement, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
225 |
Env<AttrContext> localEnv) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
226 |
Env<AttrContext> prevEnv = env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
227 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
228 |
env = localEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
229 |
return translateArgs(_args, parameters, varargsElement); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
230 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
231 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
232 |
env = prevEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
233 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
234 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
235 |
|
10 | 236 |
/** Add a bridge definition and enter corresponding method symbol in |
237 |
* local scope of origin. |
|
238 |
* |
|
239 |
* @param pos The source code position to be used for the definition. |
|
240 |
* @param meth The method for which a bridge needs to be added |
|
241 |
* @param impl That method's implementation (possibly the method itself) |
|
242 |
* @param origin The class to which the bridge will be added |
|
243 |
* @param hypothetical |
|
244 |
* True if the bridge method is not strictly necessary in the |
|
245 |
* binary, but is represented in the symbol table to detect |
|
246 |
* erasure clashes. |
|
247 |
* @param bridges The list buffer to which the bridge will be added |
|
248 |
*/ |
|
249 |
void addBridge(DiagnosticPosition pos, |
|
250 |
MethodSymbol meth, |
|
251 |
MethodSymbol impl, |
|
252 |
ClassSymbol origin, |
|
253 |
boolean hypothetical, |
|
254 |
ListBuffer<JCTree> bridges) { |
|
255 |
make.at(pos); |
|
47870
924591048898
8189659: Anonymous subtype of raw type causes VerifyError
sadayapalam
parents:
47248
diff
changeset
|
256 |
Type implTypeErasure = erasure(impl.type); |
10 | 257 |
|
258 |
// Create a bridge method symbol and a bridge definition without a body. |
|
259 |
Type bridgeType = meth.erasure(types); |
|
24793
bb58a9f1ae10
8044487: Fix for 8042785 causes regression tests to fail with java.lang.VerifyError
vromero
parents:
24792
diff
changeset
|
260 |
long flags = impl.flags() & AccessFlags | SYNTHETIC | BRIDGE | |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
261 |
(origin.isInterface() ? DEFAULT : 0); |
10 | 262 |
if (hypothetical) flags |= HYPOTHETICAL; |
263 |
MethodSymbol bridge = new MethodSymbol(flags, |
|
264 |
meth.name, |
|
265 |
bridgeType, |
|
266 |
origin); |
|
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
267 |
/* once JDK-6996415 is solved it should be checked if this approach can |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
268 |
* be applied to method addOverrideBridgesIfNeeded |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
269 |
*/ |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
270 |
bridge.params = createBridgeParams(impl, bridge, bridgeType); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
18000
diff
changeset
|
271 |
bridge.setAttributes(impl); |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
272 |
|
10 | 273 |
if (!hypothetical) { |
274 |
JCMethodDecl md = make.MethodDef(bridge, null); |
|
275 |
||
276 |
// The bridge calls this.impl(..), if we have an implementation |
|
277 |
// in the current class, super.impl(...) otherwise. |
|
278 |
JCExpression receiver = (impl.owner == origin) |
|
279 |
? make.This(origin.erasure(types)) |
|
280 |
: make.Super(types.supertype(origin.type).tsym.erasure(types), origin); |
|
281 |
||
282 |
// The type returned from the original method. |
|
47870
924591048898
8189659: Anonymous subtype of raw type causes VerifyError
sadayapalam
parents:
47248
diff
changeset
|
283 |
Type calltype = implTypeErasure.getReturnType(); |
10 | 284 |
|
285 |
// Construct a call of this.impl(params), or super.impl(params), |
|
286 |
// casting params and possibly results as needed. |
|
287 |
JCExpression call = |
|
288 |
make.Apply( |
|
289 |
null, |
|
290 |
make.Select(receiver, impl).setType(calltype), |
|
47870
924591048898
8189659: Anonymous subtype of raw type causes VerifyError
sadayapalam
parents:
47248
diff
changeset
|
291 |
translateArgs(make.Idents(md.params), implTypeErasure.getParameterTypes(), null)) |
10 | 292 |
.setType(calltype); |
47870
924591048898
8189659: Anonymous subtype of raw type causes VerifyError
sadayapalam
parents:
47248
diff
changeset
|
293 |
JCStatement stat = (implTypeErasure.getReturnType().hasTag(VOID)) |
10 | 294 |
? make.Exec(call) |
295 |
: make.Return(coerce(call, bridgeType.getReturnType())); |
|
296 |
md.body = make.Block(0, List.of(stat)); |
|
297 |
||
298 |
// Add bridge to `bridges' buffer |
|
299 |
bridges.append(md); |
|
300 |
} |
|
301 |
||
33367 | 302 |
// Add bridge to scope of enclosing class and keep track of the bridge span. |
10 | 303 |
origin.members().enter(bridge); |
33367 | 304 |
bridgeSpans.put(bridge, new Pair<>(meth, impl)); |
10 | 305 |
} |
306 |
||
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
307 |
private List<VarSymbol> createBridgeParams(MethodSymbol impl, MethodSymbol bridge, |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
308 |
Type bridgeType) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
309 |
List<VarSymbol> bridgeParams = null; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
310 |
if (impl.params != null) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
311 |
bridgeParams = List.nil(); |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
312 |
List<VarSymbol> implParams = impl.params; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
313 |
Type.MethodType mType = (Type.MethodType)bridgeType; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
314 |
List<Type> argTypes = mType.argtypes; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
315 |
while (implParams.nonEmpty() && argTypes.nonEmpty()) { |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19939
diff
changeset
|
316 |
VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC | PARAMETER, |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
317 |
implParams.head.name, argTypes.head, bridge); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
18000
diff
changeset
|
318 |
param.setAttributes(implParams.head); |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
319 |
bridgeParams = bridgeParams.append(param); |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
320 |
implParams = implParams.tail; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
321 |
argTypes = argTypes.tail; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
322 |
} |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
323 |
} |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
324 |
return bridgeParams; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
325 |
} |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
326 |
|
10 | 327 |
/** Add bridge if given symbol is a non-private, non-static member |
328 |
* of the given class, which is either defined in the class or non-final |
|
329 |
* inherited, and one of the two following conditions holds: |
|
330 |
* 1. The method's type changes in the given class, as compared to the |
|
331 |
* class where the symbol was defined, (in this case |
|
332 |
* we have extended a parameterized class with non-trivial parameters). |
|
333 |
* 2. The method has an implementation with a different erased return type. |
|
334 |
* (in this case we have used co-variant returns). |
|
335 |
* If a bridge already exists in some other class, no new bridge is added. |
|
336 |
* Instead, it is checked that the bridge symbol overrides the method symbol. |
|
337 |
* (Spec ???). |
|
338 |
* todo: what about bridges for privates??? |
|
339 |
* |
|
340 |
* @param pos The source code position to be used for the definition. |
|
341 |
* @param sym The symbol for which a bridge might have to be added. |
|
342 |
* @param origin The class in which the bridge would go. |
|
343 |
* @param bridges The list buffer to which the bridge would be added. |
|
344 |
*/ |
|
345 |
void addBridgeIfNeeded(DiagnosticPosition pos, |
|
346 |
Symbol sym, |
|
347 |
ClassSymbol origin, |
|
348 |
ListBuffer<JCTree> bridges) { |
|
349 |
if (sym.kind == MTH && |
|
350 |
sym.name != names.init && |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
351 |
(sym.flags() & (PRIVATE | STATIC)) == 0 && |
33367 | 352 |
(sym.flags() & SYNTHETIC) != SYNTHETIC && |
10 | 353 |
sym.isMemberOf(origin, types)) |
354 |
{ |
|
355 |
MethodSymbol meth = (MethodSymbol)sym; |
|
356 |
MethodSymbol bridge = meth.binaryImplementation(origin, types); |
|
33367 | 357 |
MethodSymbol impl = meth.implementation(origin, types, true); |
10 | 358 |
if (bridge == null || |
359 |
bridge == meth || |
|
360 |
(impl != null && !bridge.owner.isSubClass(impl.owner, types))) { |
|
361 |
// No bridge was added yet. |
|
362 |
if (impl != null && isBridgeNeeded(meth, impl, origin.type)) { |
|
363 |
addBridge(pos, meth, impl, origin, bridge==impl, bridges); |
|
364 |
} else if (impl == meth |
|
365 |
&& impl.owner != origin |
|
366 |
&& (impl.flags() & FINAL) == 0 |
|
367 |
&& (meth.flags() & (ABSTRACT|PUBLIC)) == PUBLIC |
|
368 |
&& (origin.flags() & PUBLIC) > (impl.owner.flags() & PUBLIC)) { |
|
369 |
// this is to work around a horrible but permanent |
|
370 |
// reflection design error. |
|
371 |
addBridge(pos, meth, impl, origin, false, bridges); |
|
372 |
} |
|
33367 | 373 |
} else if ((bridge.flags() & SYNTHETIC) == SYNTHETIC) { |
374 |
final Pair<MethodSymbol, MethodSymbol> bridgeSpan = bridgeSpans.get(bridge); |
|
375 |
MethodSymbol other = bridgeSpan == null ? null : bridgeSpan.fst; |
|
10 | 376 |
if (other != null && other != meth) { |
377 |
if (impl == null || !impl.overrides(other, origin, types, true)) { |
|
33367 | 378 |
// Is bridge effectively also the bridge for `meth', if so no clash. |
379 |
MethodSymbol target = bridgeSpan == null ? null : bridgeSpan.snd; |
|
380 |
if (target == null || !target.overrides(meth, origin, types, true, false)) { |
|
381 |
// Bridge for other symbol pair was added |
|
45413
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
382 |
log.error(pos, Errors.NameClashSameErasureNoOverride( |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
383 |
other.name, types.memberType(origin.type, other).asMethodType().getParameterTypes(), |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
384 |
other.location(origin.type, types), |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
385 |
meth.name, types.memberType(origin.type, meth).asMethodType().getParameterTypes(), |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
386 |
meth.location(origin.type, types))); |
33367 | 387 |
} |
10 | 388 |
} |
389 |
} |
|
390 |
} else if (!bridge.overrides(meth, origin, types, true)) { |
|
391 |
// Accidental binary override without source override. |
|
45413
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
392 |
// Don't diagnose the problem if it would already |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
393 |
// have been reported in the superclass |
10 | 394 |
if (bridge.owner == origin || |
45413
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
395 |
types.asSuper(bridge.owner.type, meth.owner) == null) { |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
396 |
log.error(pos, Errors.NameClashSameErasureNoOverride( |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
397 |
bridge.name, types.memberType(origin.type, bridge).asMethodType().getParameterTypes(), |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
398 |
bridge.location(origin.type, types), |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
399 |
meth.name, types.memberType(origin.type, meth).asMethodType().getParameterTypes(), |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
400 |
meth.location(origin.type, types))); |
75202c6b2c35
7170058: Confusing error message from javac when overriding a method from a raw supertype
vromero
parents:
41247
diff
changeset
|
401 |
} |
10 | 402 |
} |
403 |
} |
|
404 |
} |
|
405 |
// where |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
406 |
|
10 | 407 |
/** |
408 |
* @param method The symbol for which a bridge might have to be added |
|
409 |
* @param impl The implementation of method |
|
410 |
* @param dest The type in which the bridge would go |
|
411 |
*/ |
|
412 |
private boolean isBridgeNeeded(MethodSymbol method, |
|
413 |
MethodSymbol impl, |
|
414 |
Type dest) { |
|
415 |
if (impl != method) { |
|
416 |
// If either method or impl have different erasures as |
|
417 |
// members of dest, a bridge is needed. |
|
418 |
Type method_erasure = method.erasure(types); |
|
419 |
if (!isSameMemberWhenErased(dest, method, method_erasure)) |
|
420 |
return true; |
|
421 |
Type impl_erasure = impl.erasure(types); |
|
422 |
if (!isSameMemberWhenErased(dest, impl, impl_erasure)) |
|
423 |
return true; |
|
424 |
||
41247
002eb49496ca
8166363: Method with reordered type parameter bounds compiles with @Override annotation but does not actually override superclass method.
sadayapalam
parents:
33711
diff
changeset
|
425 |
/* Bottom line: A bridge is needed if the erasure of the implementation |
002eb49496ca
8166363: Method with reordered type parameter bounds compiles with @Override annotation but does not actually override superclass method.
sadayapalam
parents:
33711
diff
changeset
|
426 |
is different from that of the method that it overrides. |
002eb49496ca
8166363: Method with reordered type parameter bounds compiles with @Override annotation but does not actually override superclass method.
sadayapalam
parents:
33711
diff
changeset
|
427 |
*/ |
002eb49496ca
8166363: Method with reordered type parameter bounds compiles with @Override annotation but does not actually override superclass method.
sadayapalam
parents:
33711
diff
changeset
|
428 |
return !types.isSameType(impl_erasure, method_erasure); |
10 | 429 |
} else { |
430 |
// method and impl are the same... |
|
431 |
if ((method.flags() & ABSTRACT) != 0) { |
|
432 |
// ...and abstract so a bridge is not needed. |
|
433 |
// Concrete subclasses will bridge as needed. |
|
434 |
return false; |
|
435 |
} |
|
436 |
||
437 |
// The erasure of the return type is always the same |
|
438 |
// for the same symbol. Reducing the three tests in |
|
439 |
// the other branch to just one: |
|
440 |
return !isSameMemberWhenErased(dest, method, method.erasure(types)); |
|
441 |
} |
|
442 |
} |
|
443 |
/** |
|
444 |
* Lookup the method as a member of the type. Compare the |
|
445 |
* erasures. |
|
446 |
* @param type the class where to look for the method |
|
447 |
* @param method the method to look for in class |
|
448 |
* @param erasure the erasure of method |
|
449 |
*/ |
|
450 |
private boolean isSameMemberWhenErased(Type type, |
|
451 |
MethodSymbol method, |
|
452 |
Type erasure) { |
|
453 |
return types.isSameType(erasure(types.memberType(type, method)), |
|
454 |
erasure); |
|
455 |
} |
|
456 |
||
457 |
void addBridges(DiagnosticPosition pos, |
|
458 |
TypeSymbol i, |
|
459 |
ClassSymbol origin, |
|
460 |
ListBuffer<JCTree> bridges) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
461 |
for (Symbol sym : i.members().getSymbols(NON_RECURSIVE)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
462 |
addBridgeIfNeeded(pos, sym, origin, bridges); |
10 | 463 |
for (List<Type> l = types.interfaces(i.type); l.nonEmpty(); l = l.tail) |
464 |
addBridges(pos, l.head.tsym, origin, bridges); |
|
465 |
} |
|
466 |
||
467 |
/** Add all necessary bridges to some class appending them to list buffer. |
|
468 |
* @param pos The source code position to be used for the bridges. |
|
469 |
* @param origin The class in which the bridges go. |
|
470 |
* @param bridges The list buffer to which the bridges are added. |
|
471 |
*/ |
|
472 |
void addBridges(DiagnosticPosition pos, ClassSymbol origin, ListBuffer<JCTree> bridges) { |
|
473 |
Type st = types.supertype(origin.type); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
474 |
while (st.hasTag(CLASS)) { |
10 | 475 |
// if (isSpecialization(st)) |
476 |
addBridges(pos, st.tsym, origin, bridges); |
|
477 |
st = types.supertype(st); |
|
478 |
} |
|
479 |
for (List<Type> l = types.interfaces(origin.type); l.nonEmpty(); l = l.tail) |
|
480 |
// if (isSpecialization(l.head)) |
|
481 |
addBridges(pos, l.head.tsym, origin, bridges); |
|
482 |
} |
|
483 |
||
484 |
/* ************************************************************************ |
|
485 |
* Visitor methods |
|
486 |
*************************************************************************/ |
|
487 |
||
488 |
/** Visitor argument: proto-type. |
|
489 |
*/ |
|
490 |
private Type pt; |
|
491 |
||
492 |
/** Visitor method: perform a type translation on tree. |
|
493 |
*/ |
|
494 |
public <T extends JCTree> T translate(T tree, Type pt) { |
|
495 |
Type prevPt = this.pt; |
|
496 |
try { |
|
497 |
this.pt = pt; |
|
498 |
return translate(tree); |
|
499 |
} finally { |
|
500 |
this.pt = prevPt; |
|
501 |
} |
|
502 |
} |
|
503 |
||
504 |
/** Visitor method: perform a type translation on list of trees. |
|
505 |
*/ |
|
506 |
public <T extends JCTree> List<T> translate(List<T> trees, Type pt) { |
|
507 |
Type prevPt = this.pt; |
|
508 |
List<T> res; |
|
509 |
try { |
|
510 |
this.pt = pt; |
|
511 |
res = translate(trees); |
|
512 |
} finally { |
|
513 |
this.pt = prevPt; |
|
514 |
} |
|
515 |
return res; |
|
516 |
} |
|
517 |
||
518 |
public void visitClassDef(JCClassDecl tree) { |
|
519 |
translateClass(tree.sym); |
|
520 |
result = tree; |
|
521 |
} |
|
522 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
523 |
JCTree currentMethod = null; |
10 | 524 |
public void visitMethodDef(JCMethodDecl tree) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
525 |
JCTree previousMethod = currentMethod; |
10 | 526 |
try { |
527 |
currentMethod = tree; |
|
528 |
tree.restype = translate(tree.restype, null); |
|
529 |
tree.typarams = List.nil(); |
|
530 |
tree.params = translateVarDefs(tree.params); |
|
15385 | 531 |
tree.recvparam = translate(tree.recvparam, null); |
10 | 532 |
tree.thrown = translate(tree.thrown, null); |
533 |
tree.body = translate(tree.body, tree.sym.erasure(types).getReturnType()); |
|
534 |
tree.type = erasure(tree.type); |
|
535 |
result = tree; |
|
536 |
} finally { |
|
537 |
currentMethod = previousMethod; |
|
538 |
} |
|
539 |
||
540 |
// Check that we do not introduce a name clash by erasing types. |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
541 |
for (Symbol sym : tree.sym.owner.members().getSymbolsByName(tree.name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
542 |
if (sym != tree.sym && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
543 |
types.isSameType(erasure(sym.type), tree.type)) { |
10 | 544 |
log.error(tree.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45413
diff
changeset
|
545 |
Errors.NameClashSameErasure(tree.sym, sym)); |
10 | 546 |
return; |
547 |
} |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
public void visitVarDef(JCVariableDecl tree) { |
|
552 |
tree.vartype = translate(tree.vartype, null); |
|
553 |
tree.init = translate(tree.init, tree.sym.erasure(types)); |
|
554 |
tree.type = erasure(tree.type); |
|
555 |
result = tree; |
|
556 |
} |
|
557 |
||
558 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
559 |
tree.body = translate(tree.body); |
|
560 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
561 |
result = tree; |
|
562 |
} |
|
563 |
||
564 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
565 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
566 |
tree.body = translate(tree.body); |
|
567 |
result = tree; |
|
568 |
} |
|
569 |
||
570 |
public void visitForLoop(JCForLoop tree) { |
|
571 |
tree.init = translate(tree.init, null); |
|
572 |
if (tree.cond != null) |
|
573 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
574 |
tree.step = translate(tree.step, null); |
|
575 |
tree.body = translate(tree.body); |
|
576 |
result = tree; |
|
577 |
} |
|
578 |
||
579 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
580 |
tree.var = translate(tree.var, null); |
|
581 |
Type iterableType = tree.expr.type; |
|
582 |
tree.expr = translate(tree.expr, erasure(tree.expr.type)); |
|
583 |
if (types.elemtype(tree.expr.type) == null) |
|
584 |
tree.expr.type = iterableType; // preserve type for Lower |
|
585 |
tree.body = translate(tree.body); |
|
586 |
result = tree; |
|
587 |
} |
|
588 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
589 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
590 |
JCTree prevMethod = currentMethod; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
591 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
592 |
currentMethod = null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
593 |
tree.params = translate(tree.params); |
22168
a48fe7ec473d
8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
22163
diff
changeset
|
594 |
tree.body = translate(tree.body, tree.body.type==null? null : erasure(tree.body.type)); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
595 |
tree.type = erasure(tree.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
596 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
597 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
598 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
599 |
currentMethod = prevMethod; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
600 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
601 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
602 |
|
10 | 603 |
public void visitSwitch(JCSwitch tree) { |
604 |
Type selsuper = types.supertype(tree.selector.type); |
|
605 |
boolean enumSwitch = selsuper != null && |
|
606 |
selsuper.tsym == syms.enumSym; |
|
607 |
Type target = enumSwitch ? erasure(tree.selector.type) : syms.intType; |
|
608 |
tree.selector = translate(tree.selector, target); |
|
609 |
tree.cases = translateCases(tree.cases); |
|
610 |
result = tree; |
|
611 |
} |
|
612 |
||
613 |
public void visitCase(JCCase tree) { |
|
614 |
tree.pat = translate(tree.pat, null); |
|
615 |
tree.stats = translate(tree.stats); |
|
616 |
result = tree; |
|
617 |
} |
|
618 |
||
619 |
public void visitSynchronized(JCSynchronized tree) { |
|
620 |
tree.lock = translate(tree.lock, erasure(tree.lock.type)); |
|
621 |
tree.body = translate(tree.body); |
|
622 |
result = tree; |
|
623 |
} |
|
624 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
625 |
public void visitTry(JCTry tree) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
626 |
tree.resources = translate(tree.resources, syms.autoCloseableType); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
627 |
tree.body = translate(tree.body); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
628 |
tree.catchers = translateCatchers(tree.catchers); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
629 |
tree.finalizer = translate(tree.finalizer); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
630 |
result = tree; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
631 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
632 |
|
10 | 633 |
public void visitConditional(JCConditional tree) { |
634 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
635 |
tree.truepart = translate(tree.truepart, erasure(tree.type)); |
|
636 |
tree.falsepart = translate(tree.falsepart, erasure(tree.type)); |
|
637 |
tree.type = erasure(tree.type); |
|
1356
9f40f16e543b
6500343: compiler generates bad code when translating conditional expressions
mcimadamore
parents:
1260
diff
changeset
|
638 |
result = retype(tree, tree.type, pt); |
10 | 639 |
} |
640 |
||
641 |
public void visitIf(JCIf tree) { |
|
642 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
643 |
tree.thenpart = translate(tree.thenpart); |
|
644 |
tree.elsepart = translate(tree.elsepart); |
|
645 |
result = tree; |
|
646 |
} |
|
647 |
||
648 |
public void visitExec(JCExpressionStatement tree) { |
|
649 |
tree.expr = translate(tree.expr, null); |
|
650 |
result = tree; |
|
651 |
} |
|
652 |
||
653 |
public void visitReturn(JCReturn tree) { |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
654 |
tree.expr = translate(tree.expr, currentMethod != null ? types.erasure(currentMethod.type).getReturnType() : null); |
10 | 655 |
result = tree; |
656 |
} |
|
657 |
||
658 |
public void visitThrow(JCThrow tree) { |
|
659 |
tree.expr = translate(tree.expr, erasure(tree.expr.type)); |
|
660 |
result = tree; |
|
661 |
} |
|
662 |
||
663 |
public void visitAssert(JCAssert tree) { |
|
664 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
665 |
if (tree.detail != null) |
|
666 |
tree.detail = translate(tree.detail, erasure(tree.detail.type)); |
|
667 |
result = tree; |
|
668 |
} |
|
669 |
||
670 |
public void visitApply(JCMethodInvocation tree) { |
|
671 |
tree.meth = translate(tree.meth, null); |
|
672 |
Symbol meth = TreeInfo.symbol(tree.meth); |
|
673 |
Type mt = meth.erasure(types); |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
674 |
boolean useInstantiatedPtArgs = |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
675 |
allowGraphInference && !types.isSignaturePolymorphic((MethodSymbol)meth.baseSymbol()); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
676 |
List<Type> argtypes = useInstantiatedPtArgs ? |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
677 |
tree.meth.type.getParameterTypes() : |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
678 |
mt.getParameterTypes(); |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
679 |
if (meth.name == names.init && meth.owner == syms.enumSym) |
10 | 680 |
argtypes = argtypes.tail.tail; |
681 |
if (tree.varargsElement != null) |
|
682 |
tree.varargsElement = types.erasure(tree.varargsElement); |
|
683 |
else |
|
19133
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
684 |
if (tree.args.length() != argtypes.length()) { |
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
685 |
log.error(tree.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45413
diff
changeset
|
686 |
Errors.MethodInvokedWithIncorrectNumberArguments(tree.args.length(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45413
diff
changeset
|
687 |
argtypes.length())); |
19133
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
688 |
} |
10 | 689 |
tree.args = translateArgs(tree.args, argtypes, tree.varargsElement); |
690 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
691 |
tree.type = types.erasure(tree.type); |
10 | 692 |
// Insert casts of method invocation results as needed. |
693 |
result = retype(tree, mt.getReturnType(), pt); |
|
694 |
} |
|
695 |
||
696 |
public void visitNewClass(JCNewClass tree) { |
|
47248 | 697 |
if (tree.encl != null) { |
698 |
if (tree.def == null) { |
|
699 |
tree.encl = translate(tree.encl, erasure(tree.encl.type)); |
|
700 |
} else { |
|
701 |
tree.args = tree.args.prepend(attr.makeNullCheck(tree.encl)); |
|
702 |
tree.encl = null; |
|
703 |
} |
|
704 |
} |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
705 |
|
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
706 |
Type erasedConstructorType = tree.constructorType != null ? |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
707 |
erasure(tree.constructorType) : |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
708 |
null; |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
709 |
|
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
710 |
List<Type> argtypes = erasedConstructorType != null && allowGraphInference ? |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
711 |
erasedConstructorType.getParameterTypes() : |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
712 |
tree.constructor.erasure(types).getParameterTypes(); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
713 |
|
10 | 714 |
tree.clazz = translate(tree.clazz, null); |
715 |
if (tree.varargsElement != null) |
|
716 |
tree.varargsElement = types.erasure(tree.varargsElement); |
|
717 |
tree.args = translateArgs( |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
718 |
tree.args, argtypes, tree.varargsElement); |
10 | 719 |
tree.def = translate(tree.def, null); |
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
720 |
if (erasedConstructorType != null) |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
721 |
tree.constructorType = erasedConstructorType; |
10 | 722 |
tree.type = erasure(tree.type); |
723 |
result = tree; |
|
724 |
} |
|
725 |
||
726 |
public void visitNewArray(JCNewArray tree) { |
|
727 |
tree.elemtype = translate(tree.elemtype, null); |
|
728 |
translate(tree.dims, syms.intType); |
|
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
729 |
if (tree.type != null) { |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
730 |
tree.elems = translate(tree.elems, erasure(types.elemtype(tree.type))); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
731 |
tree.type = erasure(tree.type); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
732 |
} else { |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
733 |
tree.elems = translate(tree.elems, null); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
734 |
} |
10 | 735 |
|
736 |
result = tree; |
|
737 |
} |
|
738 |
||
739 |
public void visitParens(JCParens tree) { |
|
740 |
tree.expr = translate(tree.expr, pt); |
|
28800
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28339
diff
changeset
|
741 |
tree.type = erasure(tree.expr.type); |
10 | 742 |
result = tree; |
743 |
} |
|
744 |
||
745 |
public void visitAssign(JCAssign tree) { |
|
746 |
tree.lhs = translate(tree.lhs, null); |
|
747 |
tree.rhs = translate(tree.rhs, erasure(tree.lhs.type)); |
|
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
748 |
tree.type = erasure(tree.lhs.type); |
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
749 |
result = retype(tree, tree.type, pt); |
10 | 750 |
} |
751 |
||
752 |
public void visitAssignop(JCAssignOp tree) { |
|
3558
56be54d60f36
6869075: regression: javac crashes when compiling compound string assignment with generics
mcimadamore
parents:
3542
diff
changeset
|
753 |
tree.lhs = translate(tree.lhs, null); |
1468
19d266637353
6751514: Unary post-increment with type variables crash javac during lowering
mcimadamore
parents:
1356
diff
changeset
|
754 |
tree.rhs = translate(tree.rhs, tree.operator.type.getParameterTypes().tail.head); |
10 | 755 |
tree.type = erasure(tree.type); |
756 |
result = tree; |
|
757 |
} |
|
758 |
||
759 |
public void visitUnary(JCUnary tree) { |
|
28337
0b46fb7be75a
8043741: VerifyError due to missing checkcast
mcimadamore
parents:
27224
diff
changeset
|
760 |
tree.arg = translate(tree.arg, (tree.getTag() == Tag.NULLCHK) |
0b46fb7be75a
8043741: VerifyError due to missing checkcast
mcimadamore
parents:
27224
diff
changeset
|
761 |
? tree.type |
0b46fb7be75a
8043741: VerifyError due to missing checkcast
mcimadamore
parents:
27224
diff
changeset
|
762 |
: tree.operator.type.getParameterTypes().head); |
10 | 763 |
result = tree; |
764 |
} |
|
765 |
||
766 |
public void visitBinary(JCBinary tree) { |
|
767 |
tree.lhs = translate(tree.lhs, tree.operator.type.getParameterTypes().head); |
|
768 |
tree.rhs = translate(tree.rhs, tree.operator.type.getParameterTypes().tail.head); |
|
769 |
result = tree; |
|
770 |
} |
|
771 |
||
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
772 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
773 |
// For now, we need to keep the annotations in the tree because of the current |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
774 |
// MultiCatch implementation wrt type annotations |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
775 |
List<TypeCompound> mirrors = annotate.fromAnnotations(tree.annotations); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
776 |
tree.underlyingType = translate(tree.underlyingType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
777 |
tree.type = tree.underlyingType.type.annotatedType(mirrors); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
778 |
result = tree; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
779 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29292
diff
changeset
|
780 |
|
10 | 781 |
public void visitTypeCast(JCTypeCast tree) { |
782 |
tree.clazz = translate(tree.clazz, null); |
|
16974
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
783 |
Type originalTarget = tree.type; |
10 | 784 |
tree.type = erasure(tree.type); |
28800
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28339
diff
changeset
|
785 |
JCExpression newExpression = translate(tree.expr, tree.type); |
28339
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
786 |
if (newExpression != tree.expr) { |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
787 |
JCTypeCast typeCast = newExpression.hasTag(Tag.TYPECAST) |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
788 |
? (JCTypeCast) newExpression |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
789 |
: null; |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
790 |
tree.expr = typeCast != null && types.isSameType(typeCast.type, originalTarget, true) |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
791 |
? typeCast.expr |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
792 |
: newExpression; |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
793 |
} |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
28800
diff
changeset
|
794 |
if (originalTarget.isIntersection()) { |
16974
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
795 |
Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget; |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
796 |
for (Type c : ict.getExplicitComponents()) { |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
797 |
Type ec = erasure(c); |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
798 |
if (!types.isSameType(ec, tree.type)) { |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
799 |
tree.expr = coerce(tree.expr, ec); |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
800 |
} |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
801 |
} |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
802 |
} |
10 | 803 |
result = tree; |
804 |
} |
|
805 |
||
806 |
public void visitTypeTest(JCInstanceOf tree) { |
|
807 |
tree.expr = translate(tree.expr, null); |
|
808 |
tree.clazz = translate(tree.clazz, null); |
|
809 |
result = tree; |
|
810 |
} |
|
811 |
||
812 |
public void visitIndexed(JCArrayAccess tree) { |
|
813 |
tree.indexed = translate(tree.indexed, erasure(tree.indexed.type)); |
|
814 |
tree.index = translate(tree.index, syms.intType); |
|
815 |
||
816 |
// Insert casts of indexed expressions as needed. |
|
817 |
result = retype(tree, types.elemtype(tree.indexed.type), pt); |
|
818 |
} |
|
819 |
||
820 |
// There ought to be nothing to rewrite here; |
|
821 |
// we don't generate code. |
|
822 |
public void visitAnnotation(JCAnnotation tree) { |
|
823 |
result = tree; |
|
824 |
} |
|
825 |
||
826 |
public void visitIdent(JCIdent tree) { |
|
827 |
Type et = tree.sym.erasure(types); |
|
828 |
||
829 |
// Map type variables to their bounds. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
830 |
if (tree.sym.kind == TYP && tree.sym.type.hasTag(TYPEVAR)) { |
10 | 831 |
result = make.at(tree.pos).Type(et); |
832 |
} else |
|
833 |
// Map constants expressions to themselves. |
|
834 |
if (tree.type.constValue() != null) { |
|
835 |
result = tree; |
|
836 |
} |
|
837 |
// Insert casts of variable uses as needed. |
|
838 |
else if (tree.sym.kind == VAR) { |
|
839 |
result = retype(tree, et, pt); |
|
840 |
} |
|
841 |
else { |
|
842 |
tree.type = erasure(tree.type); |
|
843 |
result = tree; |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
public void visitSelect(JCFieldAccess tree) { |
|
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
848 |
Type t = types.skipTypeVars(tree.selected.type, false); |
507
bdd92cc35ac4
6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables
mcimadamore
parents:
10
diff
changeset
|
849 |
if (t.isCompound()) { |
7617
6d4424dd7256
6956758: NPE in com.sun.tools.javac.code.Symbol - isSubClass
mcimadamore
parents:
7080
diff
changeset
|
850 |
tree.selected = coerce( |
507
bdd92cc35ac4
6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables
mcimadamore
parents:
10
diff
changeset
|
851 |
translate(tree.selected, erasure(tree.selected.type)), |
10 | 852 |
erasure(tree.sym.owner.type)); |
853 |
} else |
|
854 |
tree.selected = translate(tree.selected, erasure(t)); |
|
855 |
||
856 |
// Map constants expressions to themselves. |
|
857 |
if (tree.type.constValue() != null) { |
|
858 |
result = tree; |
|
859 |
} |
|
860 |
// Insert casts of variable uses as needed. |
|
861 |
else if (tree.sym.kind == VAR) { |
|
862 |
result = retype(tree, tree.sym.erasure(types), pt); |
|
863 |
} |
|
864 |
else { |
|
865 |
tree.type = erasure(tree.type); |
|
866 |
result = tree; |
|
867 |
} |
|
868 |
} |
|
869 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
870 |
public void visitReference(JCMemberReference tree) { |
33711
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
871 |
Type t = types.skipTypeVars(tree.expr.type, false); |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
872 |
Type receiverTarget = t.isCompound() ? erasure(tree.sym.owner.type) : erasure(t); |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
873 |
if (tree.kind == ReferenceKind.UNBOUND) { |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
874 |
tree.expr = make.Type(receiverTarget); |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
875 |
} else { |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
876 |
tree.expr = translate(tree.expr, receiverTarget); |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
877 |
} |
2c47dffb2e18
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
sadayapalam
parents:
33709
diff
changeset
|
878 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
879 |
tree.type = erasure(tree.type); |
23127
5aba53c2b9b2
8034048: javac crash with method references plus lambda plus var args
jjg
parents:
22168
diff
changeset
|
880 |
if (tree.varargsElement != null) |
5aba53c2b9b2
8034048: javac crash with method references plus lambda plus var args
jjg
parents:
22168
diff
changeset
|
881 |
tree.varargsElement = erasure(tree.varargsElement); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
882 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
883 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
884 |
|
10 | 885 |
public void visitTypeArray(JCArrayTypeTree tree) { |
886 |
tree.elemtype = translate(tree.elemtype, null); |
|
887 |
tree.type = erasure(tree.type); |
|
888 |
result = tree; |
|
889 |
} |
|
890 |
||
891 |
/** Visitor method for parameterized types. |
|
892 |
*/ |
|
893 |
public void visitTypeApply(JCTypeApply tree) { |
|
3149 | 894 |
JCTree clazz = translate(tree.clazz, null); |
895 |
result = clazz; |
|
10 | 896 |
} |
897 |
||
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
898 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
899 |
tree.bounds = translate(tree.bounds, null); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
900 |
tree.type = erasure(tree.type); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
901 |
result = tree; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
902 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
903 |
|
10 | 904 |
/************************************************************************** |
905 |
* utility methods |
|
906 |
*************************************************************************/ |
|
907 |
||
908 |
private Type erasure(Type t) { |
|
909 |
return types.erasure(t); |
|
910 |
} |
|
911 |
||
912 |
/************************************************************************** |
|
913 |
* main method |
|
914 |
*************************************************************************/ |
|
915 |
||
916 |
private Env<AttrContext> env; |
|
917 |
||
16968 | 918 |
private static final String statePreviousToFlowAssertMsg = |
919 |
"The current compile state [%s] of class %s is previous to FLOW"; |
|
920 |
||
10 | 921 |
void translateClass(ClassSymbol c) { |
922 |
Type st = types.supertype(c.type); |
|
923 |
// process superclass before derived |
|
16968 | 924 |
if (st.hasTag(CLASS)) { |
10 | 925 |
translateClass((ClassSymbol)st.tsym); |
16968 | 926 |
} |
10 | 927 |
|
25007 | 928 |
Env<AttrContext> myEnv = enter.getEnv(c); |
929 |
if (myEnv == null || (c.flags_field & TYPE_TRANSLATED) != 0) { |
|
10 | 930 |
return; |
16968 | 931 |
} |
25007 | 932 |
c.flags_field |= TYPE_TRANSLATED; |
16968 | 933 |
|
934 |
/* The two assertions below are set for early detection of any attempt |
|
935 |
* to translate a class that: |
|
936 |
* |
|
937 |
* 1) has no compile state being it the most outer class. |
|
938 |
* We accept this condition for inner classes. |
|
939 |
* |
|
940 |
* 2) has a compile state which is previous to Flow state. |
|
941 |
*/ |
|
942 |
boolean envHasCompState = compileStates.get(myEnv) != null; |
|
943 |
if (!envHasCompState && c.outermostClass() == c) { |
|
944 |
Assert.error("No info for outermost class: " + myEnv.enclClass.sym); |
|
945 |
} |
|
946 |
||
947 |
if (envHasCompState && |
|
948 |
CompileState.FLOW.isAfter(compileStates.get(myEnv))) { |
|
949 |
Assert.error(String.format(statePreviousToFlowAssertMsg, |
|
950 |
compileStates.get(myEnv), myEnv.enclClass.sym)); |
|
951 |
} |
|
952 |
||
10 | 953 |
Env<AttrContext> oldEnv = env; |
954 |
try { |
|
955 |
env = myEnv; |
|
956 |
// class has not been translated yet |
|
957 |
||
958 |
TreeMaker savedMake = make; |
|
959 |
Type savedPt = pt; |
|
960 |
make = make.forToplevel(env.toplevel); |
|
961 |
pt = null; |
|
962 |
try { |
|
963 |
JCClassDecl tree = (JCClassDecl) env.tree; |
|
964 |
tree.typarams = List.nil(); |
|
965 |
super.visitClassDef(tree); |
|
966 |
make.at(tree.pos); |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
967 |
ListBuffer<JCTree> bridges = new ListBuffer<>(); |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
968 |
if (allowInterfaceBridges || (tree.sym.flags() & INTERFACE) == 0) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
969 |
addBridges(tree.pos(), c, bridges); |
10 | 970 |
} |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
971 |
tree.defs = bridges.toList().prependList(tree.defs); |
10 | 972 |
tree.type = erasure(tree.type); |
973 |
} finally { |
|
974 |
make = savedMake; |
|
975 |
pt = savedPt; |
|
976 |
} |
|
977 |
} finally { |
|
978 |
env = oldEnv; |
|
979 |
} |
|
980 |
} |
|
981 |
||
982 |
/** Translate a toplevel class definition. |
|
983 |
* @param cdef The definition to be translated. |
|
984 |
*/ |
|
985 |
public JCTree translateTopLevelClass(JCTree cdef, TreeMaker make) { |
|
986 |
// note that this method does NOT support recursion. |
|
987 |
this.make = make; |
|
988 |
pt = null; |
|
989 |
return translate(cdef, null); |
|
990 |
} |
|
991 |
} |