1
2
3
4 package net.sourceforge.pmd.lang.java.ast;
5
6 import net.sourceforge.pmd.lang.ast.AbstractNode;
7 import net.sourceforge.pmd.lang.symboltable.Scope;
8
9 public abstract class AbstractJavaNode extends AbstractNode implements JavaNode {
10
11 protected JavaParser parser;
12 private Scope scope;
13 private Comment comment;
14
15 public AbstractJavaNode(int id) {
16 super(id);
17 }
18
19 public AbstractJavaNode(JavaParser parser, int id) {
20 super(id);
21 this.parser = parser;
22 }
23
24 public void jjtOpen() {
25 if (beginLine == -1 && parser.token.next != null) {
26 beginLine = parser.token.next.beginLine;
27 beginColumn = parser.token.next.beginColumn;
28 }
29 }
30
31 public void jjtClose() {
32 if (beginLine == -1 && (children == null || children.length == 0)) {
33 beginColumn = parser.token.beginColumn;
34 }
35 if (beginLine == -1) {
36 beginLine = parser.token.beginLine;
37 }
38 endLine = parser.token.endLine;
39 endColumn = parser.token.endColumn;
40 }
41
42
43
44
45 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
46 return visitor.visit(this, data);
47 }
48
49
50
51
52 public Object childrenAccept(JavaParserVisitor visitor, Object data) {
53 if (children != null) {
54 for (int i = 0; i < children.length; ++i) {
55 ((JavaNode) children[i]).jjtAccept(visitor, data);
56 }
57 }
58 return data;
59 }
60
61 public Scope getScope() {
62 if (scope == null) {
63 return ((JavaNode)parent).getScope();
64 }
65 return scope;
66 }
67
68 public void setScope(Scope scope) {
69 this.scope = scope;
70 }
71
72 public void comment(Comment theComment) {
73 comment = theComment;
74 }
75
76 public Comment comment() {
77 return comment;
78 }
79
80 public String toString() {
81 return JavaParserTreeConstants.jjtNodeName[id];
82 }
83 }