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

net.sourceforge.pmd.lang.ecmascript.ast.ASTName 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.Name;

public final class ASTName extends AbstractEcmascriptNode {
    ASTName(Name name) {
        super(name);
    }

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

    public String getIdentifier() {
        return node.getIdentifier();
    }

    public boolean isLocalName() {
        return node.isLocalName();
    }

    public boolean isGlobalName() {
        return !node.isLocalName();
    }

    /**
     * Returns whether this name node is the name of a function declaration.
     *
     * @return true if name of a function declaration,
     *         false otherwise.
     */
    public boolean isFunctionNodeName() {
        return getParent() instanceof ASTFunctionNode
                && ((ASTFunctionNode) getParent()).getFunctionName() == this;
    }

    /**
     * Returns whether this name node is the name of a function declaration
     * parameter.
     *
     * @return true if name of a function declaration parameter,
     *         false otherwise.
     */
    public boolean isFunctionNodeParameter() {
        if (getParent() instanceof ASTFunctionNode) {
            ASTFunctionNode functionNode = (ASTFunctionNode) getParent();
            for (int i = 0; i < functionNode.getNumParams(); i++) {
                if (functionNode.getParam(i) == this) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Returns whether this name node is the name of a function call.
     *
     * @return true if name of a function call, false
     *         otherwise.
     */
    public boolean isFunctionCallName() {
        return getParent() instanceof ASTFunctionCall && ((ASTFunctionCall) getParent()).getTarget() == this;
    }

    /**
     * Returns whether this name node is the name of a variable declaration.
     *
     * @return true if name of a variable declaration,
     *         false otherwise.
     */
    public boolean isVariableDeclaration() {
        return getParent() instanceof ASTVariableInitializer
                && ((ASTVariableInitializer) getParent()).getTarget() == this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy