From 73099c3a419a458cddf8cc6ec70bd1c2913c2e62 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Fri, 21 Aug 2015 17:38:09 +0300 Subject: [PATCH] Minor: move to base class --- .../debugger/AbstractKotlinSteppingTest.kt | 68 +---------------- .../idea/debugger/KotlinDebuggerTestBase.kt | 73 ++++++++++++++++++- .../AbstractKotlinEvaluateExpressionTest.kt | 7 +- 3 files changed, 71 insertions(+), 77 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt index 00eb31aa38e..0a2d943ae9a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt @@ -16,17 +16,7 @@ package org.jetbrains.kotlin.idea.debugger -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.* -import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.test.InTextDirectivesUtils.getPrefixedInt import java.io.File @@ -49,21 +39,7 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { createAdditionalBreakpoints(fileText) createDebugProcess(path) - fun repeat(indexPrefix: String, f: SuspendContextImpl.() -> Unit) { - for (i in 1..(getPrefixedInt(fileText, indexPrefix) ?: 1)) { - doOnBreakpoint(f) - } - } - - 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_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) } - } - } + doStepping(path) finish() } @@ -87,46 +63,4 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { finish() } - - private fun SuspendContextImpl.smartStepInto(chooseFromList: Int = 0) { - this.smartStepInto(chooseFromList, false) - } - - 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 { - val breakpointManager = DebuggerManagerEx.getInstanceEx(getProject())?.getBreakpointManager() - val breakpoint = breakpointManager?.getBreakpoints()?.first { it is LineBreakpoint } - - val line = (breakpoint as LineBreakpoint).getLineIndex() - - return runReadAction { - val containingFile = breakpoint.getPsiFile() - if (containingFile == null) throw AssertionError("Couldn't find file for breakpoint at the line $line") - - val position = MockSourcePosition(_file = containingFile, _line = line) - - val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position) - - 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 - } - } - }.filterNotNull() - } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt index 5e85ae38089..9dfd2bb8dbd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt @@ -19,15 +19,15 @@ package org.jetbrains.kotlin.idea.debugger import com.intellij.debugger.DebuggerInvocationUtil import com.intellij.debugger.DebuggerManagerEx import com.intellij.debugger.SourcePosition -import com.intellij.debugger.engine.DebugProcessImpl -import com.intellij.debugger.engine.MethodFilter -import com.intellij.debugger.engine.SuspendContextImpl -import com.intellij.debugger.engine.SuspendContextRunnable +import com.intellij.debugger.actions.MethodSmartStepTarget +import com.intellij.debugger.actions.SmartStepTarget +import com.intellij.debugger.engine.* import com.intellij.debugger.engine.evaluation.EvaluationContextImpl import com.intellij.debugger.impl.DebuggerContextImpl import com.intellij.debugger.impl.PositionUtil import com.intellij.debugger.settings.DebuggerSettings import com.intellij.debugger.ui.breakpoints.BreakpointManager +import com.intellij.debugger.ui.breakpoints.LineBreakpoint import com.intellij.execution.process.ProcessOutputTypes import com.intellij.openapi.application.ModalityState import com.intellij.openapi.roots.JdkOrderEntry @@ -45,11 +45,13 @@ import com.intellij.xdebugger.breakpoints.XBreakpointType import com.intellij.xdebugger.breakpoints.XLineBreakpointType import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpoint import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpointType +import org.jetbrains.kotlin.idea.debugger.stepping.* import org.jetbrains.kotlin.idea.test.JetJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.InTextDirectivesUtils.findStringWithPrefixes +import java.io.File import javax.swing.SwingUtilities abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { @@ -136,6 +138,69 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { dp.getManagerThread()!!.schedule(dp.createStepOutCommand(this)) } + protected fun doStepping(path: String) { + val file = File(path) + val fileText = file.readText() + fun repeat(indexPrefix: String, f: SuspendContextImpl.() -> Unit) { + for (i in 1..(InTextDirectivesUtils.getPrefixedInt(fileText, indexPrefix) ?: 1)) { + doOnBreakpoint(f) + } + } + + file.readLines().forEach { + val line = it.trim() + when { + line.startsWith("// STEP_INTO: ") -> repeat("// STEP_INTO: ") { stepInto(this) } + line.startsWith("// STEP_OUT: ") -> repeat("// STEP_OUT: ") { stepOut() } + line.startsWith("// SMART_STEP_INTO_BY_INDEX: ") -> doOnBreakpoint { smartStepInto(InTextDirectivesUtils.getPrefixedInt(it, "// SMART_STEP_INTO_BY_INDEX: ")!!) } + line.startsWith("// SMART_STEP_INTO: ") -> repeat("// SMART_STEP_INTO: ") { smartStepInto() } + line.startsWith("// RESUME: ") -> repeat("// RESUME: ") { resume(this) } + } + } + } + + protected fun SuspendContextImpl.smartStepInto(chooseFromList: Int = 0) { + this.smartStepInto(chooseFromList, false) + } + + 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 { + val breakpointManager = DebuggerManagerEx.getInstanceEx(getProject())?.getBreakpointManager() + val breakpoint = breakpointManager?.getBreakpoints()?.first { it is LineBreakpoint } + + val line = (breakpoint as LineBreakpoint).getLineIndex() + + return runReadAction { + val containingFile = breakpoint.getPsiFile() + if (containingFile == null) throw AssertionError("Couldn't find file for breakpoint at the line $line") + + val position = MockSourcePosition(_file = containingFile, _line = line) + + val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position) + + 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 + } + } + }.filterNotNull() + } + protected fun SuspendContextImpl.printContext() { runReadAction { if (this.getFrameProxy() == null) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt index 00efde1f6b5..3b9a0dd6556 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt @@ -113,12 +113,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB createDebugProcess(path) - val count = InTextDirectivesUtils.getPrefixedInt(fileText, "// STEP_INTO: ") ?: 0 - if (count > 0) { - for (i in 1..count) { - doOnBreakpoint { this@AbstractKotlinEvaluateExpressionTest.stepInto(this) } - } - } + doStepping(path) doOnBreakpoint { val exceptions = linkedMapOf()