mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-psi] PsiMethodCallExpressionImpl: on ambiguous call use upper bound of types if possible
GitOrigin-RevId: 7de48b2542e2fe0a0f8503ab3dd3c4d34784747c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
84f0a34d82
commit
3a2c9be754
+2
-1
@@ -164,7 +164,8 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements
|
||||
theOnly = type;
|
||||
}
|
||||
else if (!theOnly.equals(type)) {
|
||||
return null;
|
||||
theOnly = GenericsUtil.getLeastUpperBound(type, theOnly, file.getManager());
|
||||
if (theOnly == null) return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Main {
|
||||
String foo(int x) { return "1";}
|
||||
StringBuilder foo(String x) { return new StringBuilder();}
|
||||
|
||||
void test() {
|
||||
foo(1.25).le<caret>
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Main {
|
||||
String foo(int x) { return "1";}
|
||||
StringBuilder foo(String x) { return new StringBuilder();}
|
||||
|
||||
void test() {
|
||||
foo(1.25).length()<caret>
|
||||
}
|
||||
}
|
||||
+7
@@ -3251,4 +3251,11 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
myFixture.completeBasic();
|
||||
assertTrue(myFixture.getLookupElementStrings().contains("A"));
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testAmbiguousCallLeastUpperBound() {
|
||||
configureByTestName();
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
}
|
||||
|
||||
+11
-6
@@ -345,19 +345,24 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
PsiMethodCallExpression outerCall = (PsiMethodCallExpression) innerCall.getParent().getParent();
|
||||
|
||||
assertAmbiguous(outerCall);
|
||||
assertAmbiguous(innerCall);
|
||||
assertAmbiguous(outerCall, "java.util.Collection<? extends java.lang.Object>");
|
||||
assertAmbiguous(innerCall, "java.util.Collection<? extends java.lang.Object>");
|
||||
|
||||
dropCaches();
|
||||
|
||||
assertAmbiguous(innerCall);
|
||||
assertAmbiguous(outerCall);
|
||||
assertAmbiguous(innerCall, "java.util.Collection<? extends java.lang.Object>");
|
||||
assertAmbiguous(outerCall, "java.util.Collection<? extends java.lang.Object>");
|
||||
}
|
||||
|
||||
private static void assertAmbiguous(PsiMethodCallExpression call) {
|
||||
private static void assertAmbiguous(PsiMethodCallExpression call, @Nullable String expectedType) {
|
||||
assertNull(call.getText(), call.resolveMethod());
|
||||
assertSize(2, call.multiResolve(false));
|
||||
assertNull(call.getText(), call.getType());
|
||||
PsiType type = call.getType();
|
||||
if (expectedType == null) {
|
||||
assertNull(call.getText(), type);
|
||||
} else {
|
||||
assertEquals(call.getText(), expectedType, type.getCanonicalText());
|
||||
}
|
||||
}
|
||||
|
||||
public void testAdditionalConstraintsBasedOnLambdaResolution() {
|
||||
|
||||
Reference in New Issue
Block a user