diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java index 275be58d365..f0f135de061 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java @@ -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; } diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.kt new file mode 100644 index 00000000000..302db459b95 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.kt @@ -0,0 +1,15 @@ +package annotationValue + +annotation class Anno(val value: String) + +@Anno("abc") +class SomeClass + +fun main(args: Array) { + //Breakpoint! + val a = 5 +} + +// EXPRESSION: (SomeClass::class.java.annotations[0] as Anno).value +// RESULT: "abc": Ljava/lang/String; + diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.out b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.out new file mode 100644 index 00000000000..a035ef34207 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/annotationValue.out @@ -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 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 debef61d47c..b4a28969e1d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java @@ -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");