mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
inference: stop at assignment when walking up to the top level (IDEA-207128)
GitOrigin-RevId: d12b1e0af3e3f2880e14ecb000e82e3afa887228
This commit is contained in:
committed by
intellij-monorepo-bot
parent
076a9cbca4
commit
d8afa71220
@@ -728,10 +728,11 @@ public class LambdaUtil {
|
||||
PsiLambdaExpression.class,
|
||||
PsiConditionalExpression.class,
|
||||
PsiSwitchExpression.class,
|
||||
PsiAssignmentExpression.class,
|
||||
PsiCodeBlock.class,
|
||||
PsiCall.class);
|
||||
while (true) {
|
||||
if (parent instanceof PsiCall) {
|
||||
if (parent instanceof PsiCall || parent instanceof PsiAssignmentExpression) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -775,7 +776,7 @@ public class LambdaUtil {
|
||||
|
||||
top = psiCall;
|
||||
if (top instanceof PsiExpression && PsiPolyExpressionUtil.isPolyExpression((PsiExpression)top)) {
|
||||
parent = PsiTreeUtil.getParentOfType(parent.getParent(), PsiExpressionList.class, PsiLambdaExpression.class, PsiCodeBlock.class);
|
||||
parent = PsiTreeUtil.getParentOfType(parent.getParent(), PsiExpressionList.class, PsiLambdaExpression.class, PsiAssignmentExpression.class, PsiCodeBlock.class);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.function.*;
|
||||
|
||||
class A {
|
||||
|
||||
{
|
||||
B<Double> local;
|
||||
method(local = new B<>(new C<>((supplier) -> supplier.get())));
|
||||
}
|
||||
|
||||
void method(B<?> value) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class B<T> {
|
||||
B(C<T> c) { }
|
||||
}
|
||||
|
||||
class C<T> {
|
||||
C(Function<Supplier<T>, T> f) { }
|
||||
}
|
||||
@@ -109,6 +109,8 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNestedDiamondsInsideAssignmentInMethodsCall() { doTest();}
|
||||
|
||||
private void doTest() {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.java.codeInsight.daemon.lambda;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
@@ -22,6 +24,11 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InferredTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testNestedCallReturnType() {
|
||||
myFixture.configureByText("a.java", "import java.util.List;\n" +
|
||||
@@ -86,6 +93,45 @@ public class InferredTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.checkHighlighting(false, false, false);
|
||||
}
|
||||
|
||||
public void testNestedDiamondsInsideAssignmentInMethodsCall() throws IOException {
|
||||
String path = JavaTestUtil.getJavaTestDataPath() + Diamond8HighlightingTest.BASE_PATH + "/" + getTestName(false) + ".java";
|
||||
|
||||
String text = FileUtil.loadFile(new File(path));
|
||||
|
||||
PsiFile file = myFixture.configureByText("a.java", text);
|
||||
|
||||
PsiNewExpression newB =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(file, text.indexOf("new B<>"), PsiNewExpression.class, false);
|
||||
|
||||
PsiNewExpression newC =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(file, text.indexOf("new C<>"), PsiNewExpression.class, false);
|
||||
|
||||
PsiMethodCallExpression get =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(file, text.indexOf("get()"), PsiMethodCallExpression.class, false);
|
||||
|
||||
PsiLambdaExpression lambda =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(file, text.indexOf("->"), PsiLambdaExpression.class, false);
|
||||
|
||||
assertEquals("B<Double>", newB.getType().getPresentableText());
|
||||
assertEquals("Double", get.getType().getPresentableText());
|
||||
assertEquals("C<Double>", newC.getType().getPresentableText());
|
||||
assertEquals("Function<Supplier<Double>, Double>", lambda.getFunctionalInterfaceType().getPresentableText());
|
||||
|
||||
checkResolveResultDoesNotDependOnResolveOrder(file);
|
||||
}
|
||||
|
||||
private void checkResolveResultDoesNotDependOnResolveOrder(PsiFile file) {
|
||||
Map<PsiJavaCodeReferenceElement, String> gold = new HashMap<>();
|
||||
for (PsiJavaCodeReferenceElement ref : SyntaxTraverser.psiTraverser(file).filter(PsiJavaCodeReferenceElement.class)) {
|
||||
gold.put(ref, ref.advancedResolve(true).toString());
|
||||
}
|
||||
|
||||
for (PsiJavaCodeReferenceElement ref : gold.keySet()) {
|
||||
getPsiManager().dropPsiCaches();
|
||||
assertEquals("Wrong resolve result for " + ref.getText(), gold.get(ref), ref.advancedResolve(true).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
|
||||
Reference in New Issue
Block a user