CallableBuilder: Add option to suppress substitution
This commit is contained in:
+20
-13
@@ -80,7 +80,7 @@ class TypeCandidate(val theType: JetType, scope: JetScope? = null) {
|
|||||||
var renderedTypeParameters: List<RenderedTypeParameter>? = null
|
var renderedTypeParameters: List<RenderedTypeParameter>? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun render(typeParameterNameMap: Map<TypeParameterDescriptor, String>, fakeFunction: FunctionDescriptor) {
|
fun render(typeParameterNameMap: Map<TypeParameterDescriptor, String>, fakeFunction: FunctionDescriptor?) {
|
||||||
renderedType = theType.renderShort(typeParameterNameMap);
|
renderedType = theType.renderShort(typeParameterNameMap);
|
||||||
renderedTypeParameters = typeParameters.map {
|
renderedTypeParameters = typeParameters.map {
|
||||||
RenderedTypeParameter(it, it.getContainingDeclaration() == fakeFunction, typeParameterNameMap[it]!!)
|
RenderedTypeParameter(it, it.getContainingDeclaration() == fakeFunction, typeParameterNameMap[it]!!)
|
||||||
@@ -114,7 +114,8 @@ class CallableBuilderConfiguration(
|
|||||||
val callableInfos: List<CallableInfo>,
|
val callableInfos: List<CallableInfo>,
|
||||||
val originalExpression: JetExpression,
|
val originalExpression: JetExpression,
|
||||||
val currentFile: JetFile,
|
val currentFile: JetFile,
|
||||||
val currentEditor: Editor
|
val currentEditor: Editor,
|
||||||
|
val enableSubstitutions: Boolean = true
|
||||||
)
|
)
|
||||||
|
|
||||||
fun CallableBuilderConfiguration(
|
fun CallableBuilderConfiguration(
|
||||||
@@ -254,18 +255,24 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
(receiverClassDescriptor as ClassDescriptorWithResolutionScopes).getScopeForMemberDeclarationResolution()
|
(receiverClassDescriptor as ClassDescriptorWithResolutionScopes).getScopeForMemberDeclarationResolution()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fakeFunction: FunctionDescriptor?
|
||||||
// figure out type substitutions for type parameters
|
// figure out type substitutions for type parameters
|
||||||
val substitutionMap = LinkedHashMap<JetType, JetType>()
|
val substitutionMap = LinkedHashMap<JetType, JetType>()
|
||||||
collectSubstitutionsForReceiverTypeParameters(receiverType, substitutionMap)
|
if (config.enableSubstitutions) {
|
||||||
val typeArgumentsForFakeFunction = callableInfo.typeParameterInfos
|
collectSubstitutionsForReceiverTypeParameters(receiverType, substitutionMap)
|
||||||
.map {
|
val typeArgumentsForFakeFunction = callableInfo.typeParameterInfos
|
||||||
val typeCandidates = computeTypeCandidates(it)
|
.map {
|
||||||
assert (typeCandidates.size == 1, "Ambiguous type candidates for type parameter $it: $typeCandidates")
|
val typeCandidates = computeTypeCandidates(it)
|
||||||
typeCandidates.first().theType
|
assert (typeCandidates.size == 1, "Ambiguous type candidates for type parameter $it: $typeCandidates")
|
||||||
}
|
typeCandidates.first().theType
|
||||||
.subtract(substitutionMap.keySet())
|
}
|
||||||
val fakeFunction = createFakeFunctionDescriptor(scope, typeArgumentsForFakeFunction.size)
|
.subtract(substitutionMap.keySet())
|
||||||
collectSubstitutionsForCallableTypeParameters(fakeFunction, typeArgumentsForFakeFunction, substitutionMap)
|
fakeFunction = createFakeFunctionDescriptor(scope, typeArgumentsForFakeFunction.size)
|
||||||
|
collectSubstitutionsForCallableTypeParameters(fakeFunction!!, typeArgumentsForFakeFunction, substitutionMap)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fakeFunction = null
|
||||||
|
}
|
||||||
substitutions = substitutionMap.map { JetTypeSubstitution(it.key, it.value) }
|
substitutions = substitutionMap.map { JetTypeSubstitution(it.key, it.value) }
|
||||||
|
|
||||||
callableInfo.parameterInfos.forEach {
|
callableInfo.parameterInfos.forEach {
|
||||||
@@ -336,7 +343,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
private fun renderTypeCandidates(
|
private fun renderTypeCandidates(
|
||||||
typeInfo: TypeInfo,
|
typeInfo: TypeInfo,
|
||||||
typeParameterNameMap: Map<TypeParameterDescriptor, String>,
|
typeParameterNameMap: Map<TypeParameterDescriptor, String>,
|
||||||
fakeFunction: FunctionDescriptor
|
fakeFunction: FunctionDescriptor?
|
||||||
) {
|
) {
|
||||||
typeCandidates[typeInfo]?.forEach { it.render(typeParameterNameMap, fakeFunction) }
|
typeCandidates[typeInfo]?.forEach { it.render(typeParameterNameMap, fakeFunction) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user