1 4 5 6 7 package com.tc.aspectwerkz.expression.ast; 8 9 public class SimpleNode implements Node { 10 protected Node parent; 11 12 protected Node[] children; 13 14 protected int id; 15 16 protected ExpressionParser parser; 17 18 public SimpleNode(int i) { 19 id = i; 20 } 21 22 public SimpleNode(ExpressionParser p, int i) { 23 this(i); 24 parser = p; 25 } 26 27 public void jjtOpen() { 28 } 29 30 public void jjtClose() { 31 } 32 33 public void jjtSetParent(Node n) { 34 parent = n; 35 } 36 37 public Node jjtGetParent() { 38 return parent; 39 } 40 41 public void jjtAddChild(Node n, int i) { 42 if (children == null) { 43 children = new Node[i + 1]; 44 } else if (i >= children.length) { 45 Node c[] = new Node[i + 1]; 46 System.arraycopy(children, 0, c, 0, children.length); 47 children = c; 48 } 49 children[i] = n; 50 } 51 52 public Node jjtGetChild(int i) { 53 return children[i]; 54 } 55 56 public int jjtGetNumChildren() { 57 return (children == null) ? 0 : children.length; 58 } 59 60 63 public Object jjtAccept(ExpressionParserVisitor visitor, Object data) { 64 return visitor.visit(this, data); 65 } 66 67 70 public Object childrenAccept(ExpressionParserVisitor visitor, Object data) { 71 if (children != null) { 72 for (int i = 0; i < children.length; ++i) { 73 children[i].jjtAccept(visitor, data); 74 } 75 } 76 return data; 77 } 78 79 84 85 public String toString() { 86 return ExpressionParserTreeConstants.jjtNodeName[id]; 87 } 88 89 public String toString(String prefix) { 90 return prefix + toString(); 91 } 92 93 96 97 public void dump(String prefix) { 98 System.out.println(toString(prefix)); 99 if (children != null) { 100 for (int i = 0; i < children.length; ++i) { 101 SimpleNode n = (SimpleNode) children[i]; 102 if (n != null) { 103 n.dump(prefix + " "); 104 } 105 } 106 } 107 } 108 } 109 110 | Popular Tags |