From 796a2b6e7c780deaaf29cb434d8b7e1d4febc64c Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 3 Dec 2014 21:15:13 +0300 Subject: [PATCH] Code refactoring --- .../plugin/completion/smart/SmartCompletion.kt | 16 +--------------- .../jet/plugin/completion/smart/Utils.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt index 822b53a99d7..b486e7d97cf 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt @@ -128,21 +128,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression, val result = ArrayList() val types = descriptor.fuzzyTypes(smartCastTypes) - val classifier = { (expectedInfo: ExpectedInfo) -> - val substitutor = types.stream().map { it.checkIsSubtypeOf(expectedInfo.type) }.firstOrNull() - if (substitutor != null) { - ExpectedInfoClassification.matches(substitutor) - } - else { - val substitutor2 = types.stream().map { it.makeNotNullable().checkIsSubtypeOf(expectedInfo.type) }.firstOrNull() - if (substitutor2 != null) { - ExpectedInfoClassification.matchesIfNotNullable(substitutor2) - } - else { - ExpectedInfoClassification.notMatches - } - } - } + val classifier = { (expectedInfo: ExpectedInfo) -> types.classifyExpectedInfo(expectedInfo) } result.addLookupElements(descriptor, expectedInfos, classifier) { descriptor -> lookupElementFactory.createLookupElement(descriptor, resolutionFacade, bindingContext, true) } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/Utils.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/Utils.kt index ce720a40e4b..e6d6b49e48e 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/Utils.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/Utils.kt @@ -110,14 +110,15 @@ class ExpectedInfoClassification private(val substitutor: TypeSubstitutor?, val } } -fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClassification { - val substitutor = checkIsSubtypeOf(expectedInfo.type) +fun Collection.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClassification { + val stream = stream() + val substitutor = stream.map { it.checkIsSubtypeOf(expectedInfo.type) }.firstOrNull() if (substitutor != null) { return ExpectedInfoClassification.matches(substitutor) } - if (isNullable()) { - val substitutor2 = makeNotNullable().checkIsSubtypeOf(expectedInfo.type) + if (stream.any { it.isNullable() }) { + val substitutor2 = stream.map { it.makeNotNullable().checkIsSubtypeOf(expectedInfo.type) }.firstOrNull() if (substitutor2 != null) { return ExpectedInfoClassification.matchesIfNotNullable(substitutor2) } @@ -126,6 +127,8 @@ fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo): ExpectedInfoClas return ExpectedInfoClassification.notMatches } +fun FuzzyType.classifyExpectedInfo(expectedInfo: ExpectedInfo) = listOf(this).classifyExpectedInfo(expectedInfo) + fun MutableCollection.addLookupElements( descriptor: TDescriptor, expectedInfos: Collection,