All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
/*
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

package net.sourceforge.pmd.lang.ecmascript.ast;

import org.mozilla.javascript.ast.FunctionNode;

public final class ASTFunctionNode extends AbstractEcmascriptNode {
    ASTFunctionNode(FunctionNode functionNode) {
        super(functionNode);
    }

    @Override
    protected  R acceptJsVisitor(EcmascriptVisitor visitor, P data) {
        return visitor.visit(this, data);
    }

    public int getNumParams() {
        return node.getParams().size();
    }

    public ASTName getFunctionName() {
        if (node.getFunctionName() != null) {
            return (ASTName) getChild(0);
        }
        return null;
    }

    public EcmascriptNode getParam(int index) {
        int paramIndex = index;
        if (node.getFunctionName() != null) {
            paramIndex = index + 1;
        }
        return (EcmascriptNode) getChild(paramIndex);
    }

    public EcmascriptNode getBody() {
        return (EcmascriptNode) getChild(getNumChildren() - 1);
    }

    public boolean isClosure() {
        return node.isExpressionClosure();
    }

    public boolean isGetter() {
        return node.isGetterMethod();
    }

    public boolean isSetter() {
        return node.isSetterMethod();
    }

    public boolean isGetterOrSetter() {
        return isGetter() || isSetter();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy