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 org.mozilla.javascript.ast.FunctionNode;
7   
8   public class ASTFunctionNode extends AbstractEcmascriptNode<FunctionNode> {
9       public ASTFunctionNode(FunctionNode functionNode) {
10  	super(functionNode);
11  	super.setImage(functionNode.getName());
12      }
13  
14      /**
15       * Accept the visitor.
16       */
17      public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
18  	return visitor.visit(this, data);
19      }
20  
21      public int getNumParams() {
22  	return node.getParams().size();
23      }
24  
25      public ASTName getFunctionName() {
26  	if (node.getFunctionName() != null) {
27  	    return (ASTName) jjtGetChild(0);
28  	}
29  	return null;
30      }
31  
32      public EcmascriptNode getParam(int index) {
33  	if (node.getFunctionName() != null) {
34  	    index++;
35  	}
36  	return (EcmascriptNode) jjtGetChild(index);
37      }
38  
39      public EcmascriptNode getBody() {
40          return (EcmascriptNode) jjtGetChild(jjtGetNumChildren() - 1);
41      }
42  
43      @Deprecated // use getBody() instead
44      public EcmascriptNode getBody(int index) {
45  	return getBody();
46      }
47  
48      public boolean isClosure() {
49  	return node.isExpressionClosure();
50      }
51  
52      public boolean isGetter() {
53  	return node.isGetter();
54      }
55  
56      public boolean isSetter() {
57  	return node.isSetter();
58      }
59  
60      public boolean isGetterOrSetter() {
61  	return node.isGetterOrSetter();
62      }
63  }