From 32dbed602a738d1f4d1aaf5f86b2e7658eab8c8c Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 23 Jul 2014 14:58:15 +0200 Subject: [PATCH] KT-4913 Smart completion should work after '!' #KT-4913 Fixed --- .../org/jetbrains/jet/plugin/completion/ExpectedInfos.kt | 8 ++++++++ idea/testData/completion/smart/AfterExclSign.kt | 6 ++++++ .../jet/completion/JvmSmartCompletionTestGenerated.java | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 idea/testData/completion/smart/AfterExclSign.kt diff --git a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt index 217efbf0e05..e81c12f2df6 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt @@ -56,6 +56,7 @@ import org.jetbrains.jet.lang.psi.JetCallElement import org.jetbrains.jet.lang.types.TypeUtils import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace +import org.jetbrains.jet.lang.psi.JetPrefixExpression enum class Tail { COMMA @@ -74,6 +75,7 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo ?: calculateForElvis(expressionWithType) ?: calculateForBlockExpression(expressionWithType) ?: calculateForWhenEntryValue(expressionWithType) + ?: calculateForExclOperand(expressionWithType) ?: getFromBindingContext(expressionWithType) } @@ -242,6 +244,12 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo } } + private fun calculateForExclOperand(expressionWithType: JetExpression): Collection? { + val prefixExpression = expressionWithType.getParent() as? JetPrefixExpression ?: return null + if (prefixExpression.getOperationToken() != JetTokens.EXCL) return null + return listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null)) + } + private fun getFromBindingContext(expressionWithType: JetExpression): Collection? { val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType] ?: return null return listOf(ExpectedInfo(expectedType, null)) diff --git a/idea/testData/completion/smart/AfterExclSign.kt b/idea/testData/completion/smart/AfterExclSign.kt new file mode 100644 index 00000000000..2b4af5d15dd --- /dev/null +++ b/idea/testData/completion/smart/AfterExclSign.kt @@ -0,0 +1,6 @@ +fun foo(p1: Boolean, p2: String) { + if (!) +} + +// EXIST: p1 +// ABSENT: p2 diff --git a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java index e50a5c36a01..eb0e230ee24 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java @@ -32,6 +32,11 @@ import org.jetbrains.jet.completion.AbstractJvmSmartCompletionTest; @SuppressWarnings("all") @TestMetadata("idea/testData/completion/smart") public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionTest { + @TestMetadata("AfterExclSign.kt") + public void testAfterExclSign() throws Exception { + doTest("idea/testData/completion/smart/AfterExclSign.kt"); + } + public void testAllFilesPresentInSmart() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/completion/smart"), Pattern.compile("^(.+)\\.kt$"), true); }