CallableBuilder: Add option to suppress substitution

This commit is contained in:
Alexey Sedunov
2014-10-30 16:22:35 +03:00
parent 59e4325fc0
commit 88dcd858a6
@@ -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,8 +255,10 @@ 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>()
if (config.enableSubstitutions) {
collectSubstitutionsForReceiverTypeParameters(receiverType, substitutionMap) collectSubstitutionsForReceiverTypeParameters(receiverType, substitutionMap)
val typeArgumentsForFakeFunction = callableInfo.typeParameterInfos val typeArgumentsForFakeFunction = callableInfo.typeParameterInfos
.map { .map {
@@ -264,8 +267,12 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
typeCandidates.first().theType typeCandidates.first().theType
} }
.subtract(substitutionMap.keySet()) .subtract(substitutionMap.keySet())
val fakeFunction = createFakeFunctionDescriptor(scope, typeArgumentsForFakeFunction.size) fakeFunction = createFakeFunctionDescriptor(scope, typeArgumentsForFakeFunction.size)
collectSubstitutionsForCallableTypeParameters(fakeFunction, typeArgumentsForFakeFunction, substitutionMap) 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) }
} }