From 632b9ac38c4701e0fe4dbee40f2ef91af11c45aa Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 19 Feb 2019 22:54:41 +0300 Subject: [PATCH] Evaluator: Support 'field' variable evaluation for top-level properties --- .../debugger/evaluate/variables/VariableFinder.kt | 12 +++++++++--- .../src/evaluate/singleBreakpoint/staticField.kt | 12 ++++++++++++ .../src/evaluate/singleBreakpoint/staticField.out | 8 ++++++++ .../KotlinEvaluateExpressionTestGenerated.java | 5 +++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.kt create mode 100644 idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.out diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt index 39052faf528..8c07f2d71e5 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt @@ -211,9 +211,15 @@ class VariableFinder private constructor(private val context: ExecutionContext, } private fun findFieldVariable(kind: VariableKind.FieldVar): Result? { - val thisObject = frameProxy.thisObject() ?: return null - val field = thisObject.referenceType().fieldByName(kind.fieldName) ?: return null - return Result(thisObject.getValue(field)) + val thisObject = frameProxy.thisObject() + if (thisObject != null) { + val field = thisObject.referenceType().fieldByName(kind.fieldName) ?: return null + return Result(thisObject.getValue(field)) + } else { + val containingType = frameProxy.safeLocation()?.declaringType() ?: return null + val field = containingType.fieldByName(kind.fieldName) ?: return null + return Result(containingType.getValue(field)) + } } private fun findLocalFunction(kind: VariableKind.LocalFunction): Result? { diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.kt new file mode 100644 index 00000000000..5c5f43830bb --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.kt @@ -0,0 +1,12 @@ +package staticField + +fun main() { + x +} + +val x: String = "x" + //Breakpoint! + get() = "foo" + field + +// EXPRESSION: field +// RESULT: "x": Ljava/lang/String; \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.out b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.out new file mode 100644 index 00000000000..f202d69cc71 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.out @@ -0,0 +1,8 @@ +LineBreakpoint created at staticField.kt:9 +Run Java +Connected to the target VM +staticField.kt:9 +Compile bytecode for field +Disconnected from the target VM + +Process finished with exit code 0 diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java index 02444a62ff4..37441363406 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java @@ -356,6 +356,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/simple.kt"); } + @TestMetadata("staticField.kt") + public void testStaticField() throws Exception { + runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/staticField.kt"); + } + @TestMetadata("stdlib.kt") public void testStdlib() throws Exception { runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/stdlib.kt");