Support navigation to library inline functions from stack trace
This commit is contained in:
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.idea.core.refactoring.getLineCount
|
|||||||
import org.jetbrains.kotlin.idea.core.refactoring.toPsiFile
|
import org.jetbrains.kotlin.idea.core.refactoring.toPsiFile
|
||||||
import org.jetbrains.kotlin.idea.util.DebuggerUtils
|
import org.jetbrains.kotlin.idea.util.DebuggerUtils
|
||||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinder
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.tail
|
import org.jetbrains.kotlin.name.tail
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
@@ -69,6 +71,12 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun virtualFileForInlineCall(jvmName: JvmClassName, file: VirtualFile, lineNumber: Int, project: Project): OpenFileHyperlinkInfo? {
|
private fun virtualFileForInlineCall(jvmName: JvmClassName, file: VirtualFile, lineNumber: Int, project: Project): OpenFileHyperlinkInfo? {
|
||||||
|
if (ProjectRootsUtil.isInContent(project, file, false, true, false)) {
|
||||||
|
val fileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project)
|
||||||
|
val classFile = fileFinder.findVirtualFileWithHeader(ClassId(jvmName.packageFqName, jvmName.fqNameForClassNameWithoutDollars.shortName())) ?: return null
|
||||||
|
return readDebugInfoForInlineFun(classFile.contentsToByteArray(), lineNumber, project)
|
||||||
|
}
|
||||||
|
|
||||||
if (!ProjectRootsUtil.isInContent(project, file, true, false, false)) return null
|
if (!ProjectRootsUtil.isInContent(project, file, true, false, false)) return null
|
||||||
|
|
||||||
val linesInFile = file.toPsiFile(project)?.getLineCount() ?: return null
|
val linesInFile = file.toPsiFile(project)?.getLineCount() ?: return null
|
||||||
@@ -81,7 +89,7 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter
|
|||||||
|
|
||||||
val classByByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir) ?: return null
|
val classByByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir) ?: return null
|
||||||
|
|
||||||
return readDebugInfoForInlineFun(classByByDirectory, lineNumber, project)
|
return readDebugInfoForInlineFun(classByByDirectory.readBytes(), lineNumber, project)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findClassFileByPath(packageName: String, className: String, outputDir: VirtualFile): File? {
|
private fun findClassFileByPath(packageName: String, className: String, outputDir: VirtualFile): File? {
|
||||||
@@ -98,8 +106,8 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readDebugInfoForInlineFun(classFile: File, line: Int, project: Project): OpenFileHyperlinkInfo? {
|
private fun readDebugInfoForInlineFun(bytes: ByteArray, line: Int, project: Project): OpenFileHyperlinkInfo? {
|
||||||
val debugInfo = readDebugInfo(classFile) ?: return null
|
val debugInfo = readDebugInfo(bytes) ?: return null
|
||||||
|
|
||||||
val mappings = SMAPParser.parse(debugInfo)
|
val mappings = SMAPParser.parse(debugInfo)
|
||||||
|
|
||||||
@@ -112,8 +120,8 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter
|
|||||||
return OpenFileHyperlinkInfo(project, newSourceFile.virtualFile, mappingInfo.getIntervalIfContains(line)!!.map(line) - 1)
|
return OpenFileHyperlinkInfo(project, newSourceFile.virtualFile, mappingInfo.getIntervalIfContains(line)!!.map(line) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readDebugInfo(classFile: File): String? {
|
private fun readDebugInfo(bytes: ByteArray): String? {
|
||||||
val cr = ClassReader(classFile.readBytes());
|
val cr = ClassReader(bytes);
|
||||||
var debugInfo: String? = null
|
var debugInfo: String? = null
|
||||||
cr.accept(object : ClassVisitor(InlineCodegenUtil.API) {
|
cr.accept(object : ClassVisitor(InlineCodegenUtil.API) {
|
||||||
override fun visitSource(source: String?, debug: String?) {
|
override fun visitSource(source: String?, debug: String?) {
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package inlineFunCallInLibrary
|
||||||
|
|
||||||
|
import inlineFunctionCall.*
|
||||||
|
|
||||||
|
fun box() {
|
||||||
|
call()
|
||||||
|
}
|
||||||
|
|
||||||
|
// WITH_MOCK_LIBRARY: true
|
||||||
|
// FILE: inlineFunInLibrary.kt
|
||||||
|
// LINE: 4
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package inlineFunFromLibrary
|
||||||
|
|
||||||
|
import inlineFunInLibrary.*
|
||||||
|
|
||||||
|
fun box() {
|
||||||
|
foo {
|
||||||
|
println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WITH_MOCK_LIBRARY: true
|
||||||
|
// FILE: inlineFunInLibrary.kt
|
||||||
|
// LINE: 4
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package inlineFunInLibrary
|
||||||
|
|
||||||
|
inline fun foo(f: () -> Unit) {
|
||||||
|
null!!
|
||||||
|
f()
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package inlineFunctionCall
|
||||||
|
|
||||||
|
import inlineFunInLibrary.*
|
||||||
|
|
||||||
|
fun call() {
|
||||||
|
foo {
|
||||||
|
println()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,11 +109,11 @@ public abstract class AbstractKotlinExceptionFilterTest: KotlinCodeInsightTestCa
|
|||||||
?: throw AssertionError("Couldn't find file: name = $expectedFileName")
|
?: throw AssertionError("Couldn't find file: name = $expectedFileName")
|
||||||
val expectedLineNumber = InTextDirectivesUtils.getPrefixedInt(fileText, "// LINE: ")!!
|
val expectedLineNumber = InTextDirectivesUtils.getPrefixedInt(fileText, "// LINE: ")!!
|
||||||
|
|
||||||
// TODO compare virtual files
|
|
||||||
assertEquals("Wrong fileName for line $stackTraceElement", expectedFileName, descriptor.file.name)
|
|
||||||
|
|
||||||
val document = FileDocumentManager.getInstance().getDocument(expectedVirtualFile)!!
|
val document = FileDocumentManager.getInstance().getDocument(expectedVirtualFile)!!
|
||||||
val expectedOffset = document.getLineStartOffset(expectedLineNumber - 1)
|
val expectedOffset = document.getLineStartOffset(expectedLineNumber - 1)
|
||||||
assertEquals("Wrong offset for line $stackTraceElement", expectedOffset, descriptor.offset)
|
|
||||||
|
// TODO compare virtual files
|
||||||
|
assertEquals("Wrong result for line $stackTraceElement", expectedFileName + ":" + expectedOffset, descriptor.file.name + ":" + descriptor.offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,30 @@ public class KotlinExceptionFilterTestGenerated extends AbstractKotlinExceptionF
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineFunCallInLibrary")
|
||||||
|
public void testInlineFunCallInLibrary() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunCallInLibrary/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineFunFromLibrary")
|
||||||
|
public void testInlineFunFromLibrary() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunFromLibrary/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineFunctionAnotherFile")
|
@TestMetadata("inlineFunctionAnotherFile")
|
||||||
public void testInlineFunctionAnotherFile() throws Exception {
|
public void testInlineFunctionAnotherFile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunctionAnotherFile/");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunctionAnotherFile/");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineFunctionInnerClass")
|
||||||
|
public void testInlineFunctionInnerClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunctionInnerClass/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineFunctionSameFile")
|
@TestMetadata("inlineFunctionSameFile")
|
||||||
public void testInlineFunctionSameFile() throws Exception {
|
public void testInlineFunctionSameFile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunctionSameFile/");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/exceptionFilter/inlineFunctionSameFile/");
|
||||||
|
|||||||
Reference in New Issue
Block a user