Allow to place breakpoints in inline functions defined in android tests

This commit is contained in:
Nikolay Krasko
2016-10-28 21:56:21 +03:00
parent ae2e857843
commit 78c76a2ca4
2 changed files with 38 additions and 19 deletions
@@ -264,7 +264,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
}
try {
if (myDebugProcess.isDexDebug()) {
val inlineLocations = getLocationsOfInlinedLine(type, position, myDebugProcess.searchScope)
val inlineLocations = runReadAction { getLocationsOfInlinedLine(type, position, myDebugProcess.searchScope) }
if (!inlineLocations.isEmpty()) {
return inlineLocations
}
@@ -54,27 +54,46 @@ fun readClassFile(project: Project,
file: VirtualFile): ByteArray? {
val fqNameWithInners = jvmName.fqNameForClassNameWithoutDollars.tail(jvmName.packageFqName)
when {
ProjectRootsUtil.isLibrarySourceFile(project, file) -> {
val classId = ClassId(jvmName.packageFqName, Name.identifier(fqNameWithInners.asString()))
fun readFromLibrary() : ByteArray? {
if (!ProjectRootsUtil.isLibrarySourceFile(project, file)) return null
val fileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project)
val classFile = fileFinder.findVirtualFileWithHeader(classId) ?: return null
return classFile.contentsToByteArray()
}
val classId = ClassId(jvmName.packageFqName, Name.identifier(fqNameWithInners.asString()))
ProjectRootsUtil.isProjectSourceFile(project, file) -> {
val module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(file)
val outputDir = CompilerPaths.getModuleOutputDirectory(module, /*forTests = */ false) ?: return null
val className = fqNameWithInners.asString().replace('.', '$')
val classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir) ?: return null
return classByDirectory.readBytes()
}
else -> return null
val fileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project)
val classFile = fileFinder.findVirtualFileWithHeader(classId) ?: return null
return classFile.contentsToByteArray()
}
fun readFromOutput(isForTestClasses: Boolean): ByteArray? {
if (!ProjectRootsUtil.isProjectSourceFile(project, file)) return null
val module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(file)
val outputDir = CompilerPaths.getModuleOutputDirectory(module, /*forTests = */ isForTestClasses) ?: return null
val className = fqNameWithInners.asString().replace('.', '$')
var classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir)
if (classByDirectory == null) {
if (!isForTestClasses) {
return null
}
val outputModeDirName = outputDir.name
val androidTestOutputDir = outputDir.parent?.parent?.findChild("androidTest")?.findChild(outputModeDirName) ?: return null
classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, androidTestOutputDir) ?: return null
}
return classByDirectory.readBytes()
}
fun readFromSourceOutput() : ByteArray? = readFromOutput(false)
fun readFromTestOutput() : ByteArray? = readFromOutput(true)
return readFromLibrary() ?:
readFromSourceOutput() ?:
readFromTestOutput()
}
private fun findClassFileByPath(packageName: String, className: String, outputDir: VirtualFile): File? {