1 2 3 package org.objectweb.speedo.query.parser; 4 5 import org.objectweb.speedo.query.parser.SpeedoQLTreeConstants; 6 import org.objectweb.speedo.query.parser.SpeedoQL; 7 import org.objectweb.speedo.query.parser.Node; 8 import org.objectweb.speedo.query.parser.SpeedoQLVisitor; 9 import org.objectweb.speedo.query.parser.SpeedoQLConstants; 10 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 14 public class SimpleNode implements Node { 15 protected Node parent; 16 protected Node[] children; 17 protected int id; 18 protected SpeedoQL parser; 19 20 public ArrayList ops = new ArrayList (); public Object value = null; 23 25 26 public SimpleNode(int i) { 27 id = i; 28 } 29 30 public SimpleNode(SpeedoQL p, int i) { 31 this(i); 32 parser = p; 33 } 34 35 public void jjtOpen() { 36 } 37 38 public void jjtClose() { 39 } 40 41 public void jjtSetParent(Node n) { 42 parent = n; 43 } 44 45 public Node jjtGetParent() { 46 return parent; 47 } 48 49 public void jjtAddChild(Node n, int i) { 50 if (children == null) { 51 children = new Node[i + 1]; 52 } else if (i >= children.length) { 53 Node c[] = new Node[i + 1]; 54 System.arraycopy(children, 0, c, 0, children.length); 55 children = c; 56 } 57 children[i] = n; 58 } 59 60 public Node jjtGetChild(int i) { 61 return children[i]; 62 } 63 64 public int jjtGetNumChildren() { 65 return (children == null) ? 0 : children.length; 66 } 67 68 73 74 public String toString() { 75 String ret = ""; 76 77 if (ops.size() != 0) { 78 ret += "("; 79 for (Iterator i = ops.iterator(); i.hasNext();) { 80 String token = SpeedoQLConstants.tokenImage[((Integer ) i.next()).intValue()]; 81 ret += token.substring(1, token.length() - 1) + ","; 82 } 84 ret = ret.substring(0, ret.length() - 1); 85 } 86 if (value != null) ret += "value=[" + value + "]"; 87 if (ops.size() != 0) ret += ")"; 88 return SpeedoQLTreeConstants.jjtNodeName[id] + " " + ret; 89 } 90 91 public String toString(String prefix) { 92 return prefix + toString(); 93 } 94 95 97 98 public void dump(String prefix) { 99 System.out.println(toString(prefix)); 100 if (children != null) { 101 for (int i = 0; i < children.length; ++i) { 102 SimpleNode n = (SimpleNode) children[i]; 103 if (n != null) { 104 n.dump(prefix + " "); 105 } 106 } 107 } 108 } 109 110 111 public Object jjtAccept(SpeedoQLVisitor visitor, Object data) { 112 return visitor.visit(this, data); 113 } 114 115 116 public Object childrenAccept(SpeedoQLVisitor visitor, Object data) { 117 if (children != null) { 118 for (int i = 0; i < children.length; ++i) { 119 children[i].jjtAccept(visitor, data); 120 } 121 } 122 return data; 123 } 124 } 125 126 | Popular Tags |