Refactoring: inlined 'collectSmartCastReceiverValues'
This commit is contained in:
@@ -47,10 +47,7 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
|||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT;
|
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;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION;
|
||||||
@@ -520,9 +517,8 @@ public class CandidateResolver {
|
|||||||
@NotNull ResolutionContext<?> context
|
@NotNull ResolutionContext<?> context
|
||||||
) {
|
) {
|
||||||
ExpressionReceiver receiverToCast = new ExpressionReceiver(JetPsiUtil.safeDeparenthesize(expression, false), actualType);
|
ExpressionReceiver receiverToCast = new ExpressionReceiver(JetPsiUtil.safeDeparenthesize(expression, false), actualType);
|
||||||
List<JetType> variants =
|
Collection<JetType> variants = SmartCastUtils.getSmartCastVariantsExcludingReceiver(
|
||||||
SmartCastUtils.getSmartCastVariantsExcludingReceiver(context.trace.getBindingContext(), context.dataFlowInfo,
|
context.trace.getBindingContext(), context.dataFlowInfo, receiverToCast);
|
||||||
receiverToCast);
|
|
||||||
for (JetType possibleType : variants) {
|
for (JetType possibleType : variants) {
|
||||||
if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) {
|
if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) {
|
||||||
return possibleType;
|
return possibleType;
|
||||||
|
|||||||
+6
-13
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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
|
* @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<JetType> getSmartCastVariantsExcludingReceiver(
|
public static Collection<JetType> getSmartCastVariantsExcludingReceiver(
|
||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull DataFlowInfo dataFlowInfo,
|
@NotNull DataFlowInfo dataFlowInfo,
|
||||||
@NotNull ReceiverValue receiverToCast
|
@NotNull ReceiverValue receiverToCast
|
||||||
@@ -77,23 +78,15 @@ public class SmartCastUtils {
|
|||||||
ThisReceiver receiver = (ThisReceiver) receiverToCast;
|
ThisReceiver receiver = (ThisReceiver) receiverToCast;
|
||||||
assert receiver.exists();
|
assert receiver.exists();
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver);
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver);
|
||||||
return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue);
|
return dataFlowInfo.getPossibleTypes(dataFlowValue);
|
||||||
}
|
}
|
||||||
else if (receiverToCast instanceof ExpressionReceiver) {
|
else if (receiverToCast instanceof ExpressionReceiver) {
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverToCast, bindingContext);
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverToCast, bindingContext);
|
||||||
return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue);
|
return dataFlowInfo.getPossibleTypes(dataFlowValue);
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
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(
|
public static boolean isSubTypeBySmartCastIgnoringNullability(
|
||||||
@NotNull ReceiverValue receiverArgument,
|
@NotNull ReceiverValue receiverArgument,
|
||||||
@NotNull JetType receiverParameterType,
|
@NotNull JetType receiverParameterType,
|
||||||
@@ -106,7 +99,7 @@ public class SmartCastUtils {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private static JetType getSmartCastSubType(
|
private static JetType getSmartCastSubType(
|
||||||
@NotNull JetType receiverParameterType,
|
@NotNull JetType receiverParameterType,
|
||||||
@NotNull List<JetType> smartCastTypes
|
@NotNull Collection<JetType> smartCastTypes
|
||||||
) {
|
) {
|
||||||
Set<JetType> subTypes = Sets.newHashSet();
|
Set<JetType> subTypes = Sets.newHashSet();
|
||||||
for (JetType smartCastType : smartCastTypes) {
|
for (JetType smartCastType : smartCastTypes) {
|
||||||
@@ -136,7 +129,7 @@ public class SmartCastUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JetType> smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver(
|
Collection<JetType> smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver(
|
||||||
context.trace.getBindingContext(), context.dataFlowInfo, receiver);
|
context.trace.getBindingContext(), context.dataFlowInfo, receiver);
|
||||||
JetType smartCastSubType = getSmartCastSubType(receiverParameterType, smartCastTypesExcludingReceiver);
|
JetType smartCastSubType = getSmartCastSubType(receiverParameterType, smartCastTypesExcludingReceiver);
|
||||||
if (smartCastSubType == null) return false;
|
if (smartCastSubType == null) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user