Debugger: Allow to evaluate private properties from companion objects (KT-26795)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
+42
@@ -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
|
||||
+13
@@ -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
|
||||
Generated
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user