01: /* Generated By:JJTree: Do not edit this line. ASTVariableDeclaratorId.java */
02:
03: package net.sourceforge.pmd.ast;
04:
05: import net.sourceforge.pmd.symboltable.NameOccurrence;
06: import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
07:
08: import java.util.List;
09:
10: public class ASTVariableDeclaratorId extends SimpleJavaTypeNode {
11:
12: public ASTVariableDeclaratorId(int id) {
13: super (id);
14: }
15:
16: public ASTVariableDeclaratorId(JavaParser p, int id) {
17: super (p, id);
18: }
19:
20: /**
21: * Accept the visitor. *
22: */
23: public Object jjtAccept(JavaParserVisitor visitor, Object data) {
24: return visitor.visit(this , data);
25: }
26:
27: private int arrayDepth;
28: private VariableNameDeclaration nameDeclaration;
29:
30: public VariableNameDeclaration getNameDeclaration() {
31: return nameDeclaration;
32: }
33:
34: public void setNameDeclaration(VariableNameDeclaration decl) {
35: nameDeclaration = decl;
36: }
37:
38: public List<NameOccurrence> getUsages() {
39: return getScope().getVariableDeclarations()
40: .get(nameDeclaration);
41: }
42:
43: public void bumpArrayDepth() {
44: arrayDepth++;
45: }
46:
47: public int getArrayDepth() {
48: return arrayDepth;
49: }
50:
51: public boolean isArray() {
52: return arrayDepth > 0;
53: }
54:
55: public boolean isExceptionBlockParameter() {
56: return jjtGetParent().jjtGetParent() instanceof ASTTryStatement;
57: }
58:
59: public SimpleNode getTypeNameNode() {
60: if (jjtGetParent() instanceof ASTFormalParameter) {
61: return findTypeNameNode(jjtGetParent());
62: } else if (jjtGetParent().jjtGetParent() instanceof ASTLocalVariableDeclaration
63: || jjtGetParent().jjtGetParent() instanceof ASTFieldDeclaration) {
64: return findTypeNameNode(jjtGetParent().jjtGetParent());
65: }
66: throw new RuntimeException(
67: "Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration");
68: }
69:
70: public ASTType getTypeNode() {
71: if (jjtGetParent() instanceof ASTFormalParameter) {
72: return ((ASTFormalParameter) jjtGetParent()).getTypeNode();
73: } else if (jjtGetParent().jjtGetParent() instanceof ASTLocalVariableDeclaration
74: || jjtGetParent().jjtGetParent() instanceof ASTFieldDeclaration) {
75: SimpleNode n = (SimpleNode) jjtGetParent().jjtGetParent();
76: return n.getFirstChildOfType(ASTType.class);
77: }
78: throw new RuntimeException(
79: "Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration");
80: }
81:
82: private SimpleNode findTypeNameNode(Node node) {
83: int i = 0;
84: while (node.jjtGetChild(i) instanceof ASTAnnotation) {
85: // skip annotations
86: i++;
87: }
88: ASTType typeNode = (ASTType) node.jjtGetChild(i);
89: return (SimpleNode) typeNode.jjtGetChild(0);
90: }
91: }
|