Smart completion: "null" when nullable value expected

This commit is contained in:
Valentin Kipyatkov
2014-04-29 19:50:37 +04:00
parent 32405e57e6
commit 3c75e9ec28
7 changed files with 25 additions and 0 deletions
@@ -4,6 +4,7 @@ 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>) {
@@ -11,5 +12,9 @@ object KeywordValues {
collection.add(LookupElementBuilder.create("true").bold())
collection.add(LookupElementBuilder.create("false").bold())
}
if (expectedInfos.any { it.`type`.isNullable() }) {
collection.add(LookupElementBuilder.create("null").bold())
}
}
}
@@ -3,3 +3,5 @@ class Foo
fun foo(p : Any){
var a : Foo? = <caret>
}
// ELEMENT: Foo
@@ -3,3 +3,5 @@ class Foo
fun foo(p : Any){
var a : Foo? = Foo()<caret>
}
// ELEMENT: Foo
@@ -6,3 +6,5 @@ fun foo(c: C?, i: Int){}
fun foo() {
foo(<caret>
}
// ELEMENT: C
@@ -6,3 +6,5 @@ fun foo(c: C?, i: Int){}
fun foo() {
foo(C()<caret>
}
// ELEMENT: C
+7
View File
@@ -0,0 +1,7 @@
fun foo(p: String?) {}
fun bar() {
foo(<caret>)
}
// EXIST: null
@@ -281,6 +281,11 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest("idea/testData/completion/smart/NotSillyAssignment.kt");
}
@TestMetadata("Null.kt")
public void testNull() throws Exception {
doTest("idea/testData/completion/smart/Null.kt");
}
@TestMetadata("NullableThis.kt")
public void testNullableThis() throws Exception {
doTest("idea/testData/completion/smart/NullableThis.kt");