Skip to content

Commit 78c76a2

Browse files
committed
Allow to place breakpoints in inline functions defined in android tests
1 parent ae2e857 commit 78c76a2

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
264264
}
265265
try {
266266
if (myDebugProcess.isDexDebug()) {
267-
val inlineLocations = getLocationsOfInlinedLine(type, position, myDebugProcess.searchScope)
267+
val inlineLocations = runReadAction { getLocationsOfInlinedLine(type, position, myDebugProcess.searchScope) }
268268
if (!inlineLocations.isEmpty()) {
269269
return inlineLocations
270270
}

idea/src/org/jetbrains/kotlin/idea/debugger/smapUtil.kt

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,46 @@ fun readClassFile(project: Project,
5454
file: VirtualFile): ByteArray? {
5555
val fqNameWithInners = jvmName.fqNameForClassNameWithoutDollars.tail(jvmName.packageFqName)
5656

57-
when {
58-
ProjectRootsUtil.isLibrarySourceFile(project, file) -> {
59-
val classId = ClassId(jvmName.packageFqName, Name.identifier(fqNameWithInners.asString()))
57+
fun readFromLibrary() : ByteArray? {
58+
if (!ProjectRootsUtil.isLibrarySourceFile(project, file)) return null
6059

61-
val fileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project)
62-
val classFile = fileFinder.findVirtualFileWithHeader(classId) ?: return null
63-
return classFile.contentsToByteArray()
64-
}
60+
val classId = ClassId(jvmName.packageFqName, Name.identifier(fqNameWithInners.asString()))
61+
62+
val fileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project)
63+
val classFile = fileFinder.findVirtualFileWithHeader(classId) ?: return null
64+
return classFile.contentsToByteArray()
65+
}
66+
67+
fun readFromOutput(isForTestClasses: Boolean): ByteArray? {
68+
if (!ProjectRootsUtil.isProjectSourceFile(project, file)) return null
69+
70+
val module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(file)
71+
val outputDir = CompilerPaths.getModuleOutputDirectory(module, /*forTests = */ isForTestClasses) ?: return null
6572

66-
ProjectRootsUtil.isProjectSourceFile(project, file) -> {
67-
val module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(file)
68-
val outputDir = CompilerPaths.getModuleOutputDirectory(module, /*forTests = */ false) ?: return null
73+
val className = fqNameWithInners.asString().replace('.', '$')
74+
var classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir)
6975

70-
val className = fqNameWithInners.asString().replace('.', '$')
71-
val classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir) ?: return null
76+
if (classByDirectory == null) {
77+
if (!isForTestClasses) {
78+
return null
79+
}
80+
81+
val outputModeDirName = outputDir.name
82+
val androidTestOutputDir = outputDir.parent?.parent?.findChild("androidTest")?.findChild(outputModeDirName) ?: return null
7283

73-
return classByDirectory.readBytes()
84+
classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, androidTestOutputDir) ?: return null
7485
}
7586

76-
else -> return null
87+
return classByDirectory.readBytes()
7788
}
89+
90+
fun readFromSourceOutput() : ByteArray? = readFromOutput(false)
91+
92+
fun readFromTestOutput() : ByteArray? = readFromOutput(true)
93+
94+
return readFromLibrary() ?:
95+
readFromSourceOutput() ?:
96+
readFromTestOutput()
7897
}
7998

8099
private fun findClassFileByPath(packageName: String, className: String, outputDir: VirtualFile): File? {

0 commit comments

Comments
 (0)