From 4d3d6e8a8cda73d5982872ed5bec179c364247ad Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 1 Sep 2014 16:30:24 +0400 Subject: [PATCH] new inference: ignore trivial dependencies --- .../graphInference/InferenceVariable.java | 21 ++++++++------- .../newLambda/NestedLambdaExpressions1.java | 27 +++++++++++++++++++ .../lambda/NewLambdaHighlightingTest.java | 1 + 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaExpressions1.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java index 8d91b620f798..da7b4b78930a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java @@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.resolve.graphInference; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightTypeParameter; +import com.intellij.psi.util.PsiUtil; import java.util.*; @@ -49,6 +50,10 @@ public class InferenceVariable extends LightTypeParameter { } public boolean addBound(PsiType classType, InferenceBound inferenceBound) { + if (inferenceBound == InferenceBound.EQ && + PsiUtil.resolveClassInClassTypeOnly(classType) == this) { + return false; + } List list = myBounds.get(inferenceBound); if (list == null) { list = new ArrayList(); @@ -77,20 +82,18 @@ public class InferenceVariable extends LightTypeParameter { } } + if (!session.hasCapture(this) && dependencies.isEmpty()) { + return dependencies; + } + next: for (InferenceVariable variable : session.getInferenceVariables()) { if (!dependencies.contains(variable) && variable != this) { - nextBound: - for (List bounds : myBounds.values()) { //todo + for (List bounds : variable.myBounds.values()) { //todo if (bounds != null) { for (PsiType bound : bounds) { - final Set deps = new HashSet(); - session.collectDependencies(bound, deps); - if (deps.isEmpty()) { - continue nextBound; - } - - if (deps.contains(this)) { + final InferenceVariable inferenceVariable = session.getInferenceVariable(bound); + if (inferenceVariable == this) { dependencies.add(variable); continue next; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaExpressions1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaExpressions1.java new file mode 100644 index 000000000000..c31497d1f65a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaExpressions1.java @@ -0,0 +1,27 @@ +class ExplicitLambdaNoParams { + interface I { + T a(); + } + + I foo(I iff) { return null;} + + { + foo(() -> foo(() -> 1)).a(); + I a1 = foo(() -> foo(() -> 1)).a(); + } +} + +class LambdaWithFormalParameterTypes { + + interface I { + T a(int p); + } + + I foo(I iff) { return null;} + + { + foo((int a) -> foo((int b) -> 1)).a(0); + I a1 = foo((int a) -> foo((int b) -> 1)).a(0); + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java index 1da75f51ba6f..e31cb8989ed2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java @@ -94,6 +94,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIDEA126109() { doTest(); } public void testIDEA126809() { doTest(); } public void testIDEA124424() { doTest(); } + public void testNestedLambdaExpressions1() { doTest(); } public void testIDEA127596() throws Exception { doTest();