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

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

/**
 * 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 class ASTName extends AbstractEcmascriptNode {
    public ASTName(Name name) {
        super(name);
        super.setImage(name.getIdentifier());
    }

    /**
     * Accept the visitor.
     */
    @Override
    public Object jjtAccept(EcmascriptParserVisitor visitor, Object 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 jjtGetParent() instanceof ASTFunctionNode
                && ((ASTFunctionNode) jjtGetParent()).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 (jjtGetParent() instanceof ASTFunctionNode) {
            ASTFunctionNode functionNode = (ASTFunctionNode) jjtGetParent();
            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 jjtGetParent() instanceof ASTFunctionCall && ((ASTFunctionCall) jjtGetParent()).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 jjtGetParent() instanceof ASTVariableInitializer
                && ((ASTVariableInitializer) jjtGetParent()).getTarget() == this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy