View Javadoc
1 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */ 2 package net.sourceforge.pmd.ast; 3 4 import net.sourceforge.pmd.symboltable.Scope; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class SimpleNode implements Node { 10 protected Node parent; 11 protected Node[] children; 12 protected int id; 13 protected JavaParser parser; 14 private String image; 15 private int beginLine = -1; 16 private int endLine; 17 private int beginColumn = -1; 18 private int endColumn; 19 private Scope scope; 20 21 public SimpleNode(int i) { 22 id = i; 23 } 24 25 public SimpleNode(JavaParser p, int i) { 26 this(i); 27 parser = p; 28 } 29 30 public void jjtOpen() { 31 if (beginLine == -1 && parser.token.next != null) { 32 beginLine = parser.token.next.beginLine; 33 beginColumn = parser.token.next.beginColumn; 34 } 35 } 36 37 public void jjtClose() { 38 if (beginLine == -1 && (children == null || children.length == 0)) { 39 beginLine = parser.token.beginLine; 40 beginColumn = parser.token.beginColumn; 41 } 42 endLine = parser.token.endLine; 43 endColumn = parser.token.endColumn; 44 } 45 46 public void setScope(Scope scope) { 47 this.scope = scope; 48 } 49 50 public Scope getScope() { 51 if (scope == null) { 52 return ((SimpleNode) parent).getScope(); 53 } 54 return scope; 55 } 56 57 public int getBeginLine() { 58 return beginLine; 59 } 60 61 public void testingOnly__setBeginLine(int i) { 62 this.beginLine = i; 63 } 64 65 public void testingOnly__setBeginColumn(int i) { 66 this.beginColumn = i; 67 } 68 69 public int getBeginColumn() { 70 if (beginColumn != -1) { 71 return beginColumn; 72 } else { 73 if ((children != null) && (children.length > 0)) { 74 return ((SimpleNode) children[0]).getBeginColumn(); 75 } else { 76 throw new RuntimeException("Unable to determine begining line of Node."); 77 } 78 } 79 } 80 81 public String getImage() { 82 return image; 83 } 84 85 public void setImage(String image) { 86 this.image = image; 87 } 88 89 public int getEndLine() { 90 return endLine; 91 } 92 93 public int getEndColumn() { 94 return endColumn; 95 } 96 97 public List findChildrenOfType(Class targetType) { 98 List list = new ArrayList(); 99 findChildrenOfType(targetType, list); 100 return list; 101 } 102 103 public void findChildrenOfType(Class targetType, List results) { 104 findChildrenOfType(this, targetType, results, true); 105 } 106 107 public void findChildrenOfType(Class targetType, List results, boolean descendIntoNestedClasses) { 108 this.findChildrenOfType(this, targetType, results, descendIntoNestedClasses); 109 } 110 111 private void findChildrenOfType(Node node, Class targetType, List results, boolean descendIntoNestedClasses) { 112 if (node.getClass().equals(targetType)) { 113 results.add(node); 114 } 115 if (node.getClass().equals(ASTNestedClassDeclaration.class) && !descendIntoNestedClasses) { 116 return; 117 } 118 if (node.getClass().equals(ASTClassBodyDeclaration.class) && ((ASTClassBodyDeclaration)node).isAnonymousInnerClass() && !descendIntoNestedClasses) { 119 return; 120 } 121 for (int i = 0; i < node.jjtGetNumChildren(); i++) { 122 Node child = node.jjtGetChild(i); 123 if (child.jjtGetNumChildren() > 0) { 124 findChildrenOfType(child, targetType, results, descendIntoNestedClasses); 125 } else { 126 if (child.getClass().equals(targetType)) { 127 results.add(child); 128 } 129 } 130 } 131 } 132 133 public void jjtSetParent(Node n) { 134 parent = n; 135 } 136 137 public Node jjtGetParent() { 138 return parent; 139 } 140 141 public void jjtAddChild(Node n, int i) { 142 if (children == null) { 143 children = new Node[i + 1]; 144 } else if (i >= children.length) { 145 Node c[] = new Node[i + 1]; 146 System.arraycopy(children, 0, c, 0, children.length); 147 children = c; 148 } 149 children[i] = n; 150 } 151 152 public Node jjtGetChild(int i) { 153 return children[i]; 154 } 155 156 public int jjtGetNumChildren() { 157 return (children == null) ? 0 : children.length; 158 } 159 160 /*** Accept the visitor. **/ 161 public Object jjtAccept(JavaParserVisitor visitor, Object data) { 162 return visitor.visit(this, data); 163 } 164 165 /*** Accept the visitor. **/ 166 public Object childrenAccept(JavaParserVisitor visitor, Object data) { 167 if (children != null) { 168 for (int i = 0; i < children.length; ++i) { 169 children[i].jjtAccept(visitor, data); 170 } 171 } 172 return data; 173 } 174 175 /* You can override these two methods in subclasses of SimpleNode to 176 customize the way the node appears when the tree is dumped. If 177 your output uses more than one line you should override 178 toString(String), otherwise overriding toString() is probably all 179 you need to do. */ 180 181 public String toString() { 182 return JavaParserTreeConstants.jjtNodeName[id]; 183 } 184 185 public String toString(String prefix) { 186 return prefix + toString(); 187 } 188 189 /* Override this method if you want to customize how the node dumps 190 out its children. */ 191 public void dump(String prefix) { 192 System.out.println(toString(prefix)); 193 dumpChildren(prefix); 194 } 195 196 protected void dumpChildren(String prefix) { 197 if (children != null) { 198 for (int i = 0; i < children.length; ++i) { 199 SimpleNode n = (SimpleNode) children[i]; 200 if (n != null) { 201 n.dump(prefix + " "); 202 } 203 } 204 } 205 } 206 207 } 208

This page was automatically generated by Maven