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.Name;
    7
    8   public class ASTName extends AbstractEcmascriptNode<Name> {
    9       public ASTName(Name name) {
    10  	super(name);
    11  	super.setImage(name.getIdentifier());
    12      }
    13
    14      /**
    15       * Accept the visitor.
    16       */
    17      @Override
    18      public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
    19  	return visitor.visit(this, data);
    20      }
    21
    22      public String getIdentifier() {
    23  	return node.getIdentifier();
    24      }
    25
    26      public boolean isLocalName() {
    27  	return node.isLocalName();
    28      }
    29
    30      public boolean isGlobalName() {
    31  	return !node.isLocalName();
    32      }
    33
    34      /**
    35       * Returns whether this name node is the name of a function declaration.
    36       * @return <code>true</code> if name of a function declaration,
    37       * <code>false</code> otherwise.
    38       */
    39      public boolean isFunctionNodeName() {
    40  	return jjtGetParent() instanceof ASTFunctionNode
    41  		&& ((ASTFunctionNode) jjtGetParent()).getFunctionName() == this;
    42      }
    43
    44      /**
    45       * Returns whether this name node is the name of a function declaration parameter.
    46       * @return <code>true</code> if name of a function declaration parameter,
    47       * <code>false</code> otherwise.
    48       */
    49      public boolean isFunctionNodeParameter() {
    50  	if (jjtGetParent() instanceof ASTFunctionNode) {
    51  	    ASTFunctionNode functionNode = (ASTFunctionNode) jjtGetParent();
    52  	    for (int i = 0; i < functionNode.getNumParams(); i++) {
    53  		if (functionNode.getParam(i) == this) {
    54  		    return true;
    55  		}
    56  	    }
    57  	}
    58  	return false;
    59      }
    60
    61      /**
    62       * Returns whether this name node is the name of a function call.
    63       * @return <code>true</code> if name of a function call,
    64       * <code>false</code> otherwise.
    65       */
    66      public boolean isFunctionCallName() {
    67  	return jjtGetParent() instanceof ASTFunctionCall && ((ASTFunctionCall) jjtGetParent()).getTarget() == this;
    68      }
    69
    70      /**
    71       * Returns whether this name node is the name of a variable declaration.
    72       * @return <code>true</code> if name of a variable declaration,
    73       * <code>false</code> otherwise.
    74       */
    75      public boolean isVariableDeclaration() {
    76  	return jjtGetParent() instanceof ASTVariableInitializer
    77  		&& ((ASTVariableInitializer) jjtGetParent()).getTarget() == this;
    78      }
    79  }