1 2 package org.ejen.ext.parsers.java_1_2; 23 24 import org.ejen.util.arl.ArlUtil; 26 27 34 public class SimpleNode implements Node { 35 protected Node parent; 36 protected Node[] children; 37 protected int id; 38 protected JavaParser parser; 39 protected Token first, last; 41 public SimpleNode(int i) { 43 id = i; 44 } 45 46 public SimpleNode(JavaParser p, int i) { 47 this(i); 48 parser = p; 49 } 50 51 public void jjtOpen() { 52 first = parser.getToken(1); 54 } 56 57 public void jjtClose() { 58 last = parser.getToken(0); 60 } 62 63 public void jjtSetParent(Node n) { 64 parent = n; 65 } 66 67 public Node jjtGetParent() { 68 return parent; 69 } 70 71 public void jjtAddChild(Node n, int i) { 72 if (children == null) { 73 children = new Node[i + 1]; 74 } else if (i >= children.length) { 75 Node c[] = new Node[i + 1]; 76 77 System.arraycopy(children, 0, c, 0, children.length); 78 children = c; 79 } 80 children[i] = n; 81 } 82 83 public Node jjtGetChild(int i) { 84 return children[i]; 85 } 86 87 public int jjtGetNumChildren() { 88 return (children == null) ? 0 : children.length; 89 } 90 91 96 public String toString() { 97 return JavaParserTreeConstants.jjtNodeName[id]; 98 } 99 100 public String toString(String prefix) { 101 return prefix + toString(); 102 } 103 104 106 public void dump(String prefix) { 107 System.out.println(toString(prefix)); 108 if (children != null) { 109 for (int i = 0; i < children.length; ++i) { 110 SimpleNode n = (SimpleNode) children[i]; 111 112 if (n != null) { 113 n.dump(prefix + " "); 114 } 115 } 116 } 117 } 118 119 153 public final void toNode(org.w3c.dom.Document doc, 154 org.w3c.dom.Node parent, 155 int nodesMap[], 156 int[] tokensMap, 157 boolean tokensPos) 158 throws org.w3c.dom.DOMException { 159 if (nodesMap[id] == ArlUtil.F_REMOVE) { 160 return; 161 } 162 if (nodesMap[id] == ArlUtil.F_ACCEPT) { 163 org.w3c.dom.Element elt = doc.createElement(JavaParserTreeConstants.jjtNodeName[id]); 164 165 elt.setAttribute("id", String.valueOf(id)); 166 parent.appendChild(elt); 167 parent = elt; 168 } 169 Token t = new Token(); 170 171 t.next = first; 172 if (children != null) { 173 for (int i = 0; i < children.length; i++) { 174 SimpleNode cn = (SimpleNode) (children[i]); 175 176 for (t = t.next; t != null && t != cn.first; t = t.next) { 177 t.toNode(doc, parent, tokensMap, tokensPos); 178 } 179 cn.toNode(doc, parent, nodesMap, tokensMap, tokensPos); 180 t = cn.last; 181 } 182 } 183 while (t != null && t != last) { 184 t = t.next; 185 if (t != null) { 186 t.toNode(doc, parent, tokensMap, tokensPos); 187 } 188 } 189 } 190 } 192
| Popular Tags
|