added 'commonSupertypeForPossiblyNumberTypes'
This commit is contained in:
+5
-10
@@ -48,16 +48,11 @@ public class ConstraintsUtil {
|
|||||||
}
|
}
|
||||||
values.addAll(exactBounds);
|
values.addAll(exactBounds);
|
||||||
|
|
||||||
Collection<JetType> lowerBounds = Sets.newHashSet();
|
Pair<Collection<JetType>, Collection<JetType>> pair =
|
||||||
Collection<JetType> numberLowerBounds = Sets.newHashSet();
|
TypeUtils.filterNumberTypes(typeConstraintsWithoutErrorTypes.getLowerBounds());
|
||||||
for (JetType lowerBound : typeConstraintsWithoutErrorTypes.getLowerBounds()) {
|
Collection<JetType> lowerBounds = pair.getFirst();
|
||||||
if (lowerBound.getConstructor() instanceof NumberValueTypeConstructor) {
|
Collection<JetType> numberLowerBounds = pair.getSecond();
|
||||||
numberLowerBounds.add(lowerBound);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lowerBounds.add(lowerBound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
JetType superTypeOfLowerBounds = commonSupertype(lowerBounds);
|
JetType superTypeOfLowerBounds = commonSupertype(lowerBounds);
|
||||||
if (trySuggestion(superTypeOfLowerBounds, typeConstraints)) {
|
if (trySuggestion(superTypeOfLowerBounds, typeConstraints)) {
|
||||||
return Collections.singleton(superTypeOfLowerBounds);
|
return Collections.singleton(superTypeOfLowerBounds);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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 org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -616,4 +617,30 @@ 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 NumberValueTypeConstructor) {
|
||||||
|
numberTypes.add(type);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
otherTypes.add(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Pair.create(otherTypes, numberTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static JetType commonSupertypeForPossiblyNumberTypes(@NotNull Collection<JetType> types) {
|
||||||
|
Pair<Collection<JetType>, Collection<JetType>> pair = filterNumberTypes(types);
|
||||||
|
Collection<JetType> numberTypes = pair.getSecond();
|
||||||
|
Collection<JetType> otherTypes = pair.getFirst();
|
||||||
|
if (!numberTypes.isEmpty()) {
|
||||||
|
otherTypes.add(commonSupertypeForNumberTypes(numberTypes));
|
||||||
|
}
|
||||||
|
return CommonSupertypes.commonSupertype(otherTypes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user