Get rid of intellij Pair in TypeUtils

This commit is contained in:
Alexander Udalov
2013-10-08 18:28:45 +04:00
parent beb66e2247
commit c18fd179a9
2 changed files with 20 additions and 21 deletions
@@ -19,16 +19,17 @@ package org.jetbrains.jet.lang.resolve.calls.inference;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKind.LOWER_BOUND; import static org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKind.LOWER_BOUND;
@@ -167,10 +168,9 @@ public class TypeBoundsImpl implements TypeBounds {
} }
values.addAll(exactBounds); values.addAll(exactBounds);
Pair<Collection<JetType>, Collection<JetType>> pair = Collection<JetType> numberLowerBounds = new LinkedHashSet<JetType>();
TypeUtils.filterNumberTypes(filterBounds(bounds, LOWER_BOUND, values)); Collection<JetType> generalLowerBounds = new LinkedHashSet<JetType>();
Collection<JetType> generalLowerBounds = pair.getFirst(); filterNumberTypes(filterBounds(bounds, LOWER_BOUND, values), numberLowerBounds, generalLowerBounds);
Collection<JetType> numberLowerBounds = pair.getSecond();
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds); JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds);
if (tryPossibleAnswer(superTypeOfLowerBounds)) { if (tryPossibleAnswer(superTypeOfLowerBounds)) {
@@ -209,6 +209,21 @@ public class TypeBoundsImpl implements TypeBounds {
return values; return values;
} }
private static void filterNumberTypes(
@NotNull Collection<JetType> types,
@NotNull Collection<JetType> numberTypes,
@NotNull Collection<JetType> otherTypes
) {
for (JetType type : types) {
if (type.getConstructor() instanceof IntegerValueTypeConstructor) {
numberTypes.add(type);
}
else {
otherTypes.add(type);
}
}
}
private boolean tryPossibleAnswer(@Nullable JetType possibleAnswer) { private boolean tryPossibleAnswer(@Nullable JetType possibleAnswer) {
if (possibleAnswer == null) return false; if (possibleAnswer == null) return false;
if (!possibleAnswer.getConstructor().isDenotable()) return false; if (!possibleAnswer.getConstructor().isDenotable()) return false;
@@ -21,7 +21,6 @@ import com.google.common.collect.Collections2;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Processor; import com.intellij.util.Processor;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
@@ -607,21 +606,6 @@ public class TypeUtils {
return getDefaultPrimitiveNumberType(numberValueTypeConstructor); return getDefaultPrimitiveNumberType(numberValueTypeConstructor);
} }
@NotNull
public static Pair<Collection<JetType>, Collection<JetType>> filterNumberTypes(@NotNull Collection<JetType> types) {
Collection<JetType> numberTypes = Sets.newLinkedHashSet();
Collection<JetType> otherTypes = Sets.newLinkedHashSet();
for (JetType type : types) {
if (type.getConstructor() instanceof IntegerValueTypeConstructor) {
numberTypes.add(type);
}
else {
otherTypes.add(type);
}
}
return Pair.create(otherTypes, numberTypes);
}
public static List<TypeConstructor> topologicallySortSuperclassesAndRecordAllInstances( public static List<TypeConstructor> topologicallySortSuperclassesAndRecordAllInstances(
@NotNull JetType type, @NotNull JetType type,
@NotNull final Map<TypeConstructor, Set<JetType>> constructorToAllInstances, @NotNull final Map<TypeConstructor, Set<JetType>> constructorToAllInstances,