Debugger: Allow to evaluate private properties from companion objects (KT-26795)

This commit is contained in:
Yan Zhulanow
2018-09-17 21:24:30 +03:00
parent fee0cfcecb
commit 713dc589e0
5 changed files with 62 additions and 2 deletions
@@ -2049,7 +2049,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
(forceField ||
(Visibilities.isPrivate(propertyDescriptor.getVisibility()) &&
isDefaultAccessor(propertyDescriptor.getGetter()) && isDefaultAccessor(propertyDescriptor.getSetter())))) {
fieldAccessorKind = AccessorKind.IN_CLASS_COMPANION;
fieldAccessorKind = JvmCodegenUtil.isDebuggerContext(context) ? AccessorKind.NORMAL : AccessorKind.IN_CLASS_COMPANION;
}
else if ((syntheticBackingField &&
context.getFirstCrossInlineOrNonInlineContext().getParentContext().getContextDescriptor() != containingDeclaration)) {
@@ -247,7 +247,7 @@ public class JvmCodegenUtil {
return Visibilities.isPrivate(accessor.getVisibility()) || accessor.getModality() == FINAL;
}
private static boolean isDebuggerContext(@NotNull CodegenContext context) {
public static boolean isDebuggerContext(@NotNull CodegenContext context) {
KtFile file = DescriptorToSourceUtils.getContainingFile(context.getContextDescriptor());
return file != null && CodeFragmentUtilKt.getSuppressDiagnosticsInDebugMode(file);
}
@@ -0,0 +1,42 @@
package privateFieldInCompanion
class Foo {
companion object {
private const val PRIVATE_CONST = 1
const val PUBLIC_CONST = 2
private val PRIVATE_VAL = 3
val PUBLIC_VAL = 4
private val PRIVATE_STATIC = 5
val PUBLIC_STATIC = 6
}
fun foo() {
//Breakpoint!
val a = 5
}
}
fun main(args: Array<String>) {
Foo().foo()
}
// EXPRESSION: PRIVATE_CONST
// RESULT: 1: I
// EXPRESSION: PUBLIC_CONST
// RESULT: 2: I
// EXPRESSION: PRIVATE_VAL
// RESULT: 3: I
// EXPRESSION: PUBLIC_VAL
// RESULT: 4: I
// EXPRESSION: PRIVATE_STATIC
// RESULT: 5: I
// EXPRESSION: PUBLIC_STATIC
// RESULT: 6: I
@@ -0,0 +1,13 @@
LineBreakpoint created at privateFieldInCompanion.kt:18
Run Java
Connected to the target VM
privateFieldInCompanion.kt:18
Compile bytecode for PRIVATE_CONST
Compile bytecode for PUBLIC_CONST
Compile bytecode for PRIVATE_VAL
Compile bytecode for PUBLIC_VAL
Compile bytecode for PRIVATE_STATIC
Compile bytecode for PUBLIC_STATIC
Disconnected from the target VM
Process finished with exit code 0
@@ -281,6 +281,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/privateClass.kt");
}
@TestMetadata("privateFieldInCompanion.kt")
public void testPrivateFieldInCompanion() throws Exception {
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/privateFieldInCompanion.kt");
}
@TestMetadata("privateMember.kt")
public void testPrivateMember() throws Exception {
runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/privateMember.kt");