From 1ef5362edc644996e474fb64d3b97ad3e29328bf Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 2 Aug 2017 19:45:37 +0300 Subject: [PATCH] Fix breakpoints from Kotlin file placed in irrelevant class (KT-19429) State that there're no locations in given file, if all locations for line were filtered out because of wrong file name. Need this because if we throw exception, other positions managers may return locations without explicit check for file type or file name. See PositionManagerImpl.java #KT-19429 Fixed --- .../idea/debugger/KotlinPositionManager.kt | 6 +++--- .../stepOver/stopInWrongClass.Other.kt | 11 ++++++++++ .../src/stepping/stepOver/stopInWrongClass.kt | 21 +++++++++++++++++++ .../stepping/stepOver/stopInWrongClass.out | 9 ++++++++ .../debugger/KotlinSteppingTestGenerated.java | 6 ++++++ 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.Other.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.out diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt index ac2f3ef8fd2..23d97ed528e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt @@ -261,12 +261,12 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq val line = position.line + 1 - val locations = type.locationsOfLine(KOTLIN_STRATA_NAME, null, line).filter { it.sourceName(KOTLIN_STRATA_NAME) == position.file.name } - if (locations.isEmpty()) { + val locations = type.locationsOfLine(KOTLIN_STRATA_NAME, null, line) + if (locations == null || locations.isEmpty()) { throw NoDataException.INSTANCE } - return locations + return locations.filter { it.sourceName(KOTLIN_STRATA_NAME) == position.file.name } } catch (e: AbsentInformationException) { throw NoDataException.INSTANCE diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.Other.kt b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.Other.kt new file mode 100644 index 00000000000..3a1471ac8a9 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.Other.kt @@ -0,0 +1,11 @@ +package stopInWrongClass + +class A { + fun test() { + // Breakpoint 1 + foo() + } +} + +fun foo() { +} \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.kt b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.kt new file mode 100644 index 00000000000..c93aba7d28d --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.kt @@ -0,0 +1,21 @@ +package stopInWrongClass + +class AA { + fun test() { + // Should be on the same line with Breakpoint 1 + foo() + } + + fun other() { + //Breakpoint! + foo() + } +} + +fun main(args: Array) { + // Shouldn't stop inside test() + AA().test() + AA().other() +} + +// ADDITIONAL_BREAKPOINT: stopInWrongClass.Other.kt: Breakpoint 1 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.out b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.out new file mode 100644 index 00000000000..68f6503700d --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.out @@ -0,0 +1,9 @@ +LineBreakpoint created at stopInWrongClass.Other.kt:6 +LineBreakpoint created at stopInWrongClass.kt:11 +Run Java +Connected to the target VM +stopInWrongClass.kt:11 +stopInWrongClass.kt:12 +Disconnected from the target VM + +Process finished with exit code 0 diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index b6068e0d375..5d9e164a8e2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -998,6 +998,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepOverTest(fileName); } + @TestMetadata("stopInWrongClass.kt") + public void testStopInWrongClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInWrongClass.kt"); + doStepOverTest(fileName); + } + @TestMetadata("stopInlineCallInLocalFunInSecondaryConstructor.kt") public void testStopInlineCallInLocalFunInSecondaryConstructor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInlineCallInLocalFunInSecondaryConstructor.kt");