1
1
/*
2
- * Copyright (C) 2012-2021 The Project Lombok Authors.
2
+ * Copyright (C) 2012-2022 The Project Lombok Authors.
3
3
*
4
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
* of this software and associated documentation files (the "Software"), to deal
47
47
import org .eclipse .jdt .internal .compiler .ast .Annotation ;
48
48
import org .eclipse .jdt .internal .compiler .ast .ClassLiteralAccess ;
49
49
import org .eclipse .jdt .internal .compiler .ast .CompilationUnitDeclaration ;
50
+ import org .eclipse .jdt .internal .compiler .ast .ConditionalExpression ;
50
51
import org .eclipse .jdt .internal .compiler .ast .Expression ;
51
52
import org .eclipse .jdt .internal .compiler .ast .MessageSend ;
52
53
import org .eclipse .jdt .internal .compiler .ast .NameReference ;
@@ -298,7 +299,7 @@ public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend meth
298
299
List <TypeBinding > argumentTypes = new ArrayList <TypeBinding >();
299
300
for (Expression argument : arguments ) {
300
301
TypeBinding argumentType = argument .resolvedType ;
301
- if (argumentType == null && Reflection . isFunctionalExpression (argument )) {
302
+ if (argumentType == null && requiresPolyBinding (argument )) {
302
303
argumentType = Reflection .getPolyTypeBinding (argument );
303
304
}
304
305
if (argumentType == null ) {
@@ -338,8 +339,8 @@ public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend meth
338
339
} else {
339
340
param = parameters [i ];
340
341
}
341
- // Resolve types for lambdas
342
- if (Reflection . isFunctionalExpression (arg )) {
342
+ // Resolve types for polys
343
+ if (requiresPolyBinding (arg )) {
343
344
arg .setExpectedType (param );
344
345
arg .resolveType (scope );
345
346
}
@@ -377,6 +378,10 @@ public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend meth
377
378
MessageSend_postponedErrors .clear (methodCall );
378
379
return resolvedType ;
379
380
}
381
+
382
+ private static boolean requiresPolyBinding (Expression argument ) {
383
+ return Reflection .isFunctionalExpression (argument ) || argument instanceof ConditionalExpression && Reflection .isPolyExpression (argument );
384
+ }
380
385
381
386
private static NameReference createNameRef (TypeBinding typeBinding , ASTNode source ) {
382
387
long p = ((long ) source .sourceStart << 32 ) | source .sourceEnd ;
@@ -407,6 +412,7 @@ private static final class Reflection {
407
412
public static final Field argumentTypes = Permit .permissiveGetField (MessageSend .class , "argumentTypes" );
408
413
public static final Field argumentsHaveErrors = Permit .permissiveGetField (MessageSend .class , "argumentsHaveErrors" );
409
414
public static final Field inferenceContexts = Permit .permissiveGetField (MessageSend .class , "inferenceContexts" );
415
+ private static final Method isPolyExpression = Permit .permissiveGetMethod (Expression .class , "isPolyExpression" );
410
416
private static final Class <?> functionalExpression ;
411
417
private static final Constructor <?> polyTypeBindingConstructor ;
412
418
@@ -432,6 +438,16 @@ public static boolean isFunctionalExpression(Expression expression) {
432
438
return functionalExpression .isInstance (expression );
433
439
}
434
440
441
+ public static boolean isPolyExpression (Expression expression ) {
442
+ if (isPolyExpression == null ) return false ;
443
+ try {
444
+ return (Boolean ) isPolyExpression .invoke (expression );
445
+ } catch (Exception e ) {
446
+ // Ignore
447
+ }
448
+ return false ;
449
+ }
450
+
435
451
public static TypeBinding getPolyTypeBinding (Expression expression ) {
436
452
if (polyTypeBindingConstructor == null ) return null ;
437
453
try {
0 commit comments