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          int paramIndex = index;
34  	if (node.getFunctionName() != null) {
35  	    paramIndex = index + 1;
36  	}
37  	return (EcmascriptNode<?>) jjtGetChild(paramIndex);
38      }
39  
40      public EcmascriptNode<?> getBody() {
41          return (EcmascriptNode<?>) jjtGetChild(jjtGetNumChildren() - 1);
42      }
43  
44      @Deprecated // use getBody() instead
45      public EcmascriptNode<?> getBody(int index) {
46  	return getBody();
47      }
48  
49      public boolean isClosure() {
50  	return node.isExpressionClosure();
51      }
52  
53      public boolean isGetter() {
54  	return node.isGetterMethod();
55      }
56  
57      public boolean isSetter() {
58  	return node.isSetterMethod();
59      }
60  
61      public boolean isGetterOrSetter() {
62          return isGetter() || isSetter();
63      }
64  }