View Javadoc

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