mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
calculate transitive inference variable's dependencies (IDEA-151170)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -371,6 +371,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTransitiveInferenceVariableDependencies() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user