68 Types types; |
68 Types types; |
69 JCDiagnostic.Factory diags; |
69 JCDiagnostic.Factory diags; |
70 public final boolean boxingEnabled; // = source.allowBoxing(); |
70 public final boolean boxingEnabled; // = source.allowBoxing(); |
71 public final boolean varargsEnabled; // = source.allowVarargs(); |
71 public final boolean varargsEnabled; // = source.allowVarargs(); |
72 public final boolean allowMethodHandles; |
72 public final boolean allowMethodHandles; |
73 public final boolean allowInvokeDynamic; |
|
74 public final boolean allowTransitionalJSR292; |
|
75 private final boolean debugResolve; |
73 private final boolean debugResolve; |
76 |
74 |
77 Scope polymorphicSignatureScope; |
75 Scope polymorphicSignatureScope; |
78 |
76 |
79 public static Resolve instance(Context context) { |
77 public static Resolve instance(Context context) { |
109 Source source = Source.instance(context); |
107 Source source = Source.instance(context); |
110 boxingEnabled = source.allowBoxing(); |
108 boxingEnabled = source.allowBoxing(); |
111 varargsEnabled = source.allowVarargs(); |
109 varargsEnabled = source.allowVarargs(); |
112 Options options = Options.instance(context); |
110 Options options = Options.instance(context); |
113 debugResolve = options.isSet("debugresolve"); |
111 debugResolve = options.isSet("debugresolve"); |
114 allowTransitionalJSR292 = options.isSet("allowTransitionalJSR292"); |
|
115 Target target = Target.instance(context); |
112 Target target = Target.instance(context); |
116 allowMethodHandles = allowTransitionalJSR292 || |
113 allowMethodHandles = target.hasMethodHandles(); |
117 target.hasMethodHandles(); |
|
118 allowInvokeDynamic = (allowTransitionalJSR292 || |
|
119 target.hasInvokedynamic()) && |
|
120 options.isSet("invokedynamic"); |
|
121 polymorphicSignatureScope = new Scope(syms.noSymbol); |
114 polymorphicSignatureScope = new Scope(syms.noSymbol); |
122 |
115 |
123 inapplicableMethodException = new InapplicableMethodException(diags); |
116 inapplicableMethodException = new InapplicableMethodException(diags); |
124 } |
117 } |
125 |
118 |
334 List<Type> typeargtypes, |
327 List<Type> typeargtypes, |
335 boolean allowBoxing, |
328 boolean allowBoxing, |
336 boolean useVarargs, |
329 boolean useVarargs, |
337 Warner warn) |
330 Warner warn) |
338 throws Infer.InferenceException { |
331 throws Infer.InferenceException { |
339 boolean polymorphicSignature = (m.isPolymorphicSignatureGeneric() && allowMethodHandles) || |
332 boolean polymorphicSignature = m.isPolymorphicSignatureGeneric() && allowMethodHandles; |
340 isTransitionalDynamicCallSite(site, m); |
|
341 if (useVarargs && (m.flags() & VARARGS) == 0) |
333 if (useVarargs && (m.flags() & VARARGS) == 0) |
342 throw inapplicableMethodException.setMessage(null); |
334 throw inapplicableMethodException.setMessage(null); |
343 Type mt = types.memberType(site, m); |
335 Type mt = types.memberType(site, m); |
344 |
336 |
345 // tvars is the list of formal type variables for which type arguments |
337 // tvars is the list of formal type variables for which type arguments |
346 // need to inferred. |
338 // need to inferred. |
347 List<Type> tvars = env.info.tvars; |
339 List<Type> tvars = env.info.tvars; |
348 if (typeargtypes == null) typeargtypes = List.nil(); |
340 if (typeargtypes == null) typeargtypes = List.nil(); |
349 if (allowTransitionalJSR292 && polymorphicSignature && typeargtypes.nonEmpty()) { |
341 if (mt.tag != FORALL && typeargtypes.nonEmpty()) { |
350 //transitional 292 call sites might have wrong number of targs |
|
351 } |
|
352 else if (mt.tag != FORALL && typeargtypes.nonEmpty()) { |
|
353 // This is not a polymorphic method, but typeargs are supplied |
342 // This is not a polymorphic method, but typeargs are supplied |
354 // which is fine, see JLS3 15.12.2.1 |
343 // which is fine, see JLS3 15.12.2.1 |
355 } else if (mt.tag == FORALL && typeargtypes.nonEmpty()) { |
344 } else if (mt.tag == FORALL && typeargtypes.nonEmpty()) { |
356 ForAll pmt = (ForAll) mt; |
345 ForAll pmt = (ForAll) mt; |
357 if (typeargtypes.length() != pmt.tvars.length()) |
346 if (typeargtypes.length() != pmt.tvars.length()) |
385 if (l.head.tag == FORALL) instNeeded = true; |
374 if (l.head.tag == FORALL) instNeeded = true; |
386 } |
375 } |
387 |
376 |
388 if (instNeeded) |
377 if (instNeeded) |
389 return polymorphicSignature ? |
378 return polymorphicSignature ? |
390 infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes, typeargtypes) : |
379 infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes) : |
391 infer.instantiateMethod(env, |
380 infer.instantiateMethod(env, |
392 tvars, |
381 tvars, |
393 (MethodType)mt, |
382 (MethodType)mt, |
394 m, |
383 m, |
395 argtypes, |
384 argtypes, |
398 warn); |
387 warn); |
399 |
388 |
400 checkRawArgumentsAcceptable(argtypes, mt.getParameterTypes(), |
389 checkRawArgumentsAcceptable(argtypes, mt.getParameterTypes(), |
401 allowBoxing, useVarargs, warn); |
390 allowBoxing, useVarargs, warn); |
402 return mt; |
391 return mt; |
403 } |
|
404 |
|
405 boolean isTransitionalDynamicCallSite(Type site, Symbol sym) { |
|
406 return allowTransitionalJSR292 && // old logic that doesn't use annotations |
|
407 !sym.isPolymorphicSignatureInstance() && |
|
408 ((allowMethodHandles && site == syms.methodHandleType && // invokeExact, invokeGeneric, invoke |
|
409 (sym.name == names.invoke && sym.isPolymorphicSignatureGeneric())) || |
|
410 (site == syms.invokeDynamicType && allowInvokeDynamic)); // InvokeDynamic.XYZ |
|
411 } |
392 } |
412 |
393 |
413 /** Same but returns null instead throwing a NoInstanceException |
394 /** Same but returns null instead throwing a NoInstanceException |
414 */ |
395 */ |
415 Type instantiate(Env<AttrContext> env, |
396 Type instantiate(Env<AttrContext> env, |
1410 env.info.varArgs = steps.head.isVarargsRequired(), false); |
1391 env.info.varArgs = steps.head.isVarargsRequired(), false); |
1411 methodResolutionCache.put(steps.head, sym); |
1392 methodResolutionCache.put(steps.head, sym); |
1412 steps = steps.tail; |
1393 steps = steps.tail; |
1413 } |
1394 } |
1414 if (sym.kind >= AMBIGUOUS) { |
1395 if (sym.kind >= AMBIGUOUS) { |
1415 if (site.tsym.isPolymorphicSignatureGeneric() || |
1396 if (site.tsym.isPolymorphicSignatureGeneric()) { |
1416 isTransitionalDynamicCallSite(site, sym)) { |
|
1417 //polymorphic receiver - synthesize new method symbol |
1397 //polymorphic receiver - synthesize new method symbol |
1418 env.info.varArgs = false; |
1398 env.info.varArgs = false; |
1419 sym = findPolymorphicSignatureInstance(env, |
1399 sym = findPolymorphicSignatureInstance(env, |
1420 site, name, null, argtypes, typeargtypes); |
1400 site, name, null, argtypes); |
1421 } |
1401 } |
1422 else { |
1402 else { |
1423 //if nothing is found return the 'first' error |
1403 //if nothing is found return the 'first' error |
1424 MethodResolutionPhase errPhase = |
1404 MethodResolutionPhase errPhase = |
1425 firstErroneousResolutionPhase(); |
1405 firstErroneousResolutionPhase(); |
1429 } |
1409 } |
1430 } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) { |
1410 } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) { |
1431 //non-instantiated polymorphic signature - synthesize new method symbol |
1411 //non-instantiated polymorphic signature - synthesize new method symbol |
1432 env.info.varArgs = false; |
1412 env.info.varArgs = false; |
1433 sym = findPolymorphicSignatureInstance(env, |
1413 sym = findPolymorphicSignatureInstance(env, |
1434 site, name, (MethodSymbol)sym, argtypes, typeargtypes); |
1414 site, name, (MethodSymbol)sym, argtypes); |
1435 } |
1415 } |
1436 return sym; |
1416 return sym; |
1437 } |
1417 } |
1438 |
1418 |
1439 /** Find or create an implicit method of exactly the given type (after erasure). |
1419 /** Find or create an implicit method of exactly the given type (after erasure). |
1447 * @param typeargtypes The required type arguments. |
1427 * @param typeargtypes The required type arguments. |
1448 */ |
1428 */ |
1449 Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site, |
1429 Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site, |
1450 Name name, |
1430 Name name, |
1451 MethodSymbol spMethod, // sig. poly. method or null if none |
1431 MethodSymbol spMethod, // sig. poly. method or null if none |
1452 List<Type> argtypes, |
1432 List<Type> argtypes) { |
1453 List<Type> typeargtypes) { |
|
1454 if (typeargtypes.nonEmpty() && (site.tsym.isPolymorphicSignatureGeneric() || |
|
1455 (spMethod != null && spMethod.isPolymorphicSignatureGeneric()))) { |
|
1456 log.warning(env.tree.pos(), "type.parameter.on.polymorphic.signature"); |
|
1457 } |
|
1458 |
|
1459 Type mtype = infer.instantiatePolymorphicSignatureInstance(env, |
1433 Type mtype = infer.instantiatePolymorphicSignatureInstance(env, |
1460 site, name, spMethod, argtypes, typeargtypes); |
1434 site, name, spMethod, argtypes); |
1461 long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE | |
1435 long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE | |
1462 (spMethod != null ? |
1436 (spMethod != null ? |
1463 spMethod.flags() & Flags.AccessFlags : |
1437 spMethod.flags() & Flags.AccessFlags : |
1464 Flags.PUBLIC | Flags.STATIC); |
1438 Flags.PUBLIC | Flags.STATIC); |
1465 Symbol m = null; |
1439 Symbol m = null; |