View Javadoc

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