1
2
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
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
36
37
38
39 public boolean isFunctionNodeName() {
40 return jjtGetParent() instanceof ASTFunctionNode
41 && ((ASTFunctionNode) jjtGetParent()).getFunctionName() == this;
42 }
43
44
45
46
47
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
63
64
65
66 public boolean isFunctionCallName() {
67 return jjtGetParent() instanceof ASTFunctionCall && ((ASTFunctionCall) jjtGetParent()).getTarget() == this;
68 }
69
70
71
72
73
74
75 public boolean isVariableDeclaration() {
76 return jjtGetParent() instanceof ASTVariableInitializer
77 && ((ASTVariableInitializer) jjtGetParent()).getTarget() == this;
78 }
79 }