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.Sets;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
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.checker.JetTypeChecker;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
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);
Pair<Collection<JetType>, Collection<JetType>> pair =
TypeUtils.filterNumberTypes(filterBounds(bounds, LOWER_BOUND, values));
Collection<JetType> generalLowerBounds = pair.getFirst();
Collection<JetType> numberLowerBounds = pair.getSecond();
Collection<JetType> numberLowerBounds = new LinkedHashSet<JetType>();
Collection<JetType> generalLowerBounds = new LinkedHashSet<JetType>();
filterNumberTypes(filterBounds(bounds, LOWER_BOUND, values), numberLowerBounds, generalLowerBounds);
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds);
if (tryPossibleAnswer(superTypeOfLowerBounds)) {
@@ -209,6 +209,21 @@ public class TypeBoundsImpl implements TypeBounds {
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) {
if (possibleAnswer == null) 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.Maps;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Processor;
import kotlin.Function1;
import kotlin.KotlinPackage;
@@ -607,21 +606,6 @@ public class TypeUtils {
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(
@NotNull JetType type,
@NotNull final Map<TypeConstructor, Set<JetType>> constructorToAllInstances,