Refactoring: inlined 'collectSmartCastReceiverValues'

This commit is contained in:
Svetlana Isakova
2014-10-16 18:53:11 +04:00
parent 4a1a95ea36
commit 68e2e21fb9
2 changed files with 9 additions and 20 deletions
@@ -47,10 +47,7 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT;
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION;
@@ -520,9 +517,8 @@ public class CandidateResolver {
@NotNull ResolutionContext<?> context
) {
ExpressionReceiver receiverToCast = new ExpressionReceiver(JetPsiUtil.safeDeparenthesize(expression, false), actualType);
List<JetType> variants =
SmartCastUtils.getSmartCastVariantsExcludingReceiver(context.trace.getBindingContext(), context.dataFlowInfo,
receiverToCast);
Collection<JetType> variants = SmartCastUtils.getSmartCastVariantsExcludingReceiver(
context.trace.getBindingContext(), context.dataFlowInfo, receiverToCast);
for (JetType possibleType : variants) {
if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) {
return possibleType;
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -68,7 +69,7 @@ public class SmartCastUtils {
* @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included
*/
@NotNull
public static List<JetType> getSmartCastVariantsExcludingReceiver(
public static Collection<JetType> getSmartCastVariantsExcludingReceiver(
@NotNull BindingContext bindingContext,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull ReceiverValue receiverToCast
@@ -77,23 +78,15 @@ public class SmartCastUtils {
ThisReceiver receiver = (ThisReceiver) receiverToCast;
assert receiver.exists();
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver);
return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue);
return dataFlowInfo.getPossibleTypes(dataFlowValue);
}
else if (receiverToCast instanceof ExpressionReceiver) {
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverToCast, bindingContext);
return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue);
return dataFlowInfo.getPossibleTypes(dataFlowValue);
}
return Collections.emptyList();
}
@NotNull
private static List<JetType> collectSmartCastReceiverValues(
@NotNull DataFlowInfo dataFlowInfo,
@NotNull DataFlowValue dataFlowValue
) {
return Lists.newArrayList(dataFlowInfo.getPossibleTypes(dataFlowValue));
}
public static boolean isSubTypeBySmartCastIgnoringNullability(
@NotNull ReceiverValue receiverArgument,
@NotNull JetType receiverParameterType,
@@ -106,7 +99,7 @@ public class SmartCastUtils {
@Nullable
private static JetType getSmartCastSubType(
@NotNull JetType receiverParameterType,
@NotNull List<JetType> smartCastTypes
@NotNull Collection<JetType> smartCastTypes
) {
Set<JetType> subTypes = Sets.newHashSet();
for (JetType smartCastType : smartCastTypes) {
@@ -136,7 +129,7 @@ public class SmartCastUtils {
return false;
}
List<JetType> smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver(
Collection<JetType> smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver(
context.trace.getBindingContext(), context.dataFlowInfo, receiver);
JetType smartCastSubType = getSmartCastSubType(receiverParameterType, smartCastTypesExcludingReceiver);
if (smartCastSubType == null) return false;