From 471b673bdde9820e00ebbcb6966c7a212e02d6ca Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 25 Mar 2016 18:08:43 +0300 Subject: [PATCH] Dropped HeuristicSignatures because there are supported by the language already --- .../kotlin/idea/core/ExpectedInfos.kt | 7 +- .../kotlin/idea/core/HeuristicSignatures.kt | 113 ------------------ 2 files changed, 1 insertion(+), 119 deletions(-) delete mode 100644 idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt index 5230d4016ca..12bfb7474e6 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt @@ -372,12 +372,7 @@ class ExpectedInfos( else { if (alreadyHasStar) return - val parameterType = if (useHeuristicSignatures) - resolutionFacade.ideService(). - correctedParameterType(descriptor, parameter) ?: parameter.type - else - parameter.type - + val parameterType = parameter.type if (isFunctionLiteralArgument) { if (parameterType.isFunctionType) { add(ExpectedInfo.createForArgument(parameterType, expectedName, null, argumentPositionData)) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt deleted file mode 100644 index 6905b02d6ff..00000000000 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.core - -import com.intellij.openapi.project.Project -import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES as BUILTIN_NAMES -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.psi.KtPsiFactory -import org.jetbrains.kotlin.resolve.BindingTraceContext -import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.TypeResolver -import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl -import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind -import org.jetbrains.kotlin.resolve.scopes.SubpackagesImportingScope -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.SubstitutionUtils -import org.jetbrains.kotlin.types.TypeConstructorSubstitution -import org.jetbrains.kotlin.types.Variance -import java.util.* - -internal class HeuristicSignatures( - private val moduleDescriptor: ModuleDescriptor, - private val project: Project, - private val typeResolver: TypeResolver -) { - fun correctedParameterType(function: FunctionDescriptor, parameter: ValueParameterDescriptor): KotlinType? { - val parameterIndex = function.valueParameters.indexOf(parameter) - assert(parameterIndex >= 0) - return correctedParameterType(function, parameterIndex) - } - - private fun correctedParameterType(function: FunctionDescriptor, parameterIndex: Int): KotlinType? { - val ownerType = function.dispatchReceiverParameter?.type ?: return null - - val superFunctions = function.overriddenDescriptors - if (superFunctions.isNotEmpty()) { - for (superFunction in superFunctions) { - val correctedType = correctedParameterType(superFunction, parameterIndex) ?: continue - val typeSubstitutor = SubstitutionUtils.buildDeepSubstitutor(ownerType) - return typeSubstitutor.safeSubstitute(correctedType, Variance.INVARIANT) - } - return null - } - else { - val ownerClass = ownerType.constructor.declarationDescriptor ?: return null - val classFqName = DescriptorUtils.getFqName(ownerClass) - if (!classFqName.isSafe) return null - val parameterTypes = signatures[classFqName.toSafe() to function.name] ?: return null - val typeStr = parameterTypes[parameterIndex] - val typeParameters = ownerClass.typeConstructor.parameters - - val type = typeFromText(typeStr, typeParameters) - - val substitutor = TypeConstructorSubstitution.create(ownerClass.typeConstructor, ownerType.arguments).buildSubstitutor() - return substitutor.substitute(type, Variance.INVARIANT) - } - } - - private fun typeFromText(text: String, typeParameters: Collection): KotlinType { - val typeRef = KtPsiFactory(project).createType(text) - val rootPackagesScope = SubpackagesImportingScope(null, moduleDescriptor, FqName.ROOT) - val scope = LexicalScopeImpl(rootPackagesScope, moduleDescriptor, false, null, LexicalScopeKind.SYNTHETIC) { - typeParameters.forEach { addClassifierDescriptor(it) } - } - val type = typeResolver.resolveType(scope, typeRef, BindingTraceContext(), false) - assert(!type.isError) { "No type resolved from '$text'" } - return type - } - - companion object { - private val signatures = HashMap, List>() - - init { - registerSignature(BUILTIN_NAMES.collection, "contains", "E") - registerSignature(BUILTIN_NAMES.collection, "containsAll", BUILTIN_NAMES.collection.asString() + "") - registerSignature(BUILTIN_NAMES.mutableCollection, "remove", "E") - registerSignature(BUILTIN_NAMES.mutableCollection, "removeAll", BUILTIN_NAMES.collection.asString() + "") - registerSignature(BUILTIN_NAMES.mutableCollection, "retainAll", BUILTIN_NAMES.collection.asString() + "") - registerSignature(BUILTIN_NAMES.list, "indexOf", "E") - registerSignature(BUILTIN_NAMES.list, "lastIndexOf", "E") - registerSignature(BUILTIN_NAMES.map, "get", "K") - registerSignature(BUILTIN_NAMES.map, "containsKey", "K") - registerSignature(BUILTIN_NAMES.map, "containsValue", "V") - registerSignature(BUILTIN_NAMES.mutableMap, "remove", "K") - } - - private fun registerSignature( - classFqName: FqName, - name: String, - vararg parameterTypes: String) { - signatures[classFqName to Name.identifier(name)] = parameterTypes.toList() - } - } -}