1 4 5 9 10 package org.openlaszlo.sc.parser; 11 import java.io.Serializable ; 12 13 public abstract class SimpleNode implements Node, Serializable { 14 protected final static Node[] noChildren = {}; 15 protected Node parent; 16 protected Node[] children = noChildren; 17 protected final int id; 18 protected Parser parser; 19 public String filename; public int beginLine, beginColumn; public String comment; 22 23 public SimpleNode(int i) { 24 id = i; 25 } 26 27 public SimpleNode(Parser p, int i) { 28 this(i); 29 parser = p; 30 } 31 32 public void jjtOpen() { 33 } 34 35 public void jjtClose() { 36 } 37 38 public void jjtSetParent(Node n) { parent = n; } 39 public Node jjtGetParent() { return parent; } 40 41 public void jjtAddChild(Node n, int i) { 42 if (i >= children.length) { 43 Node c[] = new Node[i + 1]; 44 System.arraycopy(children, 0, c, 0, children.length); 45 children = c; 46 } 47 children[i] = n; 48 } 49 50 public Node jjtGetChild(int i) { 51 return children[i]; 52 } 53 54 public int jjtGetNumChildren() { 55 return (children == null) ? 0 : children.length; 56 } 57 58 63 64 public String toString(String prefix) { return prefix + toString(); } 65 66 68 69 public void dump(String prefix) { 70 System.out.println(toString(prefix)); 71 if (children != null) { 72 for (int i = 0; i < children.length; ++i) { 73 SimpleNode n = (SimpleNode)children[i]; 74 if (n != null) { 75 n.dump(prefix + " "); 76 } 77 } 78 } 79 } 80 81 public void dump() { 82 dump(""); 83 } 84 85 87 public SimpleNode() { 88 this(0); 89 } 90 91 public String toString() { 92 String name = this.getClass().getName(); 93 if (name.lastIndexOf('.') >= 0) { 94 name = name.substring(name.lastIndexOf('.') + 1); 95 } 96 return name; 97 } 98 99 public Node[] getChildren() { 100 return children; 101 } 102 103 public void setChildren(Node[] children) { 104 this.children = children; 105 } 106 107 public Node __getitem__(int n) { 108 return jjtGetChild(n); 109 } 110 111 public int __len__() { 112 return jjtGetNumChildren(); 113 } 114 115 public boolean __nonzero__() { 116 return true; 117 } 118 119 123 public int getLineNumber() { 124 return beginLine; 125 } 126 127 public int getColumnNumber() { 128 return beginColumn; 129 } 130 131 public String getFilename() { 132 return filename; 133 } 134 135 public void setBeginLocation(String filename, int line, int column) { 136 this.filename = filename; 137 this.beginLine = line; 138 this.beginColumn = column; 139 } 140 141 public void setComment(String comment) { 142 this.comment = comment; 143 } 144 145 public String getComment() { 146 return this.comment; 147 } 148 } 149 | Popular Tags |