01 package net.sourceforge.pmd.lang.java.ast;
02
03 import net.sourceforge.pmd.lang.ast.AbstractNode;
04 import net.sourceforge.pmd.lang.java.symboltable.Scope;
05
06 public abstract class AbstractJavaNode extends AbstractNode implements JavaNode {
07
08 protected JavaParser parser;
09 private Scope scope;
10
11 public AbstractJavaNode(int id) {
12 super(id);
13 }
14
15 public AbstractJavaNode(JavaParser parser, int id) {
16 super(id);
17 this.parser = parser;
18 }
19
20 public void jjtOpen() {
21 if (beginLine == -1 && parser.token.next != null) {
22 beginLine = parser.token.next.beginLine;
23 beginColumn = parser.token.next.beginColumn;
24 }
25 }
26
27 public void jjtClose() {
28 if (beginLine == -1 && (children == null || children.length == 0)) {
29 beginColumn = parser.token.beginColumn;
30 }
31 if (beginLine == -1) {
32 beginLine = parser.token.beginLine;
33 }
34 endLine = parser.token.endLine;
35 endColumn = parser.token.endColumn;
36 }
37
38 /**
39 * Accept the visitor. *
40 */
41 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
42 return visitor.visit(this, data);
43 }
44
45 /**
46 * Accept the visitor. *
47 */
48 public Object childrenAccept(JavaParserVisitor visitor, Object data) {
49 if (children != null) {
50 for (int i = 0; i < children.length; ++i) {
51 ((JavaNode) children[i]).jjtAccept(visitor, data);
52 }
53 }
54 return data;
55 }
56
57 public Scope getScope() {
58 if (scope == null) {
59 return ((JavaNode)parent).getScope();
60 }
61 return scope;
62 }
63
64 public void setScope(Scope scope) {
65 this.scope = scope;
66 }
67
68 public String toString() {
69 return JavaParserTreeConstants.jjtNodeName[id];
70 }
71 }
|