Evaluate expression shouldn't be applicable for class name of Java class in static call
#KT-7261 Fixed
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(i: Int) {
|
||||
<caret>O.foo()
|
||||
}
|
||||
|
||||
class O {
|
||||
companion object {
|
||||
fun foo() {}
|
||||
}
|
||||
}
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(i: Int) {
|
||||
O.<caret>Companion.foo()
|
||||
}
|
||||
|
||||
class O {
|
||||
companion object {
|
||||
fun foo() {}
|
||||
}
|
||||
}
|
||||
// EXPECTED: O.Companion
|
||||
@@ -0,0 +1,12 @@
|
||||
package a
|
||||
|
||||
fun foo() {
|
||||
val klass = MyClass()
|
||||
<caret>a.MyClass()
|
||||
}
|
||||
|
||||
class MyClass {
|
||||
val bar = 1
|
||||
}
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(i: Int) {
|
||||
<caret>Integer.valueOf(1)
|
||||
}
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(i: Int) {
|
||||
<caret>O.foo()
|
||||
}
|
||||
|
||||
object O {
|
||||
fun foo() {}
|
||||
}
|
||||
// EXPECTED: O
|
||||
+3
@@ -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";
|
||||
}
|
||||
|
||||
+30
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user