Debugger: implement getSourcePosition for fields
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.openapi.roots.libraries.LibraryUtil
|
||||
import org.jetbrains.jet.plugin.JetJdkAndLibraryProjectDescriptor
|
||||
import com.intellij.openapi.roots.JdkOrderEntry
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.debugger.SourcePosition
|
||||
|
||||
abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
|
||||
|
||||
@@ -54,25 +55,29 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
|
||||
}
|
||||
|
||||
val sourcePosition = PositionUtil.getSourcePosition(this)
|
||||
if (sourcePosition == null) {
|
||||
return@runReadAction println("SourcePosition is null", ProcessOutputTypes.SYSTEM)
|
||||
}
|
||||
|
||||
val virtualFile = sourcePosition.getFile().getVirtualFile()
|
||||
if (virtualFile == null) {
|
||||
return@runReadAction println("VirtualFile for position is null", ProcessOutputTypes.SYSTEM)
|
||||
}
|
||||
|
||||
val libraryEntry = LibraryUtil.findLibraryEntry(virtualFile, getProject())
|
||||
if (libraryEntry != null && (libraryEntry is JdkOrderEntry ||
|
||||
libraryEntry.getPresentableName() == JetJdkAndLibraryProjectDescriptor.LIBRARY_NAME)) {
|
||||
return@runReadAction println(FileUtil.getNameWithoutExtension(virtualFile.getName()) + ".!EXT!", ProcessOutputTypes.SYSTEM)
|
||||
}
|
||||
|
||||
println(virtualFile.getName() + ":" + sourcePosition.getLine(), ProcessOutputTypes.SYSTEM)
|
||||
println(renderSourcePosition(sourcePosition), ProcessOutputTypes.SYSTEM)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun renderSourcePosition(sourcePosition: SourcePosition?): String {
|
||||
if (sourcePosition == null) {
|
||||
return "null"
|
||||
}
|
||||
|
||||
val virtualFile = sourcePosition.getFile().getVirtualFile()
|
||||
if (virtualFile == null) {
|
||||
return "VirtualFile for position is null"
|
||||
}
|
||||
|
||||
val libraryEntry = LibraryUtil.findLibraryEntry(virtualFile, getProject())
|
||||
if (libraryEntry != null && (libraryEntry is JdkOrderEntry ||
|
||||
libraryEntry.getPresentableName() == JetJdkAndLibraryProjectDescriptor.LIBRARY_NAME)) {
|
||||
return FileUtil.getNameWithoutExtension(virtualFile.getName()) + ".!EXT!"
|
||||
}
|
||||
|
||||
return virtualFile.getName() + ":" + sourcePosition.getLine()
|
||||
}
|
||||
|
||||
protected fun finish() {
|
||||
onBreakpoint {
|
||||
resume(this)
|
||||
|
||||
+16
-4
@@ -58,8 +58,10 @@ import com.intellij.psi.PsiManager
|
||||
import com.intellij.debugger.DebuggerManagerEx
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.debugger.ui.tree.render.ClassRenderer
|
||||
import com.intellij.debugger.settings.NodeRendererSettings
|
||||
import com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl
|
||||
import com.intellij.debugger.impl.DebuggerContextImpl
|
||||
import com.intellij.debugger.SourcePosition
|
||||
|
||||
public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestBase() {
|
||||
private val logger = Logger.getLogger(javaClass<KotlinEvaluateExpressionCache>())!!
|
||||
@@ -221,13 +223,17 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
|
||||
invokeRatherLater(this) {
|
||||
tree.rebuild(debuggerContext)
|
||||
expandAll(tree, Runnable {
|
||||
PRINTER.printTree(tree)
|
||||
resume(this@printFrame)
|
||||
try {
|
||||
Printer(debuggerContext).printTree(tree)
|
||||
}
|
||||
finally {
|
||||
resume(this@printFrame)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private val PRINTER = object {
|
||||
private inner class Printer(val debuggerContext: DebuggerContextImpl) {
|
||||
fun printTree(tree: DebuggerTree) {
|
||||
val root = tree.getMutableModel()!!.getRoot() as DebuggerTreeNodeImpl
|
||||
printNode(root, 0)
|
||||
@@ -246,6 +252,8 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
|
||||
is LocalVariableDescriptor -> logDescriptor(descriptor, "$curIndent local = $label\n")
|
||||
is StaticDescriptor -> logDescriptor(descriptor, "$curIndent static = $label\n")
|
||||
is ThisDescriptorImpl -> logDescriptor(descriptor, "$curIndent this = $label\n")
|
||||
is FieldDescriptorImpl -> logDescriptor(descriptor, "$curIndent field = $label"
|
||||
+ " (sp = ${render(descriptor.getSourcePosition(myProject, debuggerContext))})\n")
|
||||
is FieldDescriptor -> logDescriptor(descriptor, "$curIndent field = $label\n")
|
||||
else -> logDescriptor(descriptor, "$curIndent unknown = $label\n")
|
||||
}
|
||||
@@ -259,6 +267,10 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
|
||||
printNode(e.nextElement() as DebuggerTreeNodeImpl, indent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(sp: SourcePosition?): String {
|
||||
return renderSourcePosition(sp).replace(":", ", ")
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkExceptions(exceptions: MutableMap<String, Throwable>) {
|
||||
|
||||
Reference in New Issue
Block a user