[Misc] Make ArgumentTypeResolver::isSubtypeOfForArgumentType not static

Later, it will use type-refinement component that'll be injected there
This commit is contained in:
Denis Zharkov
2019-04-24 12:21:42 +03:00
committed by Dmitry Savvinov
parent 529763b9bd
commit 7ba3f7e599
3 changed files with 15 additions and 11 deletions
@@ -55,7 +55,6 @@ import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
public class ArgumentTypeResolver {
@NotNull private final TypeResolver typeResolver;
@NotNull private final DoubleColonExpressionResolver doubleColonExpressionResolver;
@NotNull private final KotlinBuiltIns builtIns;
@NotNull private final ReflectionTypes reflectionTypes;
@NotNull private final ConstantExpressionEvaluator constantExpressionEvaluator;
@@ -63,10 +62,10 @@ public class ArgumentTypeResolver {
@NotNull private final ModuleDescriptor moduleDescriptor;
private ExpressionTypingServices expressionTypingServices;
private DoubleColonExpressionResolver doubleColonExpressionResolver;
public ArgumentTypeResolver(
@NotNull TypeResolver typeResolver,
@NotNull DoubleColonExpressionResolver doubleColonExpressionResolver,
@NotNull KotlinBuiltIns builtIns,
@NotNull ReflectionTypes reflectionTypes,
@NotNull ConstantExpressionEvaluator constantExpressionEvaluator,
@@ -74,7 +73,6 @@ public class ArgumentTypeResolver {
@NotNull ModuleDescriptor moduleDescriptor
) {
this.typeResolver = typeResolver;
this.doubleColonExpressionResolver = doubleColonExpressionResolver;
this.builtIns = builtIns;
this.reflectionTypes = reflectionTypes;
this.constantExpressionEvaluator = constantExpressionEvaluator;
@@ -88,7 +86,12 @@ public class ArgumentTypeResolver {
this.expressionTypingServices = expressionTypingServices;
}
public static boolean isSubtypeOfForArgumentType(
@Inject
public void setDoubleColonExpressionResolver(@NotNull DoubleColonExpressionResolver doubleColonExpressionResolver) {
this.doubleColonExpressionResolver = doubleColonExpressionResolver;
}
public boolean isSubtypeOfForArgumentType(
@NotNull KotlinType actualType,
@NotNull KotlinType expectedType
) {
@@ -99,6 +102,7 @@ public class ArgumentTypeResolver {
return KotlinTypeChecker.DEFAULT.isSubtypeOf(actualType, expectedType);
}
public void checkTypesWithNoCallee(
@NotNull CallResolutionContext<?> context
) {
@@ -362,7 +362,7 @@ class CandidateResolver(
if (type == null || (type.isError && !type.isFunctionPlaceholder)) {
matchStatus = ArgumentMatchStatus.ARGUMENT_HAS_NO_TYPE
} else if (!noExpectedType(expectedType)) {
if (!ArgumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) {
if (!argumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) {
val smartCast = smartCastValueArgumentTypeIfPossible(expression, newContext.expectedType, type, newContext)
if (smartCast == null) {
resultStatus = tryNotNullableArgument(type, expectedType) ?: OTHER_ERROR
@@ -410,7 +410,7 @@ class CandidateResolver(
if (!argumentType.isMarkedNullable || parameterType.isMarkedNullable) return null
val notNullableArgumentType = argumentType.makeNotNullable()
val isApplicable = ArgumentTypeResolver.isSubtypeOfForArgumentType(notNullableArgumentType, parameterType)
val isApplicable = argumentTypeResolver.isSubtypeOfForArgumentType(notNullableArgumentType, parameterType)
return if (isApplicable) NULLABLE_ARGUMENT_TYPE_MISMATCH else null
}
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.expandIntersectionTypeIfNecessary
import java.util.*
class SmartCastManager {
class SmartCastManager(private val argumentTypeResolver: ArgumentTypeResolver) {
fun getSmartCastVariants(
receiverToCast: ReceiverValue,
@@ -110,10 +110,10 @@ class SmartCastManager {
context: ResolutionContext<*>
): ReceiverSmartCastResult? =
when {
ArgumentTypeResolver.isSubtypeOfForArgumentType(receiverArgument.type, receiverParameterType) ->
argumentTypeResolver.isSubtypeOfForArgumentType(receiverArgument.type, receiverParameterType) ->
ReceiverSmartCastResult.OK
getSmartCastVariantsExcludingReceiver(context, receiverArgument).any {
ArgumentTypeResolver.isSubtypeOfForArgumentType(it, receiverParameterType)
argumentTypeResolver.isSubtypeOfForArgumentType(it, receiverParameterType)
} ->
ReceiverSmartCastResult.SMARTCAST_NEEDED_OR_NOT_NULL_EXPECTED
else -> null
@@ -135,7 +135,7 @@ class SmartCastManager {
listOf(expectedType)
for (possibleType in c.dataFlowInfo.getCollectedTypes(dataFlowValue, c.languageVersionSettings)) {
if (expectedTypes.any { ArgumentTypeResolver.isSubtypeOfForArgumentType(possibleType, it) } &&
if (expectedTypes.any { argumentTypeResolver.isSubtypeOfForArgumentType(possibleType, it) } &&
(additionalPredicate == null || additionalPredicate(possibleType))
) {
if (expression != null) {
@@ -180,7 +180,7 @@ class SmartCastManager {
val immanentlyNotNull = !dataFlowValue.immanentNullability.canBeNull()
val nullableExpectedType = TypeUtils.makeNullable(expectedType)
if (ArgumentTypeResolver.isSubtypeOfForArgumentType(dataFlowValue.type, nullableExpectedType) &&
if (argumentTypeResolver.isSubtypeOfForArgumentType(dataFlowValue.type, nullableExpectedType) &&
(additionalPredicate == null || additionalPredicate(dataFlowValue.type))
) {
if (!immanentlyNotNull && expression != null) {