Evaluate expression: add ability to evaluate expression suspending on class header

This commit is contained in:
Natalia Ukhorskaya
2014-11-06 13:25:07 +03:00
parent 4eb93c06b1
commit 55590e00a5
5 changed files with 59 additions and 0 deletions
@@ -212,6 +212,10 @@ public class JetPsiFactory(private val project: Project) {
return createFunction("fun foo() {}").getBodyExpression()!!
}
public fun createAnonymousInitializer(): JetClassInitializer {
return createClass("class A { {} }").getAnonymousInitializers().first!!
}
public fun createEmptyClassBody(): JetClassBody {
return createClass("class A(){}").getBody()!!
}
@@ -183,6 +183,12 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
contextElement is JetProperty && !contextElement.isLocal() -> {
wrapInRunFun(contextElement.getDelegateExpressionOrInitializer()!!)
}
contextElement is JetClass -> {
val initializer = psiFactory.createAnonymousInitializer()
val newInitializer = (contextElement.getBody().addAfter(initializer, contextElement.getBody().getFirstChild()) as JetClassInitializer)
val block = newInitializer.getBody() as JetBlockExpression
block.getLastChild()
}
contextElement is JetFunctionLiteral -> {
val block = contextElement.getBodyExpression()!!
block.getStatements().first ?: block.getLastChild()
@@ -0,0 +1,12 @@
LineBreakpoint created at onClassHeader.kt:6
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! onClassHeader.OnClassHeaderPackage
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
onClassHeader.kt:6
onClassHeader.kt:18
onClassHeader.kt:16
Compile bytecode for 1 + 1
Compile bytecode for this
Compile bytecode for this.foo("a")
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0
@@ -0,0 +1,31 @@
package onClassHeader
fun main(args: Array<String>) {
val d: Base<String> = Derived()
//Breakpoint!
d.foo("")
val a = 1
}
open class Base<T> {
open fun foo(t: T): Int {
return 1
}
}
class Derived: Base<String>() {
override fun foo(t: String): Int {
return 2
}
}
// STEP_INTO: 2
// EXPRESSION: 1 + 1
// RESULT: 2: I
// EXPRESSION: this
// RESULT: instance of onClassHeader.Derived(id=ID): LonClassHeader/Derived;
// EXPRESSION: this.foo("a")
// RESULT: 2: I
@@ -154,6 +154,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
doSingleBreakpointTest(fileName);
}
@TestMetadata("onClassHeader.kt")
public void testOnClassHeader() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/onClassHeader.kt");
doSingleBreakpointTest(fileName);
}
@TestMetadata("privateMember.kt")
public void testPrivateMember() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/privateMember.kt");