1 22 23 package org.jboss.annotation.factory.ast; 24 25 public class SimpleNode implements Node { 26 protected Node parent; 27 protected Node[] children; 28 protected int id; 29 protected AnnotationParser parser; 30 31 public SimpleNode(int i) { 32 id = i; 33 } 34 35 public SimpleNode(AnnotationParser p, int i) { 36 this(i); 37 parser = p; 38 } 39 40 public void jjtOpen() { 41 } 42 43 public void jjtClose() { 44 } 45 46 public void jjtSetParent(Node n) { parent = n; } 47 public Node jjtGetParent() { return parent; } 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 69 public Object jjtAccept(AnnotationParserVisitor visitor, Object data) { 70 return visitor.visit(this, data); 71 } 72 73 74 public Object childrenAccept(AnnotationParserVisitor visitor, Object data) { 75 if (children != null) { 76 for (int i = 0; i < children.length; ++i) { 77 children[i].jjtAccept(visitor, data); 78 } 79 } 80 return data; 81 } 82 83 88 89 public String toString() { return AnnotationParserTreeConstants.jjtNodeName[id]; } 90 public String toString(String prefix) { return prefix + toString(); } 91 92 94 95 public void dump(String prefix) { 96 System.out.println(toString(prefix)); 97 if (children != null) { 98 for (int i = 0; i < children.length; ++i) { 99 SimpleNode n = (SimpleNode)children[i]; 100 if (n != null) { 101 n.dump(prefix + " "); 102 } 103 } 104 } 105 } 106 } 107 108 | Popular Tags |