Smart completion: fixed addition of tail chars after true, false and null

This commit is contained in:
Valentin Kipyatkov
2014-05-12 20:48:50 +04:00
parent 0e86e628a3
commit 2d850f41f1
4 changed files with 26 additions and 7 deletions
@@ -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<LookupElement>, expectedInfos: Collection<ExpectedInfo>) {
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() })
}
}
@@ -0,0 +1,7 @@
fun foo(b: Boolean){}
fun bar() {
foo(<caret>
}
// ELEMENT: true
@@ -0,0 +1,7 @@
fun foo(b: Boolean){}
fun bar() {
foo(true)<caret>
}
// ELEMENT: true
@@ -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");
}
}