Smart completion: "null" when nullable value expected
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user