From fe7b5cc532dd96b8112ecc7dabd7fbd761f211d9 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 17 Sep 2013 15:59:12 +0400 Subject: [PATCH] refactoring: moved methods --- .../calls/inference/TypeConstraintsImpl.java | 26 +++---------------- .../jet/lang/types/CommonSupertypes.java | 13 ++++++++++ .../jetbrains/jet/lang/types/TypeUtils.java | 3 ++- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java index f51272550da..fd8a1c27cc1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeConstraintsImpl.java @@ -20,7 +20,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.intellij.openapi.util.Pair; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.Predicate; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.types.*; @@ -152,7 +151,7 @@ public class TypeConstraintsImpl implements TypeConstraints { Collection generalLowerBounds = pair.getFirst(); Collection numberLowerBounds = pair.getSecond(); - JetType superTypeOfLowerBounds = commonSupertype(generalLowerBounds); + JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds); if (trySuggestion(superTypeOfLowerBounds)) { return Collections.singleton(superTypeOfLowerBounds); } @@ -170,14 +169,15 @@ public class TypeConstraintsImpl implements TypeConstraints { values.addAll(withoutErrorTypes.getUpperBounds()); - JetType superTypeOfNumberLowerBounds = commonSupertypeForNumberTypes(numberLowerBounds); + JetType superTypeOfNumberLowerBounds = TypeUtils.commonSupertypeForNumberTypes(numberLowerBounds); if (trySuggestion(superTypeOfNumberLowerBounds)) { return Collections.singleton(superTypeOfNumberLowerBounds); } ContainerUtil.addIfNotNull(superTypeOfNumberLowerBounds, values); if (superTypeOfLowerBounds != null && superTypeOfNumberLowerBounds != null) { - JetType superTypeOfAllLowerBounds = commonSupertype(Lists.newArrayList(superTypeOfLowerBounds, superTypeOfNumberLowerBounds)); + JetType superTypeOfAllLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes( + Lists.newArrayList(superTypeOfLowerBounds, superTypeOfNumberLowerBounds)); if (trySuggestion(superTypeOfAllLowerBounds)) { return Collections.singleton(superTypeOfAllLowerBounds); } @@ -228,22 +228,4 @@ public class TypeConstraintsImpl implements TypeConstraints { } return typeConstraintsWithoutErrorType; } - - @Nullable - private static JetType commonSupertype(@NotNull Collection lowerBounds) { - if (lowerBounds.isEmpty()) return null; - if (lowerBounds.size() == 1) { - JetType type = lowerBounds.iterator().next(); - if (type.getConstructor() instanceof IntersectionTypeConstructor) { - return commonSupertype(type.getConstructor().getSupertypes()); - } - } - return CommonSupertypes.commonSupertype(lowerBounds); - } - - @Nullable - private static JetType commonSupertypeForNumberTypes(@NotNull Collection numberLowerBounds) { - if (numberLowerBounds.isEmpty()) return null; - return TypeUtils.commonSupertypeForNumberTypes(numberLowerBounds); - } } 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 a63c1cbd42c..c098de902ed 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/CommonSupertypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/CommonSupertypes.java @@ -19,6 +19,7 @@ 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; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; @@ -33,6 +34,18 @@ import java.util.*; import static org.jetbrains.jet.lang.types.Variance.*; public class CommonSupertypes { + @Nullable + public static JetType commonSupertypeForNonDenotableTypes(@NotNull Collection types) { + if (types.isEmpty()) return null; + if (types.size() == 1) { + JetType type = types.iterator().next(); + if (type.getConstructor() instanceof IntersectionTypeConstructor) { + return commonSupertypeForNonDenotableTypes(type.getConstructor().getSupertypes()); + } + } + return commonSupertype(types); + } + @NotNull public static JetType commonSupertype(@NotNull Collection types) { assert !types.isEmpty(); 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 2ba99c2f0c9..93fd71007fd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -566,8 +566,9 @@ public class TypeUtils { return builder.toString(); } - @NotNull + @Nullable public static JetType commonSupertypeForNumberTypes(@NotNull Collection numberLowerBounds) { + if (numberLowerBounds.isEmpty()) return null; assert !numberLowerBounds.isEmpty(); Set intersectionOfSupertypes = getIntersectionOfSupertypes(numberLowerBounds); JetType primitiveNumberType = getDefaultPrimitiveNumberType(intersectionOfSupertypes);