mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Better variable display in debugger
This commit is contained in:
parent
0c4aeec667
commit
2d583dc7f4
|
@ -0,0 +1,41 @@
|
|||
package org.teavm.eclipse.debugger;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||
*/
|
||||
abstract class PropertyNameComparator<T> implements Comparator<T> {
|
||||
abstract String getName(T value);
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
String s1 = getName(o1);
|
||||
String s2 = getName(o2);
|
||||
boolean n1 = isNumber(s1);
|
||||
boolean n2 = isNumber(s2);
|
||||
if (n1 && n2) {
|
||||
return Integer.compare(Integer.parseInt(s1), Integer.parseInt(s2));
|
||||
} else if (n1) {
|
||||
return -1;
|
||||
} else if (n2) {
|
||||
return 1;
|
||||
} else {
|
||||
return s1.compareTo(s2);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNumber(String str) {
|
||||
if (str.length() > 9) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < str.length(); ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c < '0' || c > '9') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ public class TeaVMJSScope extends TeaVMVariable {
|
|||
private JavaScriptValue value;
|
||||
|
||||
public TeaVMJSScope(TeaVMDebugTarget debugTarget, String name, JavaScriptValue value) {
|
||||
super(debugTarget, new TeaVMJSValue(debugTarget, value));
|
||||
super(name, debugTarget, new TeaVMJSValue(name, debugTarget, value));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TeaVMJSStackFrame extends TeaVMStackFrame {
|
|||
super(thread);
|
||||
this.callFrame = callFrame;
|
||||
this.jsDebugger = jsDebugger;
|
||||
this.variablesHolder = new TeaVMJSVariablesHolder(thread.debugTarget, callFrame.getVariables().values(),
|
||||
this.variablesHolder = new TeaVMJSVariablesHolder("", thread.debugTarget, callFrame.getVariables().values(),
|
||||
callFrame.getThisVariable(), callFrame.getClosureVariable());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,9 @@ public class TeaVMJSValue extends TeaVMValue {
|
|||
private JavaScriptValue jsValue;
|
||||
private boolean innerStructure;
|
||||
|
||||
public TeaVMJSValue(TeaVMDebugTarget debugTarget, JavaScriptValue teavmValue) {
|
||||
super(debugTarget, new TeaVMJSVariablesHolder(debugTarget, teavmValue.getProperties().values(), null, null));
|
||||
public TeaVMJSValue(String id, TeaVMDebugTarget debugTarget, JavaScriptValue teavmValue) {
|
||||
super(id, debugTarget, new TeaVMJSVariablesHolder(id, debugTarget, teavmValue.getProperties().values(),
|
||||
null, null));
|
||||
this.jsValue = teavmValue;
|
||||
this.innerStructure = teavmValue.hasInnerStructure();
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ import org.teavm.debugging.javascript.JavaScriptVariable;
|
|||
public class TeaVMJSVariable extends TeaVMVariable {
|
||||
private JavaScriptVariable var;
|
||||
|
||||
public TeaVMJSVariable(TeaVMDebugTarget debugTarget, JavaScriptVariable var) {
|
||||
super(debugTarget, new TeaVMJSValue(debugTarget, var.getValue()));
|
||||
public TeaVMJSVariable(String id, TeaVMDebugTarget debugTarget, JavaScriptVariable var) {
|
||||
super(id, debugTarget, new TeaVMJSValue(id, debugTarget, var.getValue()));
|
||||
this.var = var;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,13 +24,16 @@ import org.teavm.debugging.javascript.JavaScriptVariable;
|
|||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||
*/
|
||||
public class TeaVMJSVariablesHolder extends TeaVMVariablesHolder {
|
||||
private String idPrefix;
|
||||
private TeaVMDebugTarget debugTarget;
|
||||
private Collection<JavaScriptVariable> teavmVariables;
|
||||
private JavaScriptValue thisScope;
|
||||
private JavaScriptValue closureScope;
|
||||
|
||||
public TeaVMJSVariablesHolder(TeaVMDebugTarget debugTarget, Collection<JavaScriptVariable> teavmVariables,
|
||||
public TeaVMJSVariablesHolder(String idPrefix, TeaVMDebugTarget debugTarget,
|
||||
Collection<JavaScriptVariable> teavmVariables,
|
||||
JavaScriptValue thisScope, JavaScriptValue closureScope) {
|
||||
this.idPrefix = idPrefix;
|
||||
this.debugTarget = debugTarget;
|
||||
this.teavmVariables = teavmVariables;
|
||||
this.thisScope = thisScope;
|
||||
|
@ -47,13 +50,14 @@ public class TeaVMJSVariablesHolder extends TeaVMVariablesHolder {
|
|||
variables.add(new TeaVMJSScope(debugTarget, "<closure>", closureScope));
|
||||
}
|
||||
List<JavaScriptVariable> teavmVarList = new ArrayList<>(teavmVariables);
|
||||
Collections.sort(teavmVarList, new Comparator<JavaScriptVariable>() {
|
||||
@Override public int compare(JavaScriptVariable o1, JavaScriptVariable o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
Collections.sort(teavmVarList, new PropertyNameComparator<JavaScriptVariable>() {
|
||||
@Override String getName(JavaScriptVariable value) {
|
||||
return value.getName();
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < teavmVarList.size(); ++i) {
|
||||
variables.add(new TeaVMJSVariable(debugTarget, teavmVarList.get(i)));
|
||||
JavaScriptVariable var = teavmVarList.get(i);
|
||||
variables.add(new TeaVMJSVariable(idPrefix + "." + var.getName(), debugTarget, var));
|
||||
}
|
||||
return variables.toArray(new TeaVMVariable[0]);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TeaVMJavaStackFrame extends TeaVMStackFrame {
|
|||
super(thread);
|
||||
this.callFrame = callFrame;
|
||||
this.teavmDebugger = teavmDebugger;
|
||||
this.variablesHolder = new TeaVMJavaVariablesHolder(thread.debugTarget, callFrame.getVariables().values());
|
||||
this.variablesHolder = new TeaVMJavaVariablesHolder("", thread.debugTarget, callFrame.getVariables().values());
|
||||
}
|
||||
|
||||
public CallFrame getCallFrame() {
|
||||
|
|
|
@ -26,8 +26,8 @@ public class TeaVMJavaValue extends TeaVMValue {
|
|||
private Value teavmValue;
|
||||
private boolean innerStructure;
|
||||
|
||||
public TeaVMJavaValue(TeaVMDebugTarget debugTarget, Value teavmValue) {
|
||||
super(debugTarget, new TeaVMJavaVariablesHolder(debugTarget, teavmValue.getProperties().values()));
|
||||
public TeaVMJavaValue(String id, TeaVMDebugTarget debugTarget, Value teavmValue) {
|
||||
super(id, debugTarget, new TeaVMJavaVariablesHolder(id, debugTarget, teavmValue.getProperties().values()));
|
||||
this.teavmValue = teavmValue;
|
||||
this.innerStructure = teavmValue.hasInnerStructure();
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ import org.teavm.debugging.Variable;
|
|||
public class TeaVMJavaVariable extends TeaVMVariable {
|
||||
private Variable var;
|
||||
|
||||
public TeaVMJavaVariable(TeaVMDebugTarget debugTarget, Variable var) {
|
||||
super(debugTarget, new TeaVMJavaValue(debugTarget, var.getValue()));
|
||||
public TeaVMJavaVariable(String id, TeaVMDebugTarget debugTarget, Variable var) {
|
||||
super(id, debugTarget, new TeaVMJavaValue(id, debugTarget, var.getValue()));
|
||||
this.var = var;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,10 +23,13 @@ import org.teavm.debugging.Variable;
|
|||
* @author Alexey Andreev
|
||||
*/
|
||||
public class TeaVMJavaVariablesHolder extends TeaVMVariablesHolder {
|
||||
private String idPrefix;
|
||||
private TeaVMDebugTarget debugTarget;
|
||||
private Collection<Variable> teavmVariables;
|
||||
|
||||
public TeaVMJavaVariablesHolder(TeaVMDebugTarget debugTarget, Collection<Variable> teavmVariables) {
|
||||
public TeaVMJavaVariablesHolder(String idPrefix, TeaVMDebugTarget debugTarget,
|
||||
Collection<Variable> teavmVariables) {
|
||||
this.idPrefix = idPrefix;
|
||||
this.debugTarget = debugTarget;
|
||||
this.teavmVariables = teavmVariables;
|
||||
}
|
||||
|
@ -35,13 +38,14 @@ public class TeaVMJavaVariablesHolder extends TeaVMVariablesHolder {
|
|||
protected TeaVMVariable[] createVariables() {
|
||||
TeaVMJavaVariable[] newVariables = new TeaVMJavaVariable[teavmVariables.size()];
|
||||
List<Variable> teavmVarList = new ArrayList<>(teavmVariables);
|
||||
Collections.sort(teavmVarList, new Comparator<Variable>() {
|
||||
@Override public int compare(Variable o1, Variable o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
Collections.sort(teavmVarList, new PropertyNameComparator<Variable>() {
|
||||
@Override String getName(Variable value) {
|
||||
return value.getName();
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < teavmVarList.size(); ++i) {
|
||||
newVariables[i] = new TeaVMJavaVariable(debugTarget, teavmVarList.get(i));
|
||||
Variable var = teavmVarList.get(i);
|
||||
newVariables[i] = new TeaVMJavaVariable(idPrefix + "." + var.getName(), debugTarget, var);
|
||||
}
|
||||
return newVariables;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ import org.eclipse.debug.core.model.IVariable;
|
|||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||
*/
|
||||
public abstract class TeaVMValue extends TeaVMDebugElement implements IValue {
|
||||
private String id;
|
||||
private TeaVMVariablesHolder variablesHolder;
|
||||
|
||||
public TeaVMValue(TeaVMDebugTarget debugTarget, TeaVMVariablesHolder variablesHolder) {
|
||||
public TeaVMValue(String id, TeaVMDebugTarget debugTarget, TeaVMVariablesHolder variablesHolder) {
|
||||
super(debugTarget);
|
||||
this.id = id;
|
||||
this.variablesHolder = variablesHolder;
|
||||
}
|
||||
|
||||
|
@ -42,4 +44,21 @@ public abstract class TeaVMValue extends TeaVMDebugElement implements IValue {
|
|||
}
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof TeaVMValue)) {
|
||||
return false;
|
||||
}
|
||||
TeaVMValue other = (TeaVMValue)obj;
|
||||
return id.equals(other.id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,12 @@ import org.teavm.eclipse.TeaVMEclipsePlugin;
|
|||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||
*/
|
||||
public abstract class TeaVMVariable extends TeaVMDebugElement implements IVariable {
|
||||
private String id;
|
||||
private TeaVMValue value;
|
||||
|
||||
public TeaVMVariable(TeaVMDebugTarget debugTarget, TeaVMValue value) {
|
||||
public TeaVMVariable(String id, TeaVMDebugTarget debugTarget, TeaVMValue value) {
|
||||
super(debugTarget);
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -67,4 +69,21 @@ public abstract class TeaVMVariable extends TeaVMDebugElement implements IVariab
|
|||
public boolean hasValueChanged() throws DebugException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof TeaVMVariable)) {
|
||||
return false;
|
||||
}
|
||||
TeaVMVariable other = (TeaVMVariable)obj;
|
||||
return id.equals(other.id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user