Minor. Extract FlatSignature factory
This commit is contained in:
+2
-11
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.results
|
package org.jetbrains.kotlin.resolve.calls.results
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
|
||||||
import org.jetbrains.kotlin.psi.ValueArgument
|
import org.jetbrains.kotlin.psi.ValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
|
||||||
@@ -26,7 +25,6 @@ import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCallImpl
|
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCallImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature.Companion.argumentValueType
|
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature.Companion.argumentValueType
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature.Companion.extensionReceiverTypeOrEmpty
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -50,14 +48,7 @@ fun <RC : ResolvedCall<*>> RC.createFlatSignature(): FlatSignature<RC> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FlatSignature(this,
|
return FlatSignature.create(this, originalDescriptor, numDefaults, call.valueArguments.map { valueArgumentToParameterType[it] })
|
||||||
originalDescriptor.typeParameters,
|
|
||||||
valueParameterTypes = originalDescriptor.extensionReceiverTypeOrEmpty() +
|
|
||||||
call.valueArguments.map { valueArgumentToParameterType[it] },
|
|
||||||
hasExtensionReceiver = originalDescriptor.extensionReceiverParameter != null,
|
|
||||||
hasVarargs = originalDescriptor.valueParameters.any { it.varargElementType != null },
|
|
||||||
numDefaults = numDefaults,
|
|
||||||
isPlatform = originalDescriptor is MemberDescriptor && originalDescriptor.isPlatform)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createOverloadingConflictResolver(
|
fun createOverloadingConflictResolver(
|
||||||
@@ -71,4 +62,4 @@ fun createOverloadingConflictResolver(
|
|||||||
MutableResolvedCall<*>::createFlatSignature,
|
MutableResolvedCall<*>::createFlatSignature,
|
||||||
{ (it as? VariableAsFunctionResolvedCallImpl)?.variableCall },
|
{ (it as? VariableAsFunctionResolvedCallImpl)?.variableCall },
|
||||||
{ DescriptorToSourceUtils.descriptorToDeclaration(it) != null}
|
{ DescriptorToSourceUtils.descriptorToDeclaration(it) != null}
|
||||||
)
|
)
|
||||||
|
|||||||
+24
-13
@@ -36,7 +36,7 @@ interface TypeSpecificityComparator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FlatSignature<out T>(
|
class FlatSignature<out T> private constructor(
|
||||||
val origin: T,
|
val origin: T,
|
||||||
val typeParameters: Collection<TypeParameterDescriptor>,
|
val typeParameters: Collection<TypeParameterDescriptor>,
|
||||||
val valueParameterTypes: List<KotlinType?>,
|
val valueParameterTypes: List<KotlinType?>,
|
||||||
@@ -48,20 +48,31 @@ class FlatSignature<out T>(
|
|||||||
val isGeneric = typeParameters.isNotEmpty()
|
val isGeneric = typeParameters.isNotEmpty()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun <D : CallableDescriptor> createFromCallableDescriptor(descriptor: D): FlatSignature<D> =
|
fun <T> create(
|
||||||
FlatSignature(descriptor,
|
origin: T,
|
||||||
descriptor.typeParameters,
|
descriptor: CallableDescriptor,
|
||||||
valueParameterTypes = descriptor.extensionReceiverTypeOrEmpty() + descriptor.valueParameters.map { it.argumentValueType },
|
numDefaults: Int,
|
||||||
hasExtensionReceiver = descriptor.extensionReceiverParameter != null,
|
parameterTypes: List<KotlinType?>
|
||||||
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
|
): FlatSignature<T> {
|
||||||
numDefaults = 0,
|
val extensionReceiverType = descriptor.extensionReceiverParameter?.type
|
||||||
isPlatform = descriptor is MemberDescriptor && descriptor.isPlatform)
|
|
||||||
|
|
||||||
val ValueParameterDescriptor.argumentValueType: KotlinType
|
return FlatSignature(origin,
|
||||||
get() = varargElementType ?: type
|
descriptor.typeParameters,
|
||||||
|
valueParameterTypes =
|
||||||
|
extensionReceiverType.singletonOrEmptyList() + parameterTypes,
|
||||||
|
hasExtensionReceiver = extensionReceiverType != null,
|
||||||
|
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
|
||||||
|
numDefaults = numDefaults,
|
||||||
|
isPlatform = descriptor is MemberDescriptor && descriptor.isPlatform
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun CallableDescriptor.extensionReceiverTypeOrEmpty() =
|
fun <D : CallableDescriptor> createFromCallableDescriptor(
|
||||||
extensionReceiverParameter?.type.singletonOrEmptyList()
|
descriptor: D
|
||||||
|
): FlatSignature<D> =
|
||||||
|
create(descriptor, descriptor, numDefaults = 0, parameterTypes = descriptor.valueParameters.map { it.argumentValueType })
|
||||||
|
|
||||||
|
val ValueParameterDescriptor.argumentValueType get() = varargElementType ?: type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user