Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Source++, the open-source live coding platform.
* Copyright (C) 2022 CodeBrig, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spp.jetbrains.marker.js.presentation

import com.intellij.icons.AllIcons
import com.intellij.ide.projectView.PresentationData
import com.intellij.ui.SimpleTextAttributes
import com.intellij.ui.treeStructure.SimpleNode
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants
import spp.jetbrains.marker.presentation.LiveVariableNode
import spp.protocol.instrument.variable.LiveVariable
import spp.protocol.instrument.variable.LiveVariableScope

/**
* todo: description.
*
* @since 0.7.0
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
*/
@Suppress("MagicNumber")
class JavascriptVariableNode(
variable: LiveVariable,
nodeMap: MutableMap<String, Array<SimpleNode>>
) : LiveVariableNode(variable, nodeMap) {

override fun createVariableNode(
variable: LiveVariable,
nodeMap: MutableMap<String, Array<SimpleNode>>
): SimpleNode {
return JavascriptVariableNode(variable, nodeMap)
}

override fun update(presentation: PresentationData) {
if (variable.scope == LiveVariableScope.GENERATED_METHOD) {
presentation.addText(variable.name + " = ", SimpleTextAttributes.GRAYED_ATTRIBUTES)
presentation.setIcon(AllIcons.Nodes.Method)
} else {
presentation.addText(variable.name + " = ", XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES)
}

if (childCount > 0) {
presentation.setIcon(AllIcons.Nodes.Variable)
presentation.addText("todo", SimpleTextAttributes.REGULAR_ATTRIBUTES)
} else {
presentation.setIcon(AllIcons.Nodes.Field)
presentation.addText(variable.value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JavascriptVariableRootNode(
private val scheme = DebuggerUIUtil.getColorScheme(null)

override fun getChildren(): Array<SimpleNode> {
return variables.map { JavascriptVariableSimpleNode(it, mutableMapOf()) }.toTypedArray()
return variables.map { JavascriptVariableNode(it, mutableMapOf()) }.toTypedArray()
}

override fun update(presentation: PresentationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import com.intellij.openapi.editor.DefaultLanguageHighlighterColors.NUMBER
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors.STRING
import com.intellij.ui.SimpleTextAttributes.*
import com.intellij.ui.treeStructure.SimpleNode
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
import org.apache.commons.lang3.EnumUtils
import spp.jetbrains.marker.ErrorVariableSimpleNode
import spp.jetbrains.marker.presentation.LiveVariableNode
import spp.protocol.instrument.variable.LiveVariable
import spp.protocol.instrument.variable.LiveVariableScope

Expand All @@ -38,10 +36,10 @@ import spp.protocol.instrument.variable.LiveVariableScope
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
*/
@Suppress("MagicNumber")
class JVMVariableSimpleNode(
val variable: LiveVariable,
private val nodeMap: MutableMap<String, Array<SimpleNode>>
) : SimpleNode() {
class JVMVariableNode(
variable: LiveVariable,
nodeMap: MutableMap<String, Array<SimpleNode>>
) : LiveVariableNode(variable, nodeMap) {

private val primitives = setOf(
"java.lang.String",
Expand All @@ -62,50 +60,12 @@ class JVMVariableSimpleNode(
"java.lang.Float",
"java.lang.Double"
)
private val scheme = DebuggerUIUtil.getColorScheme(null)

override fun getChildren(): Array<SimpleNode> {
if (variable.value == null && variable.liveIdentity != null) {
//found reference, use children of referenced node
return nodeMap[variable.liveIdentity!!] ?: arrayOf()
}

val children = if (variable.value is JsonArray) {
(variable.value as JsonArray).map { JsonObject.mapFrom(it) }.map {
if (it.getString("@skip") != null) {
ErrorVariableSimpleNode(JsonObject.mapFrom(it).map)
} else {
JVMVariableSimpleNode(toLiveVariable(it), nodeMap)
}
}.toList().toTypedArray()
} else if (variable.value is LiveVariable) {
arrayOf(JVMVariableSimpleNode(variable.value as LiveVariable, nodeMap) as SimpleNode)
} else {
emptyArray()
}

//add children to nodeMap for reference lookup
if (variable.liveIdentity != null) {
nodeMap[variable.liveIdentity!!] = children
}
return children
}

private fun toLiveVariable(it: JsonObject): LiveVariable {
var varValue = it.getValue("value")
if (varValue is JsonArray && varValue.size() == 1 &&
(varValue.first() as JsonObject).containsKey("liveClazz")
) {
varValue = toLiveVariable(varValue.first() as JsonObject)
}
return LiveVariable(
name = it.getString("name"),
value = varValue,
lineNumber = it.getInteger("lineNumber") ?: -1,
scope = EnumUtils.getEnum(LiveVariableScope::class.java, it.getString("scope")),
liveClazz = it.getString("liveClazz"),
liveIdentity = it.getString("liveIdentity")
)
override fun createVariableNode(
variable: LiveVariable,
nodeMap: MutableMap<String, Array<SimpleNode>>
): SimpleNode {
return JVMVariableNode(variable, nodeMap)
}

override fun update(presentation: PresentationData) {
Expand Down Expand Up @@ -188,6 +148,4 @@ class JVMVariableSimpleNode(
}
}
}

override fun getEqualityObjects(): Array<Any> = arrayOf(variable)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import com.intellij.ide.projectView.PresentationData
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.ui.SimpleTextAttributes
import com.intellij.ui.treeStructure.SimpleNode
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants
import io.vertx.core.json.JsonObject
import spp.jetbrains.marker.presentation.LiveVariableNode
import spp.protocol.instrument.variable.LiveVariable

/**
Expand All @@ -32,9 +32,16 @@ import spp.protocol.instrument.variable.LiveVariable
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
*/
@Suppress("MagicNumber")
class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode() {
class PythonVariableNode(
variable: LiveVariable
) : LiveVariableNode(variable, mutableMapOf()) {

private val scheme = DebuggerUIUtil.getColorScheme(null)
override fun createVariableNode(
variable: LiveVariable,
nodeMap: MutableMap<String, Array<SimpleNode>>
): SimpleNode {
return PythonVariableNode(variable)
}

override fun getChildren(): Array<SimpleNode> {
if (variable.liveClazz == "<class 'dict'>") {
Expand All @@ -44,7 +51,7 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode(
)
val children = mutableListOf<SimpleNode>()
dict.map.forEach {
children.add(PythonVariableSimpleNode(LiveVariable("'" + it.key + "'", it.value)))
children.add(PythonVariableNode(LiveVariable("'" + it.key + "'", it.value)))
}
return children.toTypedArray()
}
Expand Down Expand Up @@ -74,6 +81,7 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode(
)
)
}

variable.liveClazz == "<class 'str'>" -> {
presentation.addText(
"\"" + variable.value + "\"",
Expand All @@ -82,6 +90,7 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode(
)
)
}

else -> {
presentation.addText(
variable.value.toString(),
Expand All @@ -92,6 +101,4 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode(
}
}
}

override fun getEqualityObjects(): Array<Any> = arrayOf(variable)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PythonVariableRootNode(val variables: List<LiveVariable>, val scope: LiveV
private val scheme = DebuggerUIUtil.getColorScheme(null)

override fun getChildren(): Array<SimpleNode> {
return variables.map { PythonVariableSimpleNode(it) }.toTypedArray()
return variables.map { PythonVariableNode(it) }.toTypedArray()
}

override fun update(presentation: PresentationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spp.jetbrains.marker.js.presentation
package spp.jetbrains.marker.presentation

import com.intellij.icons.AllIcons
import com.intellij.ide.projectView.PresentationData
import com.intellij.ui.SimpleTextAttributes
import com.intellij.ui.treeStructure.SimpleNode
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
import org.apache.commons.lang3.EnumUtils
Expand All @@ -35,17 +31,20 @@ import spp.protocol.instrument.variable.LiveVariableScope
* @since 0.7.0
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
*/
@Suppress("MagicNumber")
class JavascriptVariableSimpleNode(
private val variable: LiveVariable,
abstract class LiveVariableNode(
val variable: LiveVariable,
private val nodeMap: MutableMap<String, Array<SimpleNode>>
) : SimpleNode() {

private val scheme = DebuggerUIUtil.getColorScheme(null)
val scheme = DebuggerUIUtil.getColorScheme(null)

abstract fun createVariableNode(
variable: LiveVariable,
nodeMap: MutableMap<String, Array<SimpleNode>>
): SimpleNode

//todo: LiveSimpleNode super class
override fun getChildren(): Array<SimpleNode> {
if (variable.value == null && variable.liveIdentity != null) {
if (variable.liveIdentity != null && nodeMap.containsKey(variable.liveIdentity)) {
//found reference, use children of referenced node
return nodeMap[variable.liveIdentity!!] ?: arrayOf()
}
Expand All @@ -55,17 +54,17 @@ class JavascriptVariableSimpleNode(
if (it.getString("@skip") != null) {
ErrorVariableSimpleNode(JsonObject.mapFrom(it).map)
} else {
JavascriptVariableSimpleNode(toLiveVariable(it), nodeMap)
createVariableNode(toLiveVariable(it), nodeMap)
}
}.toList().toTypedArray()
} else if (variable.value is LiveVariable) {
arrayOf(JavascriptVariableSimpleNode(variable.value as LiveVariable, nodeMap) as SimpleNode)
arrayOf(createVariableNode(variable.value as LiveVariable, nodeMap))
} else {
emptyArray()
}

//add children to nodeMap for reference lookup
if (variable.liveIdentity != null) {
if (variable.liveIdentity != null && children.isNotEmpty()) {
nodeMap[variable.liveIdentity!!] = children
}
return children
Expand All @@ -88,22 +87,6 @@ class JavascriptVariableSimpleNode(
)
}

override fun update(presentation: PresentationData) {
if (variable.scope == LiveVariableScope.GENERATED_METHOD) {
presentation.addText(variable.name + " = ", SimpleTextAttributes.GRAYED_ATTRIBUTES)
presentation.setIcon(AllIcons.Nodes.Method)
} else {
presentation.addText(variable.name + " = ", XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES)
}

if (childCount > 0) {
presentation.setIcon(AllIcons.Nodes.Variable)
presentation.addText("todo", SimpleTextAttributes.REGULAR_ATTRIBUTES)
} else {
presentation.setIcon(AllIcons.Nodes.Field)
presentation.addText(variable.value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES)
}
}

override fun getEqualityObjects(): Array<Any> = arrayOf(variable)
override fun toString(): String = variable.name
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package spp.jetbrains.sourcemarker.service.instrument.breakpoint.tree
import com.intellij.ui.treeStructure.SimpleNode
import com.intellij.util.containers.hash.LinkedHashMap
import spp.jetbrains.marker.js.presentation.JavascriptVariableRootNode
import spp.jetbrains.marker.jvm.presentation.JVMVariableSimpleNode
import spp.jetbrains.marker.jvm.presentation.JVMVariableNode
import spp.jetbrains.marker.py.presentation.PythonVariableRootNode
import spp.jetbrains.sourcemarker.service.instrument.breakpoint.StackFrameManager
import spp.protocol.artifact.ArtifactLanguage
Expand Down Expand Up @@ -76,10 +76,11 @@ class VariableRootSimpleNode : SimpleNode() {
}

else -> {
val simpleNodeMap: MutableMap<String, JVMVariableSimpleNode> = LinkedHashMap()
val simpleNodeMap: MutableMap<String, JVMVariableNode> = LinkedHashMap()
val nodeReferenceMap = mutableMapOf<String, Array<SimpleNode>>()
vars.forEach {
if (it.name.isNotEmpty()) {
simpleNodeMap[it.name] = JVMVariableSimpleNode(it, mutableMapOf())
simpleNodeMap[it.name] = JVMVariableNode(it, nodeReferenceMap)
}
}
simpleNodeMap.values.sortedWith { p0, p1 ->
Expand Down