Evaluate expression: Don't evaluate something when it is not an expression
#KT-5561 Fixed
This commit is contained in:
@@ -24,7 +24,6 @@ import com.intellij.openapi.util.Pair
|
||||
import com.intellij.debugger.engine.evaluation.TextWithImportsImpl
|
||||
import com.intellij.debugger.engine.evaluation.CodeFragmentKind
|
||||
import org.jetbrains.jet.plugin.JetFileType
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetQualifiedExpression
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
@@ -33,9 +32,11 @@ import org.jetbrains.jet.lang.psi.JetThisExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.psi.JetOperationExpression
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.lang.psi.JetExpressionCodeFragment
|
||||
import org.jetbrains.jet.lang.psi.JetSuperExpression
|
||||
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||
import org.jetbrains.jet.lang.psi.JetUserType
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective
|
||||
import org.jetbrains.jet.lang.psi.JetPackageDirective
|
||||
|
||||
class KotlinEditorTextProvider : EditorTextProvider {
|
||||
override fun getEditorText(elementAtCaret: PsiElement): TextWithImports? {
|
||||
@@ -51,6 +52,10 @@ class KotlinEditorTextProvider : EditorTextProvider {
|
||||
|
||||
class object {
|
||||
fun findExpressionInner(element: PsiElement): JetExpression? {
|
||||
if (PsiTreeUtil.getParentOfType(element, javaClass<JetUserType>(), javaClass<JetImportDirective>(), javaClass<JetPackageDirective>()) != null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val jetElement = PsiTreeUtil.getParentOfType(element, javaClass<JetElement>())
|
||||
if (jetElement == null) return null
|
||||
|
||||
@@ -84,13 +89,12 @@ class KotlinEditorTextProvider : EditorTextProvider {
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (newExpression is JetExpression) return newExpression
|
||||
|
||||
if (jetElement is JetSimpleNameExpression) {
|
||||
return jetElement
|
||||
return when {
|
||||
newExpression is JetExpression -> newExpression
|
||||
jetElement is JetSimpleNameExpression -> jetElement
|
||||
else -> null
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<caret>Ann fun foo() { }
|
||||
|
||||
annotation class Ann
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,3 @@
|
||||
import java.<caret>util.List
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo.<caret>util
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(): <caret>Int { }
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(): List<<caret>Int> { }
|
||||
|
||||
// EXPECTED: null
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(): java<caret>.lang.Integer { }
|
||||
|
||||
// EXPECTED: null
|
||||
+30
@@ -36,6 +36,11 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/debugger/selectExpression"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotation.kt")
|
||||
public void testAnnotation() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/annotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("binaryExpression.kt")
|
||||
public void testBinaryExpression() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/binaryExpression.kt");
|
||||
@@ -71,6 +76,11 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr
|
||||
doTest("idea/testData/debugger/selectExpression/getConvention.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("imports.kt")
|
||||
public void testImports() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/imports.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("infixCall.kt")
|
||||
public void testInfixCall() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/infixCall.kt");
|
||||
@@ -96,6 +106,11 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr
|
||||
doTest("idea/testData/debugger/selectExpression/modifier.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("package.kt")
|
||||
public void testPackage() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/package.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("param.kt")
|
||||
public void testParam() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/param.kt");
|
||||
@@ -146,4 +161,19 @@ public class SelectExpressionForDebuggerTestGenerated extends AbstractSelectExpr
|
||||
doTest("idea/testData/debugger/selectExpression/unaryExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("userType.kt")
|
||||
public void testUserType() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/userType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("userTypeGeneric.kt")
|
||||
public void testUserTypeGeneric() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/userTypeGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("userTypeQualified.kt")
|
||||
public void testUserTypeQualified() throws Exception {
|
||||
doTest("idea/testData/debugger/selectExpression/userTypeQualified.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user