When a value in debugger represents plain JavaScript object, show its native fields in watch window

This commit is contained in:
Alexey Andreev 2018-01-08 14:45:46 +03:00
parent 2ae6c872db
commit 10c706077a
4 changed files with 72 additions and 2 deletions

View File

@ -57,4 +57,8 @@ public class Value {
} }
return jsValue.getInstanceId(); return jsValue.getInstanceId();
} }
public JavaScriptValue getOriginalValue() {
return jsValue;
}
} }

View File

@ -0,0 +1,58 @@
/*
* Copyright 2018 Alexey Andreev.
*
* 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 org.teavm.idea.debug;
import com.intellij.util.PlatformIcons;
import com.intellij.xdebugger.frame.XCompositeNode;
import com.intellij.xdebugger.frame.XNamedValue;
import com.intellij.xdebugger.frame.XValueChildrenList;
import com.intellij.xdebugger.frame.XValueNode;
import com.intellij.xdebugger.frame.XValuePlace;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
import org.teavm.debugging.javascript.JavaScriptValue;
import org.teavm.debugging.javascript.JavaScriptVariable;
public class TeaVMOriginalValue extends XNamedValue {
private boolean root;
private JavaScriptValue innerValue;
public TeaVMOriginalValue(@NotNull String name, boolean root, JavaScriptValue innerValue) {
super(name);
this.root = root;
this.innerValue = innerValue;
}
@Override
public void computePresentation(@NotNull XValueNode node, @NotNull XValuePlace place) {
Icon icon = root ? PlatformIcons.VARIABLE_ICON : PlatformIcons.FIELD_ICON;
String representation = innerValue.getRepresentation();
if (representation == null) {
representation = "null";
}
node.setPresentation(icon, innerValue.getClassName(), representation, !innerValue.getProperties().isEmpty());
}
@Override
public void computeChildren(@NotNull XCompositeNode node) {
XValueChildrenList children = new XValueChildrenList();
for (JavaScriptVariable variable : innerValue.getProperties().values()) {
children.add(new TeaVMOriginalValue(variable.getName(), false, variable.getValue()));
}
node.addChildren(children, true);
}
}

View File

@ -20,11 +20,13 @@ import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.xdebugger.XDebuggerUtil; import com.intellij.xdebugger.XDebuggerUtil;
import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.frame.XCompositeNode; import com.intellij.xdebugger.frame.XCompositeNode;
import com.intellij.xdebugger.frame.XNamedValue;
import com.intellij.xdebugger.frame.XStackFrame; import com.intellij.xdebugger.frame.XStackFrame;
import com.intellij.xdebugger.frame.XValueChildrenList; import com.intellij.xdebugger.frame.XValueChildrenList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.teavm.debugging.CallFrame; import org.teavm.debugging.CallFrame;
import org.teavm.debugging.Value;
import org.teavm.debugging.Variable; import org.teavm.debugging.Variable;
import org.teavm.debugging.information.SourceLocation; import org.teavm.debugging.information.SourceLocation;
import org.teavm.debugging.javascript.JavaScriptCallFrame; import org.teavm.debugging.javascript.JavaScriptCallFrame;
@ -74,8 +76,14 @@ class TeaVMStackFrame extends XStackFrame {
public void computeChildren(@NotNull XCompositeNode node) { public void computeChildren(@NotNull XCompositeNode node) {
XValueChildrenList children = new XValueChildrenList(); XValueChildrenList children = new XValueChildrenList();
for (Variable variable : innerFrame.getVariables().values()) { for (Variable variable : innerFrame.getVariables().values()) {
children.add(new TeaVMValue(variable.getName(), true, variable.getValue())); children.add(createValueNode(variable.getName(), true, variable.getValue()));
} }
node.addChildren(children, true); node.addChildren(children, true);
} }
static XNamedValue createValueNode(String name, boolean root, Value value) {
return !value.getType().startsWith("@")
? new TeaVMValue(name, root, value)
: new TeaVMOriginalValue(name, root, value.getOriginalValue());
}
} }

View File

@ -92,7 +92,7 @@ public class TeaVMValue extends XNamedValue {
public void computeChildren(@NotNull XCompositeNode node) { public void computeChildren(@NotNull XCompositeNode node) {
XValueChildrenList children = new XValueChildrenList(); XValueChildrenList children = new XValueChildrenList();
for (Variable variable : innerValue.getProperties().values()) { for (Variable variable : innerValue.getProperties().values()) {
children.add(new TeaVMValue(variable.getName(), true, variable.getValue())); children.add(TeaVMStackFrame.createValueNode(variable.getName(), false, variable.getValue()));
} }
node.addChildren(children, true); node.addChildren(children, true);
} }