rename: suggestion -> possibleAnswer

This commit is contained in:
Svetlana Isakova
2013-10-09 17:58:48 +04:00
parent 0f444903f6
commit 4ab3d50e4d
@@ -144,13 +144,13 @@ public class TypeBoundsImpl implements TypeBounds {
@Override @Override
public Collection<JetType> getValues() { public Collection<JetType> getValues() {
if (resultValues == null) { if (resultValues == null) {
resultValues = computeValues(bounds); resultValues = computeValues();
} }
return resultValues; return resultValues;
} }
@NotNull @NotNull
private static Collection<JetType> computeValues(@NotNull Collection<Bound> bounds) { private Collection<JetType> computeValues() {
Set<JetType> values = Sets.newLinkedHashSet(); Set<JetType> values = Sets.newLinkedHashSet();
if (bounds.isEmpty()) { if (bounds.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
@@ -168,7 +168,7 @@ public class TypeBoundsImpl implements TypeBounds {
Set<JetType> exactBounds = filterBounds(bounds, BoundKind.EXACT_BOUND, values); Set<JetType> exactBounds = filterBounds(bounds, BoundKind.EXACT_BOUND, values);
if (exactBounds.size() == 1) { if (exactBounds.size() == 1) {
JetType exactBound = exactBounds.iterator().next(); JetType exactBound = exactBounds.iterator().next();
if (trySuggestion(exactBound, bounds)) { if (tryPossibleAnswer(exactBound)) {
return Collections.singleton(exactBound); return Collections.singleton(exactBound);
} }
} }
@@ -180,7 +180,7 @@ public class TypeBoundsImpl implements TypeBounds {
Collection<JetType> numberLowerBounds = pair.getSecond(); Collection<JetType> numberLowerBounds = pair.getSecond();
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds); JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds);
if (trySuggestion(superTypeOfLowerBounds, bounds)) { if (tryPossibleAnswer(superTypeOfLowerBounds)) {
return Collections.singleton(superTypeOfLowerBounds); return Collections.singleton(superTypeOfLowerBounds);
} }
ContainerUtil.addIfNotNull(superTypeOfLowerBounds, values); ContainerUtil.addIfNotNull(superTypeOfLowerBounds, values);
@@ -188,7 +188,7 @@ public class TypeBoundsImpl implements TypeBounds {
Set<JetType> upperBounds = filterBounds(bounds, BoundKind.UPPER_BOUND, values); Set<JetType> upperBounds = filterBounds(bounds, BoundKind.UPPER_BOUND, values);
JetType intersectionOfUpperBounds = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds); JetType intersectionOfUpperBounds = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds);
if (!upperBounds.isEmpty() && intersectionOfUpperBounds != null) { if (!upperBounds.isEmpty() && intersectionOfUpperBounds != null) {
if (trySuggestion(intersectionOfUpperBounds, bounds)) { if (tryPossibleAnswer(intersectionOfUpperBounds)) {
return Collections.singleton(intersectionOfUpperBounds); return Collections.singleton(intersectionOfUpperBounds);
} }
} }
@@ -199,7 +199,7 @@ public class TypeBoundsImpl implements TypeBounds {
values.addAll(filterBounds(bounds, BoundKind.UPPER_BOUND)); values.addAll(filterBounds(bounds, BoundKind.UPPER_BOUND));
JetType superTypeOfNumberLowerBounds = TypeUtils.commonSupertypeForNumberTypes(numberLowerBounds); JetType superTypeOfNumberLowerBounds = TypeUtils.commonSupertypeForNumberTypes(numberLowerBounds);
if (trySuggestion(superTypeOfNumberLowerBounds, bounds)) { if (tryPossibleAnswer(superTypeOfNumberLowerBounds)) {
return Collections.singleton(superTypeOfNumberLowerBounds); return Collections.singleton(superTypeOfNumberLowerBounds);
} }
ContainerUtil.addIfNotNull(superTypeOfNumberLowerBounds, values); ContainerUtil.addIfNotNull(superTypeOfNumberLowerBounds, values);
@@ -207,37 +207,33 @@ public class TypeBoundsImpl implements TypeBounds {
if (superTypeOfLowerBounds != null && superTypeOfNumberLowerBounds != null) { if (superTypeOfLowerBounds != null && superTypeOfNumberLowerBounds != null) {
JetType superTypeOfAllLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes( JetType superTypeOfAllLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(
Lists.newArrayList(superTypeOfLowerBounds, superTypeOfNumberLowerBounds)); Lists.newArrayList(superTypeOfLowerBounds, superTypeOfNumberLowerBounds));
if (trySuggestion(superTypeOfAllLowerBounds, bounds)) { if (tryPossibleAnswer(superTypeOfAllLowerBounds)) {
return Collections.singleton(superTypeOfAllLowerBounds); return Collections.singleton(superTypeOfAllLowerBounds);
} }
} }
return values; return values;
} }
private static boolean trySuggestion( private boolean tryPossibleAnswer(@Nullable JetType possibleAnswer) {
@Nullable JetType suggestion, if (possibleAnswer == null) return false;
@NotNull Collection<Bound> bounds if (!possibleAnswer.getConstructor().isDenotable()) return false;
) {
if (suggestion == null) return false;
if (!suggestion.getConstructor().isDenotable()) return false;
if (filterBounds(bounds, BoundKind.EXACT_BOUND).size() > 1) return false;
for (Bound bound : bounds) { for (Bound bound : bounds) {
switch (bound.kind) { switch (bound.kind) {
case LOWER_BOUND: case LOWER_BOUND:
if (!JetTypeChecker.INSTANCE.isSubtypeOf(bound.type, suggestion)) { if (!JetTypeChecker.INSTANCE.isSubtypeOf(bound.type, possibleAnswer)) {
return false; return false;
} }
break; break;
case UPPER_BOUND: case UPPER_BOUND:
if (!JetTypeChecker.INSTANCE.isSubtypeOf(suggestion, bound.type)) { if (!JetTypeChecker.INSTANCE.isSubtypeOf(possibleAnswer, bound.type)) {
return false; return false;
} }
break; break;
case EXACT_BOUND: case EXACT_BOUND:
if (!JetTypeChecker.INSTANCE.equalTypes(bound.type, suggestion)) { if (!JetTypeChecker.INSTANCE.equalTypes(bound.type, possibleAnswer)) {
return false; return false;
} }
break; break;