Evaluate: Fix annotation value evaluation (#KT-23058)

This commit is contained in:
Yan Zhulanow
2018-03-15 02:17:09 +03:00
parent 4d13e38948
commit 81f3346329
4 changed files with 38 additions and 1 deletions
@@ -202,7 +202,15 @@ public class JvmCodegenUtil {
}
if (!isCallInsideSameClassAsFieldRepresentingProperty(property, context)) {
if (!isDebuggerContext(context)) {
DeclarationDescriptor propertyOwner = property.getContainingDeclaration();
boolean isAnnotationValue;
if (propertyOwner instanceof ClassDescriptor) {
isAnnotationValue = ((ClassDescriptor) propertyOwner).getKind() == ANNOTATION_CLASS;
} else {
isAnnotationValue = false;
}
if (isAnnotationValue || !isDebuggerContext(context)) {
// Unless we are evaluating expression in debugger context, only properties of the same class can be directly accessed
return false;
}
@@ -0,0 +1,15 @@
package annotationValue
annotation class Anno(val value: String)
@Anno("abc")
class SomeClass
fun main(args: Array<String>) {
//Breakpoint!
val a = 5
}
// EXPRESSION: (SomeClass::class.java.annotations[0] as Anno).value
// RESULT: "abc": Ljava/lang/String;
@@ -0,0 +1,8 @@
LineBreakpoint created at annotationValue.kt:10
Run Java
Connected to the target VM
annotationValue.kt:10
Compile bytecode for (SomeClass::class.java.annotations[0] as Anno).value
Disconnected from the target VM
Process finished with exit code 0
@@ -39,6 +39,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("annotationValue.kt")
public void testAnnotationValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.kt");
doSingleBreakpointTest(fileName);
}
@TestMetadata("anonymousObjects.kt")
public void testAnonymousObjects() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/anonymousObjects.kt");