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