From 3d7b503cd675b9f44bacae0ce97ce734d725d1e8 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 27 Nov 2018 17:39:31 +0900 Subject: [PATCH] Fix source mapping for stepping into package facades from libraries (KT-28028) --- .../kotlin/idea/debugger/DebuggerUtils.kt | 48 +++++++------------ .../src/stepping/stepInto/sameFileNames.kt | 8 ++++ .../src/stepping/stepInto/sameFileNames.out | 8 ++++ .../debugger/KotlinSteppingTestGenerated.java | 5 ++ 4 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.out diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt index 01986dbcf70..4c1273b2fdf 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt @@ -75,41 +75,27 @@ object DebuggerUtils { if (!isKotlinSourceFile(fileName)) return null if (DumbService.getInstance(project).isDumb) return null - val filesWithExactName = scopes.findFirstNotEmpty { findFilesByNameInPackage(className, fileName, project, it) } ?: return null - - if (filesWithExactName.isEmpty()) return null - - if (filesWithExactName.size == 1 && !forceRanking) { - return filesWithExactName.single() - } - - // Static facade or inner class of such facade? val partFqName = className.fqNameForClassNameWithoutDollars - val filesForPart = scopes.findFirstNotEmpty { StaticFacadeIndexUtil.findFilesForFilePart(partFqName, it, project) } ?: return null - if (!filesForPart.isEmpty()) { - for (file in filesForPart) { - if (file.name == fileName) { - return file - } + + for (scope in scopes) { + val files = findFilesByNameInPackage(className, fileName, project, scope) + + if (files.isEmpty()) { + continue } - // Do not fall back to decompiled files (which have different name). - return null + + if (files.size == 1 && !forceRanking || location == null) { + return files.first() + } + + StaticFacadeIndexUtil.findFilesForFilePart(partFqName, scope, project) + .singleOrNull { it.name == fileName } + ?.let { return it } + + return FileRankingCalculatorForIde.findMostAppropriateSource(files, location) } - if (location != null) { - return FileRankingCalculatorForIde.findMostAppropriateSource(filesWithExactName, location) - } - - return filesWithExactName.first() - } - - private fun Collection.findFirstNotEmpty(predicate: (T) -> Collection): Collection? { - var result: Collection = emptyList() - for (e in this) { - result = predicate(e) - if (result.isNotEmpty()) break - } - return result + return null } private fun findFilesByNameInPackage( diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.kt b/idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.kt new file mode 100644 index 00000000000..2d893b35dd7 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.kt @@ -0,0 +1,8 @@ +package sameFileNames + +fun main() { + //Breakpoint! + val result = simple.foo() +} + +// STEP_INTO: 1 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.out b/idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.out new file mode 100644 index 00000000000..640f12481ed --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.out @@ -0,0 +1,8 @@ +LineBreakpoint created at sameFileNames.kt:5 +Run Java +Connected to the target VM +sameFileNames.kt:5 +simpleKt.kt:5 +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 350498c4be9..e0af29813ed 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -272,6 +272,11 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { runTest("idea/testData/debugger/tinyApp/src/stepping/stepInto/samAdapter.kt"); } + @TestMetadata("sameFileNames.kt") + public void testSameFileNames() throws Exception { + runTest("idea/testData/debugger/tinyApp/src/stepping/stepInto/sameFileNames.kt"); + } + @TestMetadata("siSuspendFun.kt") public void testSiSuspendFun() throws Exception { runTest("idea/testData/debugger/tinyApp/src/stepping/stepInto/siSuspendFun.kt");