From 9283daccb6110481f7ef8e8dd4ab4e523cd7067e Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 22 Dec 2014 19:13:21 +0300 Subject: [PATCH] Debugger: fix evaluate expression for traits --- .../evaluate/KotlinEvaluationBuilder.kt | 6 ++++- .../tinyApp/outs/extractThisInTrait.out | 9 ++++++++ .../singleBreakpoint/extractThisInTrait.kt | 23 +++++++++++++++++++ ...KotlinEvaluateExpressionTestGenerated.java | 6 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 idea/testData/debugger/tinyApp/outs/extractThisInTrait.out create mode 100644 idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/extractThisInTrait.kt diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt index 7b551149ebe..6045efc16fd 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -396,6 +396,9 @@ fun EvaluationContextImpl.findLocalVariable(name: String, asmType: Type?, checkT val this0 = findLocalVariable(AsmUtil.CAPTURED_THIS_FIELD, asmType, checkType = true, failIfNotFound = false) if (this0 != null) return this0 + + val `$this` = findLocalVariable("\$this", asmType, checkType = false, failIfNotFound = false) + if (`$this` != null) return `$this` } else -> { val eval4j = JDIEval(frame.virtualMachine()!!, @@ -442,7 +445,8 @@ fun EvaluationContextImpl.findLocalVariable(name: String, asmType: Type?, checkT fun findCapturedVal(name: String): Value? { var result: Value? = null - var thisObj: Value? = frame.thisObject().asValue() + val thisObject = frame.thisObject() ?: return null + var thisObj: Value? = thisObject.asValue() while (result == null && thisObj != null) { result = eval4j.getField(thisObj!!, name, asmType, checkType) diff --git a/idea/testData/debugger/tinyApp/outs/extractThisInTrait.out b/idea/testData/debugger/tinyApp/outs/extractThisInTrait.out new file mode 100644 index 00000000000..c6e9b8aebee --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/extractThisInTrait.out @@ -0,0 +1,9 @@ +LineBreakpoint created at extractThisInTrait.kt:10 +!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! extractThisInTrait.ExtractThisInTraitPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +extractThisInTrait.kt:10 +Compile bytecode for prop +Compile bytecode for this.prop +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/extractThisInTrait.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/extractThisInTrait.kt new file mode 100644 index 00000000000..ab302df9776 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/extractThisInTrait.kt @@ -0,0 +1,23 @@ +package extractThisInTrait + +fun main(args: Array) { + TImpl().foo() +} + +trait T { + fun foo() { + //Breakpoint! + val a = 1 + } + + val prop: Int + get() = 1 +} + +class TImpl(): T + +// EXPRESSION: prop +// RESULT: 1: I + +// EXPRESSION: this.prop +// RESULT: 1: I \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java index 586fece8cc2..bdd9a918ab7 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java @@ -118,6 +118,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat doSingleBreakpointTest(fileName); } + @TestMetadata("extractThisInTrait.kt") + public void testExtractThisInTrait() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/extractThisInTrait.kt"); + doSingleBreakpointTest(fileName); + } + @TestMetadata("extractVariablesFromCall.kt") public void testExtractVariablesFromCall() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/extractVariablesFromCall.kt");