01 /**
02 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03 */
04 package net.sourceforge.pmd.lang.ecmascript.ast;
05
06 import org.mozilla.javascript.ast.Name;
07
08 public class ASTName extends AbstractEcmascriptNode<Name> {
09 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 boolean isLocalName() {
23 return node.isLocalName();
24 }
25
26 public boolean isGlobalName() {
27 return !node.isLocalName();
28 }
29
30 /**
31 * Returns whether this name node is the name of a function declaration.
32 * @return <code>true</code> if name of a function declaration,
33 * <code>false</code> otherwise.
34 */
35 public boolean isFunctionNodeName() {
36 return jjtGetParent() instanceof ASTFunctionNode
37 && ((ASTFunctionNode) jjtGetParent()).getFunctionName() == this;
38 }
39
40 /**
41 * Returns whether this name node is the name of a function declaration parameter.
42 * @return <code>true</code> if name of a function declaration parameter,
43 * <code>false</code> otherwise.
44 */
45 public boolean isFunctionNodeParameter() {
46 if (jjtGetParent() instanceof ASTFunctionNode) {
47 ASTFunctionNode functionNode = (ASTFunctionNode) jjtGetParent();
48 for (int i = 0; i < functionNode.getNumParams(); i++) {
49 if (functionNode.getParam(i) == this) {
50 return true;
51 }
52 }
53 }
54 return false;
55 }
56
57 /**
58 * Returns whether this name node is the name of a function call.
59 * @return <code>true</code> if name of a function call,
60 * <code>false</code> otherwise.
61 */
62 public boolean isFunctionCallName() {
63 return jjtGetParent() instanceof ASTFunctionCall && ((ASTFunctionCall) jjtGetParent()).getTarget() == this;
64 }
65
66 /**
67 * Returns whether this name node is the name of a variable declaration.
68 * @return <code>true</code> if name of a variable declaration,
69 * <code>false</code> otherwise.
70 */
71 public boolean isVariableDeclaration() {
72 return jjtGetParent() instanceof ASTVariableInitializer
73 && ((ASTVariableInitializer) jjtGetParent()).getTarget() == this;
74 }
75 }
|