Debugger: allow evaluate expression in constructors

This commit is contained in:
Natalia Ukhorskaya
2015-07-24 12:24:50 +03:00
parent e423e99253
commit 519c2784ff
12 changed files with 128 additions and 0 deletions
@@ -93,6 +93,20 @@ public class CodeFragmentAnalyzer(
val dataFlowInfo: DataFlowInfo
when (context) {
is JetPrimaryConstructor -> {
val descriptor = resolveSession.getClassDescriptor(context.getContainingClassOrObject(), NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
scopeForContextElement = descriptor.getScopeForInitializerResolution()
dataFlowInfo = DataFlowInfo.EMPTY
}
is JetSecondaryConstructor -> {
val correctedContext = context.getDelegationCall().calleeExpression!!
val contextForElement = resolveToElement(correctedContext)
scopeForContextElement = contextForElement[BindingContext.LEXICAL_SCOPE, correctedContext]
dataFlowInfo = DataFlowInfo.EMPTY
}
is JetClassOrObject -> {
val descriptor = resolveSession.getClassDescriptor(context, NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
@@ -209,6 +209,10 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
}
}
}
contextElement is JetPrimaryConstructor -> {
val classOrObject = contextElement.getContainingClassOrObject()
insertNewInitializer(classOrObject.getOrCreateBody())
}
contextElement is JetClassOrObject -> {
insertNewInitializer(contextElement.getBody()!!)
}
@@ -216,6 +220,11 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
val block = contextElement.getBodyExpression()!!
block.getStatements().firstOrNull() ?: block.getLastChild()
}
contextElement is JetDeclarationWithBody && !contextElement.hasBody()-> {
val block = psiFactory.createBlock("")
val newBlock = contextElement.add(block) as JetBlockExpression
newBlock.getRBrace()
}
contextElement is JetDeclarationWithBody && !contextElement.hasBlockBody()-> {
wrapInRunFun(contextElement.getBodyExpression()!!)
}
@@ -0,0 +1,12 @@
class A(
a: Int
<caret>): Base(1) {
val c = 1
init {
val d = 1
val e = 1
}
}
open class Base(i: Int)
@@ -0,0 +1 @@
a + c + <error>d</error> + <error>e</error>
@@ -0,0 +1,6 @@
class A(a: Int, val a1: Int) {
<caret>constructor(b: Int): this(b, b) {}
val c = 1
}
@@ -0,0 +1 @@
<error>a</error> + b + c + a1
@@ -0,0 +1,6 @@
class A(a: Int, val a1: Int) {
<caret>constructor(b: Int): this(b, b)
val c = 1
}
@@ -0,0 +1 @@
<error>a</error> + b + c + a1
+17
View File
@@ -0,0 +1,17 @@
LineBreakpoint created at constructors.kt:9
LineBreakpoint created at constructors.kt:13
LineBreakpoint created at constructors.kt:20
LineBreakpoint created at constructors.kt:28
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! constructors.ConstructorsPackage
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
constructors.kt:9
Compile bytecode for p
constructors.kt:13
Compile bytecode for p + 1
constructors.kt:20
Compile bytecode for p1 + p2
constructors.kt:28
Compile bytecode for i1
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0
@@ -0,0 +1,37 @@
package constructors
class Derived2(): Base(1) {
// constructor with body
// EXPRESSION: p
// RESULT: 1: I
//Breakpoint!
constructor(p: Int): this() {
// EXPRESSION: p + 1
// RESULT: 2: I
//Breakpoint!
val a = 1
}
// constructor without body
// EXPRESSION: p1 + p2
// RESULT: 2: I
//Breakpoint!
constructor(p1: Int, p2: Int): this()
}
// EXPRESSION: i1
// RESULT: 1: I
class Derived1(
i1: Int
//Breakpoint!
): Base(i1)
open class Base(i: Int)
fun main(args: Array<String>) {
Derived2(1)
Derived2(1, 1)
Derived1(1)
}
@@ -97,6 +97,12 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
doTest(fileName);
}
@TestMetadata("primaryConstructor.kt")
public void testPrimaryConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/primaryConstructor.kt");
doTest(fileName);
}
@TestMetadata("privateFunArgumentsResolve.kt")
public void testPrivateFunArgumentsResolve() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/privateFunArgumentsResolve.kt");
@@ -121,6 +127,18 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
doTest(fileName);
}
@TestMetadata("secondaryConstructor.kt")
public void testSecondaryConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/secondaryConstructor.kt");
doTest(fileName);
}
@TestMetadata("secondaryConstructorWithoutBraces.kt")
public void testSecondaryConstructorWithoutBraces() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/secondaryConstructorWithoutBraces.kt");
doTest(fileName);
}
@TestMetadata("simpleNameExpression.kt")
public void testSimpleNameExpression() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/simpleNameExpression.kt");
@@ -652,6 +652,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
doMultipleBreakpointsTest(fileName);
}
@TestMetadata("constructors.kt")
public void testConstructors() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/constructors.kt");
doMultipleBreakpointsTest(fileName);
}
@TestMetadata("exceptions.kt")
public void testExceptions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt");