"true" and "false" in smart completion when Boolean? expected
This commit is contained in:
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
import java.util.ArrayList
|
||||
|
||||
@@ -204,7 +203,7 @@ fun returnExpressionItems(bindingContext: BindingContext, position: JetElement):
|
||||
if (returnType != null && returnType.nullability() == TypeNullability.NULLABLE) {
|
||||
result.add(createKeywordWithLabelElement("return null", null, addSpace = false))
|
||||
}
|
||||
if (returnType != null && KotlinBuiltIns.isBoolean(returnType.makeNotNullable())) {
|
||||
if (returnType != null && KotlinBuiltIns.isBooleanOrNullableBoolean(returnType)) {
|
||||
result.add(createKeywordWithLabelElement("return true", null, addSpace = false))
|
||||
result.add(createKeywordWithLabelElement("return false", null, addSpace = false))
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,13 +20,13 @@ import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.codeInsight.lookup.LookupElementDecorator
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.completion.COMPARISON_TOKENS
|
||||
import org.jetbrains.kotlin.idea.completion.ExpectedInfo
|
||||
import org.jetbrains.kotlin.idea.completion.fuzzyType
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean
|
||||
|
||||
object KeywordValues {
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>, expectedInfos: Collection<ExpectedInfo>, expressionWithType: JetExpression) {
|
||||
@@ -52,7 +52,7 @@ object KeywordValues {
|
||||
|
||||
if (!skipTrueFalse) {
|
||||
val booleanInfoClassifier = { info: ExpectedInfo ->
|
||||
if (info.fuzzyType?.type == KotlinBuiltIns.getInstance().getBooleanType()) ExpectedInfoClassification.match(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.noMatch
|
||||
if (info.fuzzyType?.type?.isBooleanOrNullableBoolean() ?: false) ExpectedInfoClassification.match(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.noMatch
|
||||
}
|
||||
collection.addLookupElements(null, expectedInfos, booleanInfoClassifier) { LookupElementBuilder.create("true").bold().assignSmartCompletionPriority(SmartCompletionItemPriority.TRUE) }
|
||||
collection.addLookupElements(null, expectedInfos, booleanInfoClassifier) { LookupElementBuilder.create("false").bold().assignSmartCompletionPriority(SmartCompletionItemPriority.FALSE) }
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(): Boolean? = <caret>
|
||||
|
||||
// EXIST: { itemText: "true", attributes: "bold" }
|
||||
// EXIST: { itemText: "false", attributes: "bold" }
|
||||
// EXIST: { itemText: "null", attributes: "bold" }
|
||||
+6
@@ -359,6 +359,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NullableBooleanExpected.kt")
|
||||
public void testNullableBooleanExpected() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/NullableBooleanExpected.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Object.kt")
|
||||
public void testObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/Object.kt");
|
||||
|
||||
Reference in New Issue
Block a user