1 2 3 package org.jboss.aop.annotation.ast; 4 5 public class SimpleNode implements Node { 6 protected Node parent; 7 protected Node[] children; 8 protected int id; 9 protected AnnotationParser parser; 10 11 public SimpleNode(int i) { 12 id = i; 13 } 14 15 public SimpleNode(AnnotationParser p, int i) { 16 this(i); 17 parser = p; 18 } 19 20 public void jjtOpen() { 21 } 22 23 public void jjtClose() { 24 } 25 26 public void jjtSetParent(Node n) { parent = n; } 27 public Node jjtGetParent() { return parent; } 28 29 public void jjtAddChild(Node n, int i) { 30 if (children == null) { 31 children = new Node[i + 1]; 32 } else if (i >= children.length) { 33 Node c[] = new Node[i + 1]; 34 System.arraycopy(children, 0, c, 0, children.length); 35 children = c; 36 } 37 children[i] = n; 38 } 39 40 public Node jjtGetChild(int i) { 41 return children[i]; 42 } 43 44 public int jjtGetNumChildren() { 45 return (children == null) ? 0 : children.length; 46 } 47 48 49 public Object jjtAccept(AnnotationParserVisitor visitor, Object data) { 50 return visitor.visit(this, data); 51 } 52 53 54 public Object childrenAccept(AnnotationParserVisitor visitor, Object data) { 55 if (children != null) { 56 for (int i = 0; i < children.length; ++i) { 57 children[i].jjtAccept(visitor, data); 58 } 59 } 60 return data; 61 } 62 63 68 69 public String toString() { return AnnotationParserTreeConstants.jjtNodeName[id]; } 70 public String toString(String prefix) { return prefix + toString(); } 71 72 74 75 public void dump(String prefix) { 76 System.out.println(toString(prefix)); 77 if (children != null) { 78 for (int i = 0; i < children.length; ++i) { 79 SimpleNode n = (SimpleNode)children[i]; 80 if (n != null) { 81 n.dump(prefix + " "); 82 } 83 } 84 } 85 } 86 } 87 88 | Popular Tags |