From f29efc2ca200cf898e2481f54f25eb0fc63cddc7 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Fri, 29 Jan 2016 15:05:47 +0300 Subject: [PATCH] Evaluate expression shouldn't be applicable for class name of Java class in static call #KT-7261 Fixed --- .../idea/debugger/KotlinEditorTextProvider.kt | 14 ++++++++- .../selectExpression/companionObjectCall.kt | 10 +++++++ .../selectExpression/companionObjectCall2.kt | 10 +++++++ .../selectExpression/fullyQualified.kt | 12 ++++++++ .../selectExpression/javaStaticMehtodCall.kt | 5 ++++ .../selectExpression/objectMethodCall.kt | 8 +++++ ...AbstractSelectExpressionForDebuggerTest.kt | 3 ++ ...ectExpressionForDebuggerTestGenerated.java | 30 +++++++++++++++++++ 8 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 idea/testData/debugger/selectExpression/companionObjectCall.kt create mode 100644 idea/testData/debugger/selectExpression/companionObjectCall2.kt create mode 100644 idea/testData/debugger/selectExpression/fullyQualified.kt create mode 100644 idea/testData/debugger/selectExpression/javaStaticMehtodCall.kt create mode 100644 idea/testData/debugger/selectExpression/objectMethodCall.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinEditorTextProvider.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinEditorTextProvider.kt index 9a7ea495c15..2a14449a6d0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinEditorTextProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinEditorTextProvider.kt @@ -25,7 +25,10 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.idea.KotlinFileType +import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorUtils class KotlinEditorTextProvider : EditorTextProvider { override fun getEditorText(elementAtCaret: PsiElement): TextWithImports? { @@ -109,7 +112,16 @@ class KotlinEditorTextProvider : EditorTextProvider { return when { newExpression is KtExpression -> newExpression - jetElement is KtSimpleNameExpression -> jetElement + jetElement is KtSimpleNameExpression -> { + val context = jetElement.analyzeAndGetResult().bindingContext + val qualifier = context[BindingContext.QUALIFIER, jetElement] + if (qualifier != null && !DescriptorUtils.isObject(qualifier.descriptor)) { + null + } + else { + jetElement + } + } else -> null } diff --git a/idea/testData/debugger/selectExpression/companionObjectCall.kt b/idea/testData/debugger/selectExpression/companionObjectCall.kt new file mode 100644 index 00000000000..ca1dd2f769c --- /dev/null +++ b/idea/testData/debugger/selectExpression/companionObjectCall.kt @@ -0,0 +1,10 @@ +fun foo(i: Int) { + O.foo() +} + +class O { + companion object { + fun foo() {} + } +} +// EXPECTED: null \ No newline at end of file diff --git a/idea/testData/debugger/selectExpression/companionObjectCall2.kt b/idea/testData/debugger/selectExpression/companionObjectCall2.kt new file mode 100644 index 00000000000..423065a0231 --- /dev/null +++ b/idea/testData/debugger/selectExpression/companionObjectCall2.kt @@ -0,0 +1,10 @@ +fun foo(i: Int) { + O.Companion.foo() +} + +class O { + companion object { + fun foo() {} + } +} +// EXPECTED: O.Companion \ No newline at end of file diff --git a/idea/testData/debugger/selectExpression/fullyQualified.kt b/idea/testData/debugger/selectExpression/fullyQualified.kt new file mode 100644 index 00000000000..5df33c40b14 --- /dev/null +++ b/idea/testData/debugger/selectExpression/fullyQualified.kt @@ -0,0 +1,12 @@ +package a + +fun foo() { + val klass = MyClass() + a.MyClass() +} + +class MyClass { + val bar = 1 +} + +// EXPECTED: null \ No newline at end of file diff --git a/idea/testData/debugger/selectExpression/javaStaticMehtodCall.kt b/idea/testData/debugger/selectExpression/javaStaticMehtodCall.kt new file mode 100644 index 00000000000..0b8370f4c13 --- /dev/null +++ b/idea/testData/debugger/selectExpression/javaStaticMehtodCall.kt @@ -0,0 +1,5 @@ +fun foo(i: Int) { + Integer.valueOf(1) +} + +// EXPECTED: null \ No newline at end of file diff --git a/idea/testData/debugger/selectExpression/objectMethodCall.kt b/idea/testData/debugger/selectExpression/objectMethodCall.kt new file mode 100644 index 00000000000..f0918092313 --- /dev/null +++ b/idea/testData/debugger/selectExpression/objectMethodCall.kt @@ -0,0 +1,8 @@ +fun foo(i: Int) { + O.foo() +} + +object O { + fun foo() {} +} +// EXPECTED: O \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt index d303c2e9b32..b465446ed78 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.debugger.evaluate import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.debugger.KotlinEditorTextProvider +import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.junit.Assert @@ -47,5 +48,7 @@ abstract class AbstractSelectExpressionForDebuggerTest : LightCodeInsightFixture Assert.assertEquals("Another expression should be selected", expected, actualResult) } + override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE + override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/debugger/selectExpression"; } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/SelectExpressionForDebuggerTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/SelectExpressionForDebuggerTestGenerated.java index f0f10934737..64c16b7f93d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/SelectExpressionForDebuggerTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/SelectExpressionForDebuggerTestGenerated.java @@ -55,6 +55,18 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr doTest(fileName); } + @TestMetadata("companionObjectCall.kt") + public void testCompanionObjectCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/companionObjectCall.kt"); + doTest(fileName); + } + + @TestMetadata("companionObjectCall2.kt") + public void testCompanionObjectCall2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/companionObjectCall2.kt"); + doTest(fileName); + } + @TestMetadata("expressionInPropertyInitializer.kt") public void testExpressionInPropertyInitializer() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/expressionInPropertyInitializer.kt"); @@ -67,6 +79,12 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr doTest(fileName); } + @TestMetadata("fullyQualified.kt") + public void testFullyQualified() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/fullyQualified.kt"); + doTest(fileName); + } + @TestMetadata("funArgument.kt") public void testFunArgument() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/funArgument.kt"); @@ -109,6 +127,12 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr doTest(fileName); } + @TestMetadata("javaStaticMehtodCall.kt") + public void testJavaStaticMehtodCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/javaStaticMehtodCall.kt"); + doTest(fileName); + } + @TestMetadata("keyword.kt") public void testKeyword() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/keyword.kt"); @@ -127,6 +151,12 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr doTest(fileName); } + @TestMetadata("objectMethodCall.kt") + public void testObjectMethodCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/objectMethodCall.kt"); + doTest(fileName); + } + @TestMetadata("package.kt") public void testPackage() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/selectExpression/package.kt");