View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.ecmascript.ast;
5   
6   import net.sourceforge.pmd.lang.ast.AbstractNode;
7   
8   import org.mozilla.javascript.ast.AstNode;
9   
10  public abstract class AbstractEcmascriptNode<T extends AstNode> extends AbstractNode implements EcmascriptNode {
11  
12      protected final T node;
13  
14      public AbstractEcmascriptNode(T node) {
15  	super(node.getType());
16  	this.node = node;
17  	this.beginLine = node.getLineno() + 1;
18  	this.beginLine = node.getLineno() + 1;
19  	// TODO Implement positions, or figure out how to do begin/end lines/column
20  	//this.beginPosition = node.getAbsolutePosition();
21  	//this.endPosition = this.beginPosition + node.getLength();
22      }
23  
24      /**
25       * Accept the visitor. *
26       */
27      public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
28  	return visitor.visit(this, data);
29      }
30  
31      /**
32       * Accept the visitor. *
33       */
34      public Object childrenAccept(EcmascriptParserVisitor visitor, Object data) {
35  	if (children != null) {
36  	    for (int i = 0; i < children.length; ++i) {
37  		((EcmascriptNode) children[i]).jjtAccept(visitor, data);
38  	    }
39  	}
40  	return data;
41      }
42      
43      public T getNode() {
44  	return node;
45      }
46  
47      public String getJsDoc() {
48  	return node.getJsDoc();
49      }
50  
51      public boolean hasSideEffects() {
52  	return node.hasSideEffects();
53      }
54  
55      @Override
56      public int getBeginColumn() {
57  	return -1;
58      }
59  
60      @Override
61      public String toString() {
62  	return node.shortName();
63      }
64  }