calculate transitive inference variable's dependencies (IDEA-151170)

This commit is contained in:
Anna Kozlova
2016-02-03 16:08:27 +03:00
parent c0055bc52c
commit ff21fd0ea5
3 changed files with 42 additions and 8 deletions

View File

@@ -103,14 +103,9 @@ public class InferenceVariable extends LightTypeParameter {
public Set<InferenceVariable> getDependencies(InferenceSession session) {
final Set<InferenceVariable> dependencies = new LinkedHashSet<InferenceVariable>();
for (Collection<PsiType> boundTypes : myBounds.values()) {
if (boundTypes != null) {
for (PsiType bound : boundTypes) {
session.collectDependencies(bound, dependencies);
}
}
}
collectBoundDependencies(session, dependencies);
collectTransitiveDependencies(session, dependencies, dependencies);
if (!session.hasCapture(this) && dependencies.isEmpty()) {
return dependencies;
}
@@ -128,6 +123,33 @@ public class InferenceVariable extends LightTypeParameter {
return dependencies;
}
private void collectTransitiveDependencies(InferenceSession session,
Set<InferenceVariable> dependencies,
Set<InferenceVariable> rootDependencies) {
final LinkedHashSet<InferenceVariable> newDependencies = new LinkedHashSet<InferenceVariable>();
for (InferenceVariable dependency : dependencies) {
dependency.collectBoundDependencies(session, newDependencies);
}
newDependencies.removeAll(rootDependencies);
newDependencies.remove(this);
if (!newDependencies.isEmpty()) {
rootDependencies.addAll(newDependencies);
collectTransitiveDependencies(session, newDependencies, rootDependencies);
}
}
private void collectBoundDependencies(InferenceSession session, Set<InferenceVariable> dependencies) {
for (Collection<PsiType> boundTypes : myBounds.values()) {
if (boundTypes != null) {
for (PsiType bound : boundTypes) {
session.collectDependencies(bound, dependencies);
}
}
}
}
public boolean hasInstantiation(InferenceSession session) {
List<PsiType> bounds = getBounds(InferenceBound.EQ);
if (bounds != null) {

View File

@@ -0,0 +1,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Test {
private void foo(final Stream<String> stream) {
stream.collect(Collectors.collectingAndThen(Collectors.toList(), list -> list)).get(0).length();
}
}

View File

@@ -371,6 +371,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testTransitiveInferenceVariableDependencies() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}