From 2d850f41f1c434e8f5eeb7c3d209f049d0624a46 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 12 May 2014 20:48:50 +0400 Subject: [PATCH] Smart completion: fixed addition of tail chars after true, false and null --- .../jet/plugin/completion/smart/KeywordValues.kt | 14 +++++++------- idea/testData/completion/handlers/smart/True2.kt | 7 +++++++ .../completion/handlers/smart/True2.kt.after | 7 +++++++ .../SmartCompletionHandlerTestGenerated.java | 5 +++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 idea/testData/completion/handlers/smart/True2.kt create mode 100644 idea/testData/completion/handlers/smart/True2.kt.after diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/KeywordValues.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/KeywordValues.kt index 8f632538017..7d553f548bf 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/KeywordValues.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/KeywordValues.kt @@ -20,17 +20,17 @@ import com.intellij.codeInsight.lookup.LookupElement import org.jetbrains.jet.plugin.completion.ExpectedInfo import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import com.intellij.codeInsight.lookup.LookupElementBuilder -import org.jetbrains.jet.lang.types.TypeUtils object KeywordValues { public fun addToCollection(collection: MutableCollection, expectedInfos: Collection) { - if (expectedInfos.any { it.`type` == KotlinBuiltIns.getInstance().getBooleanType() }) { - collection.add(LookupElementBuilder.create("true").bold()) - collection.add(LookupElementBuilder.create("false").bold()) + val booleanInfoClassifier = { (info: ExpectedInfo) -> + if (info.`type` == KotlinBuiltIns.getInstance().getBooleanType()) ExpectedInfoClassification.MATCHES else ExpectedInfoClassification.NOT_MATCHES } + collection.addLookupElements(expectedInfos, booleanInfoClassifier, { LookupElementBuilder.create("true").bold() }) + collection.addLookupElements(expectedInfos, booleanInfoClassifier, { LookupElementBuilder.create("false").bold() }) - if (expectedInfos.any { it.`type`.isNullable() }) { - collection.add(LookupElementBuilder.create("null").bold()) - } + collection.addLookupElements(expectedInfos, + { info -> if (info.`type`.isNullable()) ExpectedInfoClassification.MATCHES else ExpectedInfoClassification.NOT_MATCHES }, + { LookupElementBuilder.create("null").bold() }) } } \ No newline at end of file diff --git a/idea/testData/completion/handlers/smart/True2.kt b/idea/testData/completion/handlers/smart/True2.kt new file mode 100644 index 00000000000..fe13081347b --- /dev/null +++ b/idea/testData/completion/handlers/smart/True2.kt @@ -0,0 +1,7 @@ +fun foo(b: Boolean){} + +fun bar() { + foo( +} + +// ELEMENT: true diff --git a/idea/testData/completion/handlers/smart/True2.kt.after b/idea/testData/completion/handlers/smart/True2.kt.after new file mode 100644 index 00000000000..de4b2f06c22 --- /dev/null +++ b/idea/testData/completion/handlers/smart/True2.kt.after @@ -0,0 +1,7 @@ +fun foo(b: Boolean){} + +fun bar() { + foo(true) +} + +// ELEMENT: true diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java index db384196ac8..8ae87d6c4da 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java @@ -396,4 +396,9 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion doTest("idea/testData/completion/handlers/smart/True.kt"); } + @TestMetadata("True2.kt") + public void testTrue2() throws Exception { + doTest("idea/testData/completion/handlers/smart/True2.kt"); + } + }