PATCH for JSWAT-3.12 for Display Modifiers
Paulo Ferreira <[email protected]> Sun, 17 Sep 2006 11:25:43 +0100
| Newsgroups | gmane.comp.java.jswat.devel |
|---|---|
| Message-ID | <[email protected]> |
--=-PJRtTQVf06/aljWEYVop
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi,
Here is the patch for the changes I made to the allow the Display
Modifiers.
This patch also includes also a change I didn't have in the previous
message (I included the possibility to also apply the modifiers to the
Evaluator Pane).
I hope this makes things easier for you.
Paulo
--=-PJRtTQVf06/aljWEYVop
Content-Disposition: attachment; filename=jswat-3.12-patch
Content-Type: text/x-patch; name=jswat-3.12-patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
diff -u ./original/EvaluatorPanel.java ./modified/EvaluatorPanel.java
--- ./original/EvaluatorPanel.java 2006-07-14 00:52:26.000000000 +0100
+++ ./modified/EvaluatorPanel.java 2006-09-17 10:48:32.000000000 +0100
@@ -75,6 +75,14 @@
int frame = dc.getFrame();
String expr = (String) expressionComboBox.getEditor().getItem();
+ String orgexpr = expr;
+ int nCommaPOS = expr.indexOf(",");
+ String mods = (nCommaPOS >= 0) ? expr.substring(nCommaPOS + 1)
+ .trim()
+ : null;
+ expr = (nCommaPOS > 0) ? expr.substring(0, nCommaPOS)
+ : ((nCommaPOS == 0) ? ""
+ : expr);
String msg = null;
Value result = null;
if (expr.length() == 0) {
@@ -117,7 +125,9 @@
node = new AbstractView.MessageNode("void");
} else {
VariableFactory vf = VariableFactory.getInstance();
- node = vf.create(expr, result.type().name(), result,
+ node = vf.create(orgexpr,((mods == null) || (mods.length() == 0))
+ ? null
+ : mods, result.type().name(), result,
VariableNode.Kind.LOCAL);
}
}
diff -u ./original/VariableFactory.java ./modified/VariableFactory.java
--- ./original/VariableFactory.java 2006-07-19 00:01:46.000000000 +0100
+++ ./modified/VariableFactory.java 2006-09-17 10:51:44.000000000 +0100
@@ -72,10 +72,23 @@
* @return instance of VariableNode.
*/
public VariableNode create(LocalVariable local, Value value) {
+ return create(local, value, null);
+ }
+
+ /**
+ * Creates a VariableNode from a local variable and its value.
+ *
+ * @param local a local variable.
+ * @param value its value.
+ * @param mods Display Modifiers
+ *
+ * @return instance of VariableNode.
+ */
+ public VariableNode create(LocalVariable local, Value value, String mods) {
// Value.type().name() returns actual type name.
// LocalVariable.typeName() returns declared type name.
- String tname = value != null ? value.type().name() : local.typeName();
- return create(local.name(), tname, value, VariableNode.Kind.LOCAL);
+ String tname = (value != null) ? value.type().name() : local.typeName();
+ return create(local.name(), mods, tname, value, VariableNode.Kind.LOCAL);
}
/**
@@ -86,12 +99,25 @@
* @return instance of VariableNode.
*/
public VariableNode create(Field field, Value value) {
+ return create(field, value, null);
+ }
+
+ /**
+ * Creates a VariableNode from a field and its value.
+ *
+ * @param field a field.
+ * @param value its value.
+ * @param mods Display Modifiers
+ *
+ * @return instance of VariableNode.
+ */
+ public VariableNode create(Field field, Value value, String mods) {
// Value.type().name() returns actual type name.
// Field.typeName() returns declared type name.
- String tname = value != null ? value.type().name() : field.typeName();
- VariableNode.Kind kind = field.isStatic() ?
- VariableNode.Kind.STATIC_FIELD : VariableNode.Kind.FIELD;
- VariableNode node = create(field.name(), tname, value, kind);
+ String tname = (value != null) ? value.type().name() : field.typeName();
+ VariableNode.Kind kind = field.isStatic() ? VariableNode.Kind.STATIC_FIELD
+ : VariableNode.Kind.FIELD;
+ VariableNode node = create(field.name(), mods, tname, value, kind);
node.setField(field);
return node;
}
@@ -103,8 +129,20 @@
* @return instance of VariableNode.
*/
public VariableNode create(ObjectReference obj) {
+ return create(obj, null);
+ }
+
+ /**
+ * Creates a VariableNode to represent 'this' object.
+ *
+ * @param obj the 'this' object.
+ * @param mods Display Modifiers
+ *
+ * @return instance of VariableNode.
+ */
+ public VariableNode create(ObjectReference obj, String mods) {
String tname = obj.referenceType().name();
- return create("this", tname, obj, VariableNode.Kind.THIS);
+ return create("this", mods, tname, obj, VariableNode.Kind.THIS);
}
/**
@@ -148,6 +186,46 @@
}
/**
+ * Creates a VariableNode based on name, type name, and value.
+ *
+ * @param name name of the variable.
+ * @param mods Display Modifiers
+ * @param type type of the variable.
+ * @param value value of the variable.
+ * @param kind kind of variable.
+ *
+ * @return instance of VariableNode.
+ */
+ public VariableNode create(String name, String mods, String type, Value value, VariableNode.Kind kind) {
+ // Shorten the class name to avoid ellipses.
+ type = Names.getShortClassName(type);
+ if(value instanceof StringReference) {
+ return new StringNode(name, mods, type, kind, (StringReference) value);
+ } else if(value instanceof ClassObjectReference) {
+ return new ClassObjectNode(name, mods, type, kind, (ClassObjectReference) value);
+ } else if(value instanceof ArrayReference) {
+ return new ArrayNode(name, mods, type, kind, (ArrayReference) value);
+ } else if(value instanceof ObjectReference) {
+ // Check what specific type of object this is and try to show
+ // it in a more informative fashion.
+ ObjectReference obj = (ObjectReference) value;
+ String cname = obj.referenceType().name();
+ if((cname.equals("java.lang.StringBuffer") ||
+ cname.equals("java.lang.StringBuilder")) &&
+ StringBufferNode.isValid(obj)) {
+ return new StringBufferNode(name, mods, type, kind, obj);
+ } else if(cname.equals("java.util.BitSet") && BitSetNode.isValid(obj)) {
+ return new BitSetNode(name, mods, type, kind, obj);
+ } else {
+ return new ObjectNode(name, mods, type, kind, obj);
+ }
+ } else {
+ // The value is either primitive, or null.
+ return new PrimitiveNode(name, mods, type, kind, (PrimitiveValue) value);
+ }
+ }
+
+ /**
* Returns the singleton instance of this factory.
*
* @return a VariableFactory instance.
@@ -174,9 +252,21 @@
* @param kind kind of variable.
* @param aref the ArrayReference.
*/
- public ArrayNode(String name, String type, VariableNode.Kind kind,
- ArrayReference aref) {
- super(new ANChildren(aref, 0, aref.length()), name, type, kind);
+ public ArrayNode(String name, String type, VariableNode.Kind kind, ArrayReference aref) {
+ this(name, null, type, kind, aref);
+ }
+
+ /**
+ * Creates a new ArrayNode object.
+ *
+ * @param name DOCUMENT ME!
+ * @param mods Display Modifiers
+ * @param type DOCUMENT ME!
+ * @param kind DOCUMENT ME!
+ * @param aref DOCUMENT ME!
+ */
+ public ArrayNode(String name, String mods, String type, VariableNode.Kind kind, ArrayReference aref) {
+ super(new ANChildren(aref, 0, aref.length()), name, mods, type, kind);
}
protected Sheet createSheet() {
@@ -201,11 +291,27 @@
*
* @param aref the array reference.
* @param offset starting position in array.
- * @param length length of array subet.
+ * @param length length of array subset.
+ */
+ public SubNode(ArrayReference aref,
+ int offset,
+ int length) {
+ this(aref, null, offset, length);
+ }
+
+ /**
+ * Creates a new SubNode object.
+ *
+ * @param aref DOCUMENT ME!
+ * @param mods Display Modifiers
*/
- public SubNode(ArrayReference aref, int offset, int length) {
+ public SubNode(ArrayReference aref,
+ String mods,
+ int offset,
+ int length) {
// Create a unique name for this node.
- super(new ANChildren(aref, offset, length), String.valueOf(offset),
+ super(new ANChildren(aref, offset, length),
+ String.valueOf(offset), mods,
aref.referenceType().name(), VariableNode.Kind.FIELD);
if (length > 1) {
// Minus one for conversion to relative indexing.
@@ -238,18 +344,37 @@
private int offset;
/** Length of the array subset. */
private int length;
+ /** Display Modifiers. */
+ private String modifiers;
+
+ /**
+ * Constructs a new instance of ANChildren.
+ *
+ * @param aref the ArrayReference.
+ * @param offset starting position in array.
+ * @param length length of array subset.
+ */
+ public ANChildren(ArrayReference aref,
+ int offset,
+ int length) {
+ this(aref, null, offset, length);
+ }
/**
* Constructs a new instance of ANChildren.
*
* @param aref the ArrayReference.
* @param offset starting position in array.
- * @param length length of array subet.
+ * @param length length of array subset.
*/
- public ANChildren(ArrayReference aref, int offset, int length) {
+ public ANChildren(ArrayReference aref,
+ String mods,
+ int offset,
+ int length) {
this.aref = aref;
this.offset = offset;
this.length = length;
+ this.modifiers = mods;
}
protected void addNotify() {
@@ -266,7 +391,7 @@
int last = offset + length;
while (first < last) {
int size = Math.min(last - first, GROUPING_SIZE);
- Node n = new SubNode(aref, first, size);
+ Node n = new SubNode(aref, modifiers, first, size);
kids.add(n);
first += GROUPING_SIZE;
}
@@ -282,8 +407,9 @@
// Otherwise, just show the declared element type.
type = arrayType;
}
- VariableNode vn = vf.create("[" + ii + "]", type,
- value, VariableNode.Kind.FIELD);
+
+ VariableNode vn = vf.create("[" + ii + "]", modifiers, type, value,
+ VariableNode.Kind.FIELD);
kids.add(vn);
}
}
@@ -315,9 +441,21 @@
* @param kind kind of variable.
* @param cref the ClassObjectReference.
*/
- public ClassObjectNode(String name, String type, VariableNode.Kind kind,
- ClassObjectReference cref) {
- super(new CNChildren(cref), name, type, kind);
+ public ClassObjectNode(String name, String type, VariableNode.Kind kind, ClassObjectReference cref) {
+ this(name, null, type, kind, cref);
+ }
+
+ /**
+ * Constructs a new instance of ClassObjectNode.
+ *
+ * @param name name of variable.
+ * @param mods Display Modifiers
+ * @param type type of variable.
+ * @param kind kind of variable.
+ * @param cref the ClassObjectReference.
+ */
+ public ClassObjectNode(String name, String mods, String type, VariableNode.Kind kind, ClassObjectReference cref) {
+ super(new CNChildren(cref, mods), name, mods, type, kind);
this.cref = cref;
}
@@ -337,6 +475,8 @@
private static class CNChildren extends Children.SortedArray {
/** The object reference. */
private ClassObjectReference cref;
+ /** Display Modifiers. */
+ private String modifiers;
/**
* Constructs a new instance of CNChildren.
@@ -344,7 +484,18 @@
* @param cref the ClassObjectReference.
*/
public CNChildren(ClassObjectReference cref) {
+ this(cref, null);
+ }
+
+ /**
+ * Constructs a new instance of CNChildren.
+ *
+ * @param cref the ClassObjectReference.
+ * @param mods Display Modifiers
+ */
+ public CNChildren(ClassObjectReference cref, String mods) {
this.cref = cref;
+ this.modifiers = mods;
}
protected void addNotify() {
@@ -360,7 +511,7 @@
for (Field field : fields) {
if (field.isStatic()) {
Value value = type.getValue(field);
- VariableNode vn = vf.create(field, value);
+ VariableNode vn = vf.create(field, value, modifiers);
vn.setObjectReference(cref);
kids.add(vn);
}
@@ -394,9 +545,21 @@
* @param kind kind of variable.
* @param oref the ObjectReference.
*/
- public ObjectNode(String name, String type, VariableNode.Kind kind,
- ObjectReference oref) {
- super(new ONChildren(oref), name, type, kind);
+ public ObjectNode(String name, String type, VariableNode.Kind kind, ObjectReference oref) {
+ this(name, null, type, kind, oref);
+ }
+
+ /**
+ * Creates a new ObjectNode object.
+ *
+ * @param name name of variable.
+ * @param mods Display Modifiers
+ * @param type type of variable.
+ * @param kind kind of variable.
+ * @param oref the ObjectReference.
+ */
+ public ObjectNode(String name, String mods, String type, VariableNode.Kind kind, ObjectReference oref) {
+ super(new ONChildren(oref, mods), name, mods, type, kind);
this.oref = oref;
}
@@ -416,6 +579,8 @@
private static class ONChildren extends Children.SortedArray {
/** The object reference. */
private ObjectReference oref;
+ /** Display Modifiers. */
+ private String modifiers;
/**
* Constructs a new instance of ONChildren.
@@ -423,7 +588,18 @@
* @param oref the ObjectReference.
*/
public ONChildren(ObjectReference oref) {
+ this(oref, null);
+ }
+
+ /**
+ * Constructs a new instance of ONChildren.
+ *
+ * @param oref the ObjectReference.
+ * @param mods Display Modifiers
+ */
+ public ONChildren(ObjectReference oref, String mods) {
this.oref = oref;
+ this.modifiers = mods;
}
protected void addNotify() {
@@ -436,7 +612,7 @@
List<Field> fields = oref.referenceType().visibleFields();
for (Field field : fields) {
Value value = oref.getValue(field);
- VariableNode vn = vf.create(field, value);
+ VariableNode vn = vf.create(field, value, modifiers);
vn.setObjectReference(oref);
kids.add(vn);
}
@@ -468,15 +644,29 @@
* @param kind kind of variable.
* @param pval the PrimitiveValue (may be null).
*/
- public PrimitiveNode(String name, String type, VariableNode.Kind kind,
- PrimitiveValue pval) {
- super(Children.LEAF, name, type, kind);
+ public PrimitiveNode(String name, String type, VariableNode.Kind kind, PrimitiveValue pval) {
+ this(name, null, type, kind, pval);
+ }
+
+ /**
+ * Creates a new PrimitiveNode object.
+ *
+ * @param name name of variable.
+ * @param mods Display Modifiers
+ * @param type type of variable.
+ * @param kind kind of variable.
+ * @param pval the PrimitiveValue (may be null).
+ */
+ public PrimitiveNode(String name, String mods, String type, VariableNode.Kind kind, PrimitiveValue pval) {
+ super(Children.LEAF, name, mods, type, kind);
this.pval = pval;
}
protected Sheet createSheet() {
Sheet sheet = super.createSheet();
Sheet.Set set = sheet.get(Sheet.PROPERTIES);
+ String propvalue = "invalid";
+ if(modifiers == null) {
if (pval instanceof CharValue) {
CharValue cv = (CharValue) pval;
StringBuilder sb = new StringBuilder();
@@ -489,16 +679,70 @@
sb.append("(\\u");
sb.append(Strings.toHexString(cv.value()));
sb.append(')');
- set.put(createProperty(PROP_VALUE, sb.toString()));
+ propvalue = sb.toString();
} else if (pval != null) {
- set.put(createProperty(PROP_VALUE, pval.toString()));
+ propvalue = pval.toString();
+
+ set.put(createProperty(PROP_VALUE,
+ pval.toString()));
+ } else {
+ propvalue = "null";
+ }
} else {
- set.put(createProperty(PROP_VALUE, "null"));
+ propvalue = applyModifiers();
}
+
+ set.put(createProperty(PROP_VALUE, propvalue));
return sheet;
}
+
+ private String applyModifiers() {
+ if(pval != null) {
+ boolean bInteger = false;
+ long lValue = 0;
+ if(pval instanceof CharValue) {
+ CharValue cv = (CharValue) pval;
+ if((modifiers.indexOf('u') >= 0) ||
+ Character.isISOControl(cv.charValue())) { // Display Unicode for character
+ return "(\\u" + Strings.toHexString(cv.value()) + ')';
+ } else if(modifiers.indexOf('s') < 0) { // 's' is of higher priority than either 'xbo'
+ lValue = cv.longValue();
+ bInteger = true;
+ }
+ } else if(pval instanceof ByteValue) {
+ lValue = ((ByteValue) pval).longValue();
+ bInteger = true;
+ } else if(pval instanceof ShortValue) {
+ lValue = ((ShortValue) pval).longValue();
+ bInteger = true;
+ } else if(pval instanceof IntegerValue) {
+ lValue = ((IntegerValue) pval).longValue();
+ bInteger = true;
+ } else if(pval instanceof LongValue) {
+ lValue = ((LongValue) pval).longValue();
+ bInteger = true;
}
+ if(bInteger) {
+ if(modifiers.indexOf('x') >= 0) {
+ return "0x" + Long.toHexString(lValue)
+ .toUpperCase();
+ } else if(modifiers.indexOf('o') >= 0) {
+ return "0" + Long.toOctalString(lValue);
+ } else if(modifiers.indexOf('b') >= 0) {
+ return "b" + Long.toBinaryString(lValue);
+ }
+ }
+
+ // Unknown, Invalid or String Modifier - Default Display as String
+ return pval.toString();
+ } else {
+ return "null";
+ }
+ }
+}
+
+
/**
* Represents a StringReference.
*
@@ -516,9 +760,21 @@
* @param kind kind of variable.
* @param sref the StringReference.
*/
- public StringNode(String name, String type, VariableNode.Kind kind,
- StringReference sref) {
- super(Children.LEAF, name, type, kind);
+ public StringNode(String name, String type, VariableNode.Kind kind, StringReference sref) {
+ this(name, null, type, kind, sref);
+ }
+
+ /**
+ * Constructs a new instance of StringNode.
+ *
+ * @param name name of variable.
+ * @param mods Display Modifiers
+ * @param type type of variable.
+ * @param kind kind of variable.
+ * @param sref the StringReference.
+ */
+ public StringNode(String name, String mods, String type, VariableNode.Kind kind, StringReference sref) {
+ super(Children.LEAF, name, mods, type, kind);
this.sref = sref;
}
@@ -547,9 +803,21 @@
* @param kind kind of variable.
* @param sref the StringReference.
*/
- public StringBufferNode(String name, String type, VariableNode.Kind kind,
- ObjectReference oref) {
- super(Children.LEAF, name, type, kind);
+ public StringBufferNode(String name, String type, VariableNode.Kind kind, ObjectReference oref) {
+ this(name, null, type, kind, oref);
+ }
+
+ /**
+ * Constructs a new instance of StringBufferNode.
+ *
+ * @param name name of variable.
+ * @param mods Display Modifiers
+ * @param type type of variable.
+ * @param kind kind of variable.
+ * @param sref the StringReference.
+ */
+ public StringBufferNode(String name, String mods, String type, VariableNode.Kind kind, ObjectReference oref) {
+ super(Children.LEAF, name, mods, type, kind);
this.oref = oref;
}
@@ -624,8 +892,20 @@
* @param kind kind of variable.
* @param sref the StringReference.
*/
- public BitSetNode(String name, String type, VariableNode.Kind kind,
- ObjectReference oref) {
+ public BitSetNode(String name, String type, VariableNode.Kind kind, ObjectReference oref) {
+ this(name, null, type, kind, oref);
+ }
+
+ /**
+ * Creates a new BitSetNode object.
+ *
+ * @param name name of variable.
+ * @param mods Display Modifiers
+ * @param type type of variable.
+ * @param kind kind of variable.
+ * @param sref the StringReference.
+ */
+ public BitSetNode(String name, String mods, String type, VariableNode.Kind kind, ObjectReference oref) {
super(Children.LEAF, name, type, kind);
this.oref = oref;
}
diff -u ./original/VariableNode.java ./modified/VariableNode.java
--- ./original/VariableNode.java 2006-07-20 00:28:38.000000000 +0100
+++ ./modified/VariableNode.java 2006-09-17 10:52:37.000000000 +0100
@@ -62,6 +62,8 @@
protected static final String PROP_TYPE = "type";
/** Name of the value property. */
protected static final String PROP_VALUE = "value";
+ /** Display Modifiers. */
+ protected String modifiers;
/** The name of the variable. */
private String name;
/** The type of the variable. */
@@ -83,12 +85,35 @@
* @param type type of the variable.
* @param kind kind of variable.
*/
- public VariableNode(Children kids, String name, String type, Kind kind) {
+ public VariableNode(Children kids,
+ String name,
+ String type,
+ Kind kind)
+ {
+ this(kids, name, null, type, kind);
+ }
+
+/**
+ * Constructs a VariableNode to represent the given class loader.
+ *
+ * @param kids children of this node.
+ * @param name name of the variable.
+ * @param type type of the variable.
+ * @param kind kind of variable.
+ */
+ public VariableNode(Children kids,
+ String name,
+ String mods,
+ String type,
+ Kind kind)
+ {
super(kids);
this.name = name;
this.type = type;
this.kind = kind;
- nodeActions = new Action[] {
+ this.modifiers = mods;
+ nodeActions = new Action[]
+ {
SystemAction.get(BreakpointAction.class),
SystemAction.get(WatchAction.class),
};
diff -u ./original/WatchesView.java ./modified/WatchesView.java
--- ./original/WatchesView.java 2006-07-18 01:47:44.000000000 +0100
+++ ./modified/WatchesView.java 2006-09-17 10:53:17.000000000 +0100
@@ -303,6 +303,12 @@
private Node evaluate(String expr, ThreadReference thread, int frame) {
String msg = null;
Value result = null;
+
+ String orgexpr = expr;
+ int nCommaPOS = expr.indexOf(",");
+ String modifiers = (nCommaPOS >= 0) ? expr.substring(nCommaPOS + 1).trim() : null;
+ expr = (nCommaPOS > 0) ? expr.substring(0, nCommaPOS) : ((nCommaPOS == 0) ? "" : expr);
+
if (expr.length() == 0) {
msg = "";
} else {
@@ -333,14 +339,14 @@
Node node = null;
if (msg != null) {
- node = new ExpressionNode(expr, msg);
+ node = new ExpressionNode(orgexpr, msg);
} else if (result != null) {
if (result instanceof VoidValue) {
- node = new ExpressionNode(expr, "void");
+ node = new ExpressionNode(orgexpr, "void");
} else {
VariableFactory vf = VariableFactory.getInstance();
- node = vf.create(expr, result.type().name(), result,
- VariableNode.Kind.LOCAL);
+ node = vf.create(orgexpr, ((sModifiers == null) || (sModifiers.length() == 0)) ? null : sModifiers,
+ result.type().name(), result, VariableNode.Kind.LOCAL);
}
}
return node;
--=-PJRtTQVf06/aljWEYVop
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
jswat-dev mailing list
[email protected]
http://www.bluemarsh.com/mailman/listinfo/jswat-dev
--=-PJRtTQVf06/aljWEYVop--