diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index 4d0ff9d0b4e..f889abbb75c 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -33,7 +33,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoClassification +import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoMatch import org.jetbrains.kotlin.idea.completion.smart.SMART_COMPLETION_ITEM_PRIORITY_KEY import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion import org.jetbrains.kotlin.idea.completion.smart.SmartCompletionItemPriority @@ -278,13 +278,13 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, val keywordsToSkip = HashSet() val keywordValueConsumer = object : KeywordValues.Consumer { - override fun consume(lookupString: String, expectedInfoClassifier: (ExpectedInfo) -> ExpectedInfoClassification, priority: SmartCompletionItemPriority, factory: () -> LookupElement) { + override fun consume(lookupString: String, expectedInfoMatcher: (ExpectedInfo) -> ExpectedInfoMatch, priority: SmartCompletionItemPriority, factory: () -> LookupElement) { keywordsToSkip.add(lookupString) val lookupElement = factory() val matched = expectedInfos.any { - val classification = expectedInfoClassifier(it) - assert(!classification.makeNotNullable) { "Nullable keyword values not supported" } - classification.isMatch() + val match = expectedInfoMatcher(it) + assert(!match.makeNotNullable) { "Nullable keyword values not supported" } + match.isMatch() } if (matched) { lookupElement.putUserData(SmartCompletionInBasicWeigher.KEYWORD_VALUE_MATCHED_KEY, matched) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordValues.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordValues.kt index 99d9a57f891..f264bda97a3 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordValues.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordValues.kt @@ -23,9 +23,9 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference -import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoClassification +import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoMatch import org.jetbrains.kotlin.idea.completion.smart.SmartCompletionItemPriority -import org.jetbrains.kotlin.idea.completion.smart.classifyExpectedInfo +import org.jetbrains.kotlin.idea.completion.smart.matchExpectedInfo import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver import org.jetbrains.kotlin.idea.util.FuzzyType @@ -40,7 +40,7 @@ object KeywordValues { interface Consumer { fun consume( lookupString: String, - expectedInfoClassifier: (ExpectedInfo) -> ExpectedInfoClassification, + expectedInfoMatcher: (ExpectedInfo) -> ExpectedInfoMatch, priority: SmartCompletionItemPriority, factory: () -> LookupElement) } @@ -54,29 +54,29 @@ object KeywordValues { isJvmModule: Boolean ) { if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { - val booleanInfoClassifier = classifier@ { info: ExpectedInfo -> + val booleanInfoMatcher = matcher@ { info: ExpectedInfo -> // no sense in true or false as when entry - if (info.additionalData is WhenEntryAdditionalData) return@classifier ExpectedInfoClassification.noMatch + if (info.additionalData is WhenEntryAdditionalData) return@matcher ExpectedInfoMatch.noMatch if (info.fuzzyType?.type?.isBooleanOrNullableBoolean() ?: false) - ExpectedInfoClassification.match(TypeSubstitutor.EMPTY) + ExpectedInfoMatch.match(TypeSubstitutor.EMPTY) else - ExpectedInfoClassification.noMatch + ExpectedInfoMatch.noMatch } - consumer.consume("true", booleanInfoClassifier, SmartCompletionItemPriority.TRUE) { + consumer.consume("true", booleanInfoMatcher, SmartCompletionItemPriority.TRUE) { LookupElementBuilder.create(KeywordLookupObject(), "true").bold() } - consumer.consume("false", booleanInfoClassifier, SmartCompletionItemPriority.FALSE) { + consumer.consume("false", booleanInfoMatcher, SmartCompletionItemPriority.FALSE) { LookupElementBuilder.create(KeywordLookupObject(), "false").bold() } - val nullClassifier = { info: ExpectedInfo -> + val nullMatcher = { info: ExpectedInfo -> if (info.fuzzyType != null && info.fuzzyType!!.type.isMarkedNullable()) - ExpectedInfoClassification.match(TypeSubstitutor.EMPTY) + ExpectedInfoMatch.match(TypeSubstitutor.EMPTY) else - ExpectedInfoClassification.noMatch + ExpectedInfoMatch.noMatch } - consumer.consume("null", nullClassifier, SmartCompletionItemPriority.NULL) { + consumer.consume("null", nullMatcher, SmartCompletionItemPriority.NULL) { LookupElementBuilder.create(KeywordLookupObject(), "null").bold() } } @@ -87,8 +87,8 @@ object KeywordValues { val kClassDescriptor = resolutionFacade.getFrontendService(ReflectionTypes::class.java).kClass val classLiteralType = JetTypeImpl.create(Annotations.EMPTY, kClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType))) val kClassTypes = listOf(FuzzyType(classLiteralType, emptyList())) - val kClassClassifier = { info: ExpectedInfo -> kClassTypes.classifyExpectedInfo(info) } - consumer.consume("class", kClassClassifier, SmartCompletionItemPriority.CLASS_LITERAL) { + val kClassMatcher = { info: ExpectedInfo -> kClassTypes.matchExpectedInfo(info) } + consumer.consume("class", kClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) { LookupElementBuilder.create(KeywordLookupObject(), "class").bold() } @@ -99,8 +99,8 @@ object KeywordValues { if (javaLangClassDescriptor != null) { val javaLangClassType = JetTypeImpl.create(Annotations.EMPTY, javaLangClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType))) val javaClassTypes = listOf(FuzzyType(javaLangClassType, emptyList())) - val javaClassClassifier = { info: ExpectedInfo -> javaClassTypes.classifyExpectedInfo(info) } - consumer.consume("class", javaClassClassifier, SmartCompletionItemPriority.CLASS_LITERAL) { + val javaClassMatcher = { info: ExpectedInfo -> javaClassTypes.matchExpectedInfo(info) } + consumer.consume("class", javaClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) { LookupElementBuilder.create(KeywordLookupObject(), "class.java") .withPresentableText("class") .withTailText(".java") diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt index 53e0b294b44..8b125378db1 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt @@ -233,18 +233,18 @@ class SmartCompletionInBasicWeigher( if (fuzzyTypes.isEmpty()) return NO_MATCH_WEIGHT - val classified: Collection> = expectedInfos.map { it to fuzzyTypes.classifyExpectedInfo(it) } - if (classified.all { it.second == ExpectedInfoClassification.noMatch }) return NO_MATCH_WEIGHT + val matched: Collection> = expectedInfos.map { it to fuzzyTypes.matchExpectedInfo(it) } + if (matched.all { it.second == ExpectedInfoMatch.noMatch }) return NO_MATCH_WEIGHT val nameSimilarity = if (name != null) { - val matchingInfos = classified.filter { it.second != ExpectedInfoClassification.noMatch }.map { it.first } + val matchingInfos = matched.filter { it.second != ExpectedInfoMatch.noMatch }.map { it.first } calcNameSimilarity(name.asString(), matchingInfos) } else { 0 } - return if (classified.any { it.second.isMatch() }) + return if (matched.any { it.second.isMatch() }) fullMatchWeight(nameSimilarity) else ifNotNullMatchWeight(nameSimilarity) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt index 127be417c8c..8f924eabc22 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt @@ -155,9 +155,9 @@ class SmartCompletion( val result = SmartList() val types = descriptor.fuzzyTypesForSmartCompletion(smartCastCalculator, callType, resolutionFacade) - val infoClassifier = { expectedInfo: ExpectedInfo -> types.classifyExpectedInfo(expectedInfo) } + val infoMatcher = { expectedInfo: ExpectedInfo -> types.matchExpectedInfo(expectedInfo) } - result.addLookupElements(descriptor, expectedInfos, infoClassifier, noNameSimilarityForReturnItself = callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { descriptor -> + result.addLookupElements(descriptor, expectedInfos, infoMatcher, noNameSimilarityForReturnItself = callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { descriptor -> lookupElementFactory.createLookupElementsInSmartCompletion(descriptor, bindingContext, true) } @@ -180,8 +180,8 @@ class SmartCompletion( if (!forBasicCompletion) { // basic completion adds keyword values on its own val keywordValueConsumer = object : KeywordValues.Consumer { - override fun consume(lookupString: String, expectedInfoClassifier: (ExpectedInfo) -> ExpectedInfoClassification, priority: SmartCompletionItemPriority, factory: () -> LookupElement) { - items.addLookupElements(null, expectedInfos, expectedInfoClassifier) { + override fun consume(lookupString: String, expectedInfoMatcher: (ExpectedInfo) -> ExpectedInfoMatch, priority: SmartCompletionItemPriority, factory: () -> LookupElement) { + items.addLookupElements(null, expectedInfos, expectedInfoMatcher) { val lookupElement = factory() lookupElement.putUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY, priority) listOf(lookupElement) @@ -266,8 +266,8 @@ class SmartCompletion( val items = thisExpressionItems(bindingContext, place, prefixMatcher.getPrefix(), resolutionFacade) for (item in items) { val types = smartCastCalculator.types(item.receiverParameter).map { FuzzyType(it, emptyList()) } - val classifier = { expectedInfo: ExpectedInfo -> types.classifyExpectedInfo(expectedInfo) } - addLookupElements(null, expectedInfos, classifier) { + val matcher = { expectedInfo: ExpectedInfo -> types.matchExpectedInfo(expectedInfo) } + addLookupElements(null, expectedInfos, matcher) { item.createLookupElement().assignSmartCompletionPriority(SmartCompletionItemPriority.THIS).singletonList() } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/StaticMembers.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/StaticMembers.kt index de61b499b5c..ba08f232747 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/StaticMembers.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/StaticMembers.kt @@ -69,19 +69,19 @@ class StaticMembers( fun processMember(descriptor: DeclarationDescriptor) { if (descriptor is DeclarationDescriptorWithVisibility && !descriptor.isVisible(scope.getContainingDeclaration(), bindingContext, context)) return - val classifier: (ExpectedInfo) -> ExpectedInfoClassification + val matcher: (ExpectedInfo) -> ExpectedInfoMatch if (descriptor is CallableDescriptor) { val returnType = descriptor.fuzzyReturnType() ?: return - classifier = { expectedInfo -> returnType.classifyExpectedInfo(expectedInfo) } + matcher = { expectedInfo -> returnType.classifyExpectedInfo(expectedInfo) } } else if (DescriptorUtils.isEnumEntry(descriptor) && !enumEntriesToSkip.contains(descriptor)) { - classifier = { ExpectedInfoClassification.match(TypeSubstitutor.EMPTY) } /* we do not need to check type of enum entry because it's taken from proper enum */ + matcher = { ExpectedInfoMatch.match(TypeSubstitutor.EMPTY) } /* we do not need to check type of enum entry because it's taken from proper enum */ } else { return } - collection.addLookupElements(descriptor, expectedInfos, classifier) { + collection.addLookupElements(descriptor, expectedInfos, matcher) { descriptor -> createLookupElements(descriptor, classDescriptor) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 24b780727b7..caf1eed42b1 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -119,7 +119,7 @@ fun LookupElement.addTailAndNameSimilarity( return lookupElement } -class ExpectedInfoClassification +class ExpectedInfoMatch private constructor( val substitutor: TypeSubstitutor?, val makeNotNullable: Boolean @@ -127,35 +127,35 @@ private constructor( fun isMatch() = substitutor != null && !makeNotNullable companion object { - val noMatch = ExpectedInfoClassification(null, false) - fun match(substitutor: TypeSubstitutor) = ExpectedInfoClassification(substitutor, false) - fun ifNotNullMatch(substitutor: TypeSubstitutor) = ExpectedInfoClassification(substitutor, true) + val noMatch = ExpectedInfoMatch(null, false) + fun match(substitutor: TypeSubstitutor) = ExpectedInfoMatch(substitutor, false) + fun ifNotNullMatch(substitutor: TypeSubstitutor) = ExpectedInfoMatch(substitutor, true) } } -fun Collection.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClassification { +fun Collection.matchExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoMatch { val sequence = asSequence() val substitutor = sequence.map { expectedInfo.matchingSubstitutor(it) }.firstOrNull() if (substitutor != null) { - return ExpectedInfoClassification.match(substitutor) + return ExpectedInfoMatch.match(substitutor) } if (sequence.any { it.nullability() == TypeNullability.NULLABLE }) { val substitutor2 = sequence.map { expectedInfo.matchingSubstitutor(it.makeNotNullable()) }.firstOrNull() if (substitutor2 != null) { - return ExpectedInfoClassification.ifNotNullMatch(substitutor2) + return ExpectedInfoMatch.ifNotNullMatch(substitutor2) } } - return ExpectedInfoClassification.noMatch + return ExpectedInfoMatch.noMatch } -fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo) = listOf(this).classifyExpectedInfo(expectedInfo) +fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo) = listOf(this).matchExpectedInfo(expectedInfo) fun MutableCollection.addLookupElements( descriptor: TDescriptor, expectedInfos: Collection, - infoClassifier: (ExpectedInfo) -> ExpectedInfoClassification, + infoMatcher: (ExpectedInfo) -> ExpectedInfoMatch, noNameSimilarityForReturnItself: Boolean = false, lookupElementFactory: (TDescriptor) -> Collection ) { @@ -170,7 +170,7 @@ fun MutableCollection.addLoo val matchedInfos = HashMap>() val makeNullableInfos = HashMap>() for (info in expectedInfos) { - val classification = infoClassifier(info) + val classification = infoMatcher(info) if (classification.substitutor != null) { @Suppress("UNCHECKED_CAST") val substitutedDescriptor = descriptor.substituteFixed(classification.substitutor)