diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/CommonSupertypes.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/CommonSupertypes.java index c098de902ed..38b7b3959c3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/CommonSupertypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/CommonSupertypes.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.lang.types; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,11 +26,12 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; -import org.jetbrains.jet.utils.DFS; import java.util.*; -import static org.jetbrains.jet.lang.types.Variance.*; +import static org.jetbrains.jet.lang.types.TypeUtils.topologicallySortSuperclassesAndRecordAllInstances; +import static org.jetbrains.jet.lang.types.Variance.IN_VARIANCE; +import static org.jetbrains.jet.lang.types.Variance.OUT_VARIANCE; public class CommonSupertypes { @Nullable @@ -135,55 +135,6 @@ public class CommonSupertypes { return result; } - private static List topologicallySortSuperclassesAndRecordAllInstances( - @NotNull JetType type, - @NotNull final Map> constructorToAllInstances, - @NotNull final Set visited - ) { - return DFS.dfs( - Collections.singletonList(type), - new DFS.Neighbors() { - @NotNull - @Override - public Iterable getNeighbors(JetType current) { - TypeSubstitutor substitutor = TypeSubstitutor.create(current); - List result = Lists.newArrayList(); - for (JetType supertype : current.getConstructor().getSupertypes()) { - if (visited.contains(supertype.getConstructor())) { - continue; - } - result.add(substitutor.safeSubstitute(supertype, INVARIANT)); - } - return result; - } - }, - new DFS.Visited() { - @Override - public boolean checkAndMarkVisited(JetType current) { - return visited.add(current.getConstructor()); - } - }, - new DFS.NodeHandlerWithListResult() { - @Override - public void beforeChildren(JetType current) { - TypeConstructor constructor = current.getConstructor(); - - Set instances = constructorToAllInstances.get(constructor); - if (instances == null) { - instances = new HashSet(); - constructorToAllInstances.put(constructor, instances); - } - instances.add(current); - } - - @Override - public void afterChildren(JetType current) { - result.addFirst(current.getConstructor()); - } - } - ); - } - // constructor - type constructor of a supertype to be instantiated // types - instantiations of constructor occurring as supertypes of classes we are trying to intersect @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java index 93fd71007fd..8ed5cd91842 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -34,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.scopes.ChainedScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; +import org.jetbrains.jet.utils.DFS; import java.util.*; @@ -648,4 +649,53 @@ public class TypeUtils { } return Pair.create(otherTypes, numberTypes); } + + public static List topologicallySortSuperclassesAndRecordAllInstances( + @NotNull JetType type, + @NotNull final Map> constructorToAllInstances, + @NotNull final Set visited + ) { + return DFS.dfs( + Collections.singletonList(type), + new DFS.Neighbors() { + @NotNull + @Override + public Iterable getNeighbors(JetType current) { + TypeSubstitutor substitutor = TypeSubstitutor.create(current); + List result = Lists.newArrayList(); + for (JetType supertype : current.getConstructor().getSupertypes()) { + if (visited.contains(supertype.getConstructor())) { + continue; + } + result.add(substitutor.safeSubstitute(supertype, Variance.INVARIANT)); + } + return result; + } + }, + new DFS.Visited() { + @Override + public boolean checkAndMarkVisited(JetType current) { + return visited.add(current.getConstructor()); + } + }, + new DFS.NodeHandlerWithListResult() { + @Override + public void beforeChildren(JetType current) { + TypeConstructor constructor = current.getConstructor(); + + Set instances = constructorToAllInstances.get(constructor); + if (instances == null) { + instances = new HashSet(); + constructorToAllInstances.put(constructor, instances); + } + instances.add(current); + } + + @Override + public void afterChildren(JetType current) { + result.addFirst(current.getConstructor()); + } + } + ); + } }