From 992cdd9fe2d89c6ade1889ee5501fccc08ef032b Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 19 Nov 2014 17:26:38 +0300 Subject: [PATCH] Partial body resolve: processing of standard "error" function --- .../lang/resolve/lazy/PartialBodyResolveFilter.kt | 12 ++++++++++++ .../resolve/partialBodyResolve/IfNotIsError.dump | 2 +- .../{IfNotIsError.kt.todo => IfNotIsError.kt} | 0 .../partialBodyResolve/IfNotIsErrorQualifier.dump | 2 ++ .../partialBodyResolve/IfNotIsErrorQualifier.kt | 6 ++++++ .../completion/JvmSmartCompletionTestGenerated.java | 1 + .../jet/resolve/PartialBodyResolveTestGenerated.java | 12 ++++++++++++ 7 files changed, 34 insertions(+), 1 deletion(-) rename idea/testData/resolve/partialBodyResolve/{IfNotIsError.kt.todo => IfNotIsError.kt} (100%) create mode 100644 idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump create mode 100644 idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.kt diff --git a/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt b/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt index 2345b424bee..1d9bca9220c 100644 --- a/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt +++ b/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt @@ -278,6 +278,14 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J } } + override fun visitCallExpression(expression: JetCallExpression) { + val name = (expression.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedName() + if (name != null && name in possiblyNothingFunctionNames) { + result.add(expression) + } + super.visitCallExpression(expression) + } + override fun visitBinaryExpression(expression: JetBinaryExpression) { if (expression.getOperationToken() == JetTokens.ELVIS) { // do not search exits after "?:" @@ -360,5 +368,9 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J private fun JetBlockExpression.lastStatement(): JetExpression? = getLastChild().siblings(forward = false).filterIsInstance().firstOrNull() + + class object { + private val possiblyNothingFunctionNames = setOf("error") // currently hard-coded + } } diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump index 18ac239473c..7578f928cce 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump @@ -1,2 +1,2 @@ -Resolve target: val kotlin.String.size: kotlin.Int +Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsError.kt.todo b/idea/testData/resolve/partialBodyResolve/IfNotIsError.kt similarity index 100% rename from idea/testData/resolve/partialBodyResolve/IfNotIsError.kt.todo rename to idea/testData/resolve/partialBodyResolve/IfNotIsError.kt diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump new file mode 100644 index 00000000000..7578f928cce --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump @@ -0,0 +1,2 @@ +Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.kt b/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.kt new file mode 100644 index 00000000000..ad78bfaaeec --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.kt @@ -0,0 +1,6 @@ +fun foo(p: Any) { + if (p !is String) { + kotlin.error("Not String") + } + println(p.size) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java index 4a2a9616952..4881c0800bb 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.completion; import com.intellij.testFramework.TestDataPath; import org.jetbrains.jet.JUnit3RunnerWithInners; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; import org.junit.runner.RunWith; diff --git a/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java b/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java index 4d2e32017fe..c4377be1d4d 100644 --- a/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java @@ -95,6 +95,18 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT doTest(fileName); } + @TestMetadata("IfNotIsError.kt") + public void testIfNotIsError() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/IfNotIsError.kt"); + doTest(fileName); + } + + @TestMetadata("IfNotIsErrorQualifier.kt") + public void testIfNotIsErrorQualifier() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.kt"); + doTest(fileName); + } + @TestMetadata("IfNotIsReturn.kt") public void testIfNotIsReturn() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/IfNotIsReturn.kt");