Minor changes on code review
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.util
|
package org.jetbrains.kotlin.idea.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.CallHandle
|
import org.jetbrains.kotlin.resolve.calls.inference.CallHandle
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
|
||||||
@@ -94,8 +94,8 @@ class FuzzyType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun TypeParameterDescriptor.toOriginal(): TypeParameterDescriptor {
|
private fun TypeParameterDescriptor.toOriginal(): TypeParameterDescriptor {
|
||||||
val functionDescriptor = containingDeclaration as? FunctionDescriptor ?: return this
|
val callableDescriptor = containingDeclaration as? CallableMemberDescriptor ?: return this
|
||||||
return functionDescriptor.original.typeParameters[index]
|
return callableDescriptor.original.typeParameters[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?) = other is FuzzyType && other.type == type && other.freeParameters == freeParameters
|
override fun equals(other: Any?) = other is FuzzyType && other.type == type && other.freeParameters == freeParameters
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ abstract class TypesWithOperatorDetector(
|
|||||||
private val scope: LexicalScope,
|
private val scope: LexicalScope,
|
||||||
private val indicesHelper: KotlinIndicesHelper?
|
private val indicesHelper: KotlinIndicesHelper?
|
||||||
) {
|
) {
|
||||||
protected abstract fun checkIsSuitableByType(function: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor?
|
protected abstract fun checkIsSuitableByType(operator: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor?
|
||||||
|
|
||||||
private val cache = HashMap<FuzzyType, Pair<FunctionDescriptor, TypeSubstitutor>?>()
|
private val cache = HashMap<FuzzyType, Pair<FunctionDescriptor, TypeSubstitutor>?>()
|
||||||
|
|
||||||
@@ -109,9 +109,9 @@ class TypesWithContainsDetector(
|
|||||||
private val argumentType: KotlinType
|
private val argumentType: KotlinType
|
||||||
) : TypesWithOperatorDetector(OperatorNameConventions.CONTAINS, scope, indicesHelper) {
|
) : TypesWithOperatorDetector(OperatorNameConventions.CONTAINS, scope, indicesHelper) {
|
||||||
|
|
||||||
override fun checkIsSuitableByType(function: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
override fun checkIsSuitableByType(operator: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
||||||
val parameter = function.valueParameters.single()
|
val parameter = operator.valueParameters.single()
|
||||||
val fuzzyParameterType = FuzzyType(parameter.type, function.typeParameters + freeTypeParams)
|
val fuzzyParameterType = FuzzyType(parameter.type, operator.typeParameters + freeTypeParams)
|
||||||
return fuzzyParameterType.checkIsSuperTypeOf(argumentType)
|
return fuzzyParameterType.checkIsSuperTypeOf(argumentType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,13 +123,13 @@ class TypesWithGetValueDetector(
|
|||||||
private val propertyType: KotlinType?
|
private val propertyType: KotlinType?
|
||||||
) : TypesWithOperatorDetector(OperatorNameConventions.GET_VALUE, scope, indicesHelper) {
|
) : TypesWithOperatorDetector(OperatorNameConventions.GET_VALUE, scope, indicesHelper) {
|
||||||
|
|
||||||
override fun checkIsSuitableByType(function: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
override fun checkIsSuitableByType(operator: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
||||||
val paramType = FuzzyType(function.valueParameters.first().type, freeTypeParams)
|
val paramType = FuzzyType(operator.valueParameters.first().type, freeTypeParams)
|
||||||
val substitutor = paramType.checkIsSuperTypeOf(propertyOwnerType) ?: return null
|
val substitutor = paramType.checkIsSuperTypeOf(propertyOwnerType) ?: return null
|
||||||
|
|
||||||
if (propertyType == null) return substitutor
|
if (propertyType == null) return substitutor
|
||||||
|
|
||||||
val fuzzyReturnType = FuzzyType(function.returnType ?: return null, freeTypeParams)
|
val fuzzyReturnType = FuzzyType(operator.returnType ?: return null, freeTypeParams)
|
||||||
val substitutorFromPropertyType = fuzzyReturnType.checkIsSubtypeOf(propertyType) ?: return null
|
val substitutorFromPropertyType = fuzzyReturnType.checkIsSubtypeOf(propertyType) ?: return null
|
||||||
return TypeSubstitutor.createChainedSubstitutor(substitutor.substitution, substitutorFromPropertyType.substitution)
|
return TypeSubstitutor.createChainedSubstitutor(substitutor.substitution, substitutorFromPropertyType.substitution)
|
||||||
}
|
}
|
||||||
@@ -141,8 +141,8 @@ class TypesWithSetValueDetector(
|
|||||||
private val propertyOwnerType: KotlinType
|
private val propertyOwnerType: KotlinType
|
||||||
) : TypesWithOperatorDetector(OperatorNameConventions.SET_VALUE, scope, indicesHelper) {
|
) : TypesWithOperatorDetector(OperatorNameConventions.SET_VALUE, scope, indicesHelper) {
|
||||||
|
|
||||||
override fun checkIsSuitableByType(function: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
override fun checkIsSuitableByType(operator: FunctionDescriptor, freeTypeParams: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
||||||
val paramType = FuzzyType(function.valueParameters.first().type, freeTypeParams)
|
val paramType = FuzzyType(operator.valueParameters.first().type, freeTypeParams)
|
||||||
return paramType.checkIsSuperTypeOf(propertyOwnerType)
|
return paramType.checkIsSuperTypeOf(propertyOwnerType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user