Evaluator: Support 'field' variable evaluation for top-level properties

This commit is contained in:
Yan Zhulanow
2019-02-19 22:54:41 +03:00
parent 81f4e2fb3b
commit 632b9ac38c
4 changed files with 34 additions and 3 deletions
@@ -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? {
@@ -0,0 +1,12 @@
package staticField
fun main() {
x
}
val x: String = "x"
//Breakpoint!
get() = "foo" + field
// EXPRESSION: field
// RESULT: "x": Ljava/lang/String;
@@ -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
@@ -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");