- /** append Java code to <tt>sb</tt> which evaluates to this instance */
- public void toJava(StringBuffer sb) {
- sb.append("new Tree(null, ");
- sb.append(head==null ? "null" : "\"" + StringUtil.toJavaString(head+"") + "\"");
- sb.append(", new Tree[] { ");
- for(int i=0; i<children.length; i++) {
- if (children[i]==null) sb.append("null");
- else children[i].toJava(sb);
- if (i<children.length-1) sb.append(",\n ");
- }
- sb.append("})");
+ protected String headToString() { return head==null?null:head.toString(); }
+ protected String headToJava() { return head==null?null:StringUtil.toJavaString(head+""); }
+ protected String left() { return "{"; }
+ protected String right() { return "}"; }
+ protected boolean ignoreSingleton() { return false; }
+
+ public GraphViz.Node toGraphViz(GraphViz gv) {
+ if (gv.hasNode(this)) return gv.createNode(this);
+ GraphViz.Node n = gv.createNode(this);
+ n.label = head()==null ? "" : head().toString();
+ //n.color = "red";
+ for(Tree t : this) n.edge(t, null);
+ return n;