EA-219152 (partially): Support KClass 'unboxing' in debugger

KClass can be 'unboxed' to a plain Java class. Debugger should be aware of this.
Unfortunately, this commit is not enough to fully support this scenario, as it's impossible to invoke KClass methods/extension on java.lang.Class instance. There should be an additional diagnostic that will forbid such calls.
This commit is contained in:
Yan Zhulanow
2020-01-17 19:52:30 +09:00
parent a7071344f5
commit 7490c229ac
4 changed files with 43 additions and 0 deletions
@@ -50,6 +50,11 @@ class EvaluatorValueConverter(val context: ExecutionContext) {
return true
}
if (requestedType == AsmTypes.K_CLASS_TYPE && actualType == AsmTypes.JAVA_CLASS_TYPE) {
// KClass can be represented as a Java class for simpler cases. See BoxingInterpreter.isJavaLangClassBoxing().
return true
}
val unwrappedActualType = unwrap(actualType)
val unwrappedRequestedType = unwrap(requestedType)
return unwrappedActualType == unwrappedRequestedType
@@ -260,6 +260,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/javaStaticMethods.kt");
}
@TestMetadata("kClass.kt")
public void testKClass() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kClass.kt");
}
@TestMetadata("kt12206BasePropertyWithoutBackingField.kt")
public void testKt12206BasePropertyWithoutBackingField() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kt12206BasePropertyWithoutBackingField.kt");
@@ -0,0 +1,23 @@
package test
class Foo
fun main() {
val cls = Foo::class
val cls2 = Foo::class
val cls3 = Foo::class.java
//Breakpoint!
foo(cls2)
}
private fun foo(a: Any?) {}
// EXPRESSION: cls
// RESULT: instance of java.lang.Class(reflected class=test.Foo, id=ID): Ljava/lang/Class;
// EXPRESSION: cls2
// RESULT: instance of kotlin.jvm.internal.ClassReference(id=ID): Lkotlin/jvm/internal/ClassReference;
// EXPRESSION: cls3
// RESULT: instance of java.lang.Class(reflected class=test.Foo, id=ID): Ljava/lang/Class;
@@ -0,0 +1,10 @@
LineBreakpoint created at kClass.kt:11
Run Java
Connected to the target VM
kClass.kt:11
Compile bytecode for cls
Compile bytecode for cls2
Compile bytecode for cls3
Disconnected from the target VM
Process finished with exit code 0