From ee49d13d89b8968b48fe26952692b535eecdc867 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Tue, 21 Jul 2015 17:22:58 +0300 Subject: [PATCH] Add tests on smart step into lambda --- .../debugger/tinyApp/outs/funLiteral.out | 8 +++++ .../tinyApp/outs/severalFunLiterals.out | 8 +++++ .../outs/severalFunLiteralsInClass.out | 8 +++++ .../tinyApp/src/stepping/custom/funLiteral.kt | 13 ++++++++ .../src/stepping/custom/severalFunLiterals.kt | 25 ++++++++++++++ .../custom/severalFunLiteralsInClass.kt | 28 ++++++++++++++++ .../debugger/AbstractKotlinSteppingTest.kt | 33 +++++++++++-------- .../debugger/KotlinSteppingTestGenerated.java | 18 ++++++++++ 8 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/outs/funLiteral.out create mode 100644 idea/testData/debugger/tinyApp/outs/severalFunLiterals.out create mode 100644 idea/testData/debugger/tinyApp/outs/severalFunLiteralsInClass.out create mode 100644 idea/testData/debugger/tinyApp/src/stepping/custom/funLiteral.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiterals.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiteralsInClass.kt diff --git a/idea/testData/debugger/tinyApp/outs/funLiteral.out b/idea/testData/debugger/tinyApp/outs/funLiteral.out new file mode 100644 index 00000000000..b72d29c7463 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/funLiteral.out @@ -0,0 +1,8 @@ +LineBreakpoint created at funLiteral.kt:5 +!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! funLiteral.FunLiteralPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +funLiteral.kt:5 +funLiteral.kt:6 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/outs/severalFunLiterals.out b/idea/testData/debugger/tinyApp/outs/severalFunLiterals.out new file mode 100644 index 00000000000..979ebb54c6e --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/severalFunLiterals.out @@ -0,0 +1,8 @@ +LineBreakpoint created at severalFunLiterals.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! severalFunLiterals.SeveralFunLiteralsPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +severalFunLiterals.kt:6 +severalFunLiterals.kt:7 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/outs/severalFunLiteralsInClass.out b/idea/testData/debugger/tinyApp/outs/severalFunLiteralsInClass.out new file mode 100644 index 00000000000..2eaaee520c5 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/severalFunLiteralsInClass.out @@ -0,0 +1,8 @@ +LineBreakpoint created at severalFunLiteralsInClass.kt:20 +!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! severalFunLiteralsInClass.SeveralFunLiteralsInClassPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +severalFunLiteralsInClass.kt:20 +severalFunLiteralsInClass.kt:21 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/funLiteral.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/funLiteral.kt new file mode 100644 index 00000000000..b7437ad833b --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/funLiteral.kt @@ -0,0 +1,13 @@ +package funLiteral + +fun main(args: Array) { + //Breakpoint! + f1() { + f2() + } +} + +fun f1(f: () -> Unit) { f() } +fun f2() {} + +// SMART_STEP_INTO_BY_INDEX: 1 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiterals.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiterals.kt new file mode 100644 index 00000000000..7575c69854d --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiterals.kt @@ -0,0 +1,25 @@ +package severalFunLiterals + +fun main(args: Array) { + val myClass = MyClass() + //Breakpoint! + myClass.f1 { test() }.f2 { + test() + } +} + +class MyClass { + fun f1(f1Param: () -> Unit): MyClass { + f1Param() + return this + } + + fun f2(f2Param: () -> Unit): MyClass { + f2Param() + return this + } +} + +fun test() {} + +// SMART_STEP_INTO_BY_INDEX: 3 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiteralsInClass.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiteralsInClass.kt new file mode 100644 index 00000000000..ac62e5c0961 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiteralsInClass.kt @@ -0,0 +1,28 @@ +package severalFunLiteralsInClass + +fun main(args: Array) { + MyClass().inClass() +} + +class MyClass { + fun f1(f1Param: () -> Unit): MyClass { + f1Param() + return this + } + + fun f2(f2Param: () -> Unit): MyClass { + f2Param() + return this + } + + fun inClass() { + //Breakpoint! + f1 { test() }.f2 { + test() + } + } +} + +fun test() {} + +// SMART_STEP_INTO_BY_INDEX: 3 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt index e508517d152..00eb31aa38e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt @@ -20,13 +20,12 @@ import com.intellij.debugger.DebuggerManagerEx import com.intellij.debugger.actions.MethodSmartStepTarget import com.intellij.debugger.actions.SmartStepTarget import com.intellij.debugger.engine.BasicStepMethodFilter +import com.intellij.debugger.engine.MethodFilter import com.intellij.debugger.engine.NamedMethodFilter import com.intellij.debugger.engine.SuspendContextImpl import com.intellij.debugger.ui.breakpoints.LineBreakpoint import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.kotlin.idea.debugger.stepping.KotlinBasicStepMethodFilter -import org.jetbrains.kotlin.idea.debugger.stepping.KotlinMethodSmartStepTarget -import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSmartStepIntoHandler +import org.jetbrains.kotlin.idea.debugger.stepping.* import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.test.InTextDirectivesUtils.getPrefixedInt import java.io.File @@ -58,10 +57,11 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { File(path).readLines().forEach { when { - it.startsWith("// STEP_INTO") -> repeat("// STEP_INTO: ") { stepInto(this) } - it.startsWith("// STEP_OUT") -> repeat("// STEP_OUT: ") { stepOut() } - it.startsWith("// SMART_STEP_INTO") -> repeat("// SMART_STEP_INTO: ") { smartStepInto() } - it.startsWith("// RESUME") -> repeat("// RESUME: ") { resume(this) } + it.startsWith("// STEP_INTO: ") -> repeat("// STEP_INTO: ") { stepInto(this) } + it.startsWith("// STEP_OUT: ") -> repeat("// STEP_OUT: ") { stepOut() } + it.startsWith("// SMART_STEP_INTO_BY_INDEX: ") -> doOnBreakpoint { smartStepInto(getPrefixedInt(it, "// SMART_STEP_INTO_BY_INDEX: ")!!) } + it.startsWith("// SMART_STEP_INTO: ") -> repeat("// SMART_STEP_INTO: ") { smartStepInto() } + it.startsWith("// RESUME: ") -> repeat("// RESUME: ") { resume(this) } } } @@ -88,17 +88,23 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { finish() } - private fun SuspendContextImpl.smartStepInto() { - this.smartStepInto(false) + private fun SuspendContextImpl.smartStepInto(chooseFromList: Int = 0) { + this.smartStepInto(chooseFromList, false) } - private fun SuspendContextImpl.smartStepInto(ignoreFilters: Boolean) { - createSmartStepIntoFilters().forEach { - dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, it)) + private fun SuspendContextImpl.smartStepInto(chooseFromList: Int, ignoreFilters: Boolean) { + val filters = createSmartStepIntoFilters() + if (chooseFromList == 0) { + filters.forEach { + dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, it)) + } + } + else { + dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, filters.get(chooseFromList))) } } - private fun createSmartStepIntoFilters(): List { + private fun createSmartStepIntoFilters(): List { val breakpointManager = DebuggerManagerEx.getInstanceEx(getProject())?.getBreakpointManager() val breakpoint = breakpointManager?.getBreakpoints()?.first { it is LineBreakpoint } @@ -115,6 +121,7 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { stepTargets.filterIsInstance().map { stepTarget -> when (stepTarget) { + is KotlinLambdaSmartStepTarget -> KotlinLambdaMethodFilter(stepTarget.getLambda(), stepTarget.getCallingExpressionLines()!!) is KotlinMethodSmartStepTarget -> KotlinBasicStepMethodFilter(stepTarget.resolvedElement, stepTarget.getCallingExpressionLines()!!) is MethodSmartStepTarget -> BasicStepMethodFilter(stepTarget.getMethod(), stepTarget.getCallingExpressionLines()) else -> null diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index e0cccc2c8a5..c8fecebd8f0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -382,6 +382,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/tinyApp/src/stepping/custom"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("funLiteral.kt") + public void testFunLiteral() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/funLiteral.kt"); + doCustomTest(fileName); + } + @TestMetadata("fwAbstractProperty.kt") public void testFwAbstractProperty() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/fwAbstractProperty.kt"); @@ -400,6 +406,18 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doCustomTest(fileName); } + @TestMetadata("severalFunLiterals.kt") + public void testSeveralFunLiterals() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiterals.kt"); + doCustomTest(fileName); + } + + @TestMetadata("severalFunLiteralsInClass.kt") + public void testSeveralFunLiteralsInClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/severalFunLiteralsInClass.kt"); + doCustomTest(fileName); + } + @TestMetadata("stepIntoStdlibInlineFun2step.kt") public void testStepIntoStdlibInlineFun2step() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt");