View Javadoc

1   /* Generated By:JJTree: Do not edit this line. ASTLocalVariableDeclaration.java */
2   
3   package net.sourceforge.pmd.ast;
4   
5   import net.sourceforge.pmd.Rule;
6   
7   public class ASTLocalVariableDeclaration extends AccessNode implements Dimensionable, CanSuppressWarnings {
8   
9       public ASTLocalVariableDeclaration(int id) {
10          super(id);
11      }
12  
13      public ASTLocalVariableDeclaration(JavaParser p, int id) {
14          super(p, id);
15      }
16  
17      /***
18       * Accept the visitor. *
19       */
20      public Object jjtAccept(JavaParserVisitor visitor, Object data) {
21          return visitor.visit(this, data);
22      }
23  
24      public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
25          for (int i = 0; i < jjtGetNumChildren(); i++) {
26              if (jjtGetChild(i) instanceof ASTAnnotation) {
27                  ASTAnnotation a = (ASTAnnotation) jjtGetChild(i);
28                  if (a.suppresses(rule)) {
29                      return true;
30                  }
31              }
32          }
33          return false;
34      }
35  
36      public boolean isArray() {
37          return checkType() + checkDecl() > 0;
38      }
39  
40      public int getArrayDepth() {
41          if (!isArray()) {
42              return 0;
43          }
44          return checkType() + checkDecl();
45      }
46  
47      private int checkType() {
48          if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) {
49              return 0;
50          }
51          return ((ASTType) jjtGetChild(0)).getArrayDepth();
52      }
53  
54      private int checkDecl() {
55          if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
56              return 0;
57          }
58          return ((ASTVariableDeclaratorId) (jjtGetChild(1).jjtGetChild(0))).getArrayDepth();
59      }
60  
61      public void dump(String prefix) {
62          String out = "";
63          if (isArray()) {
64              out += "(array";
65              for (int i = 0; i < getArrayDepth(); i++) {
66                  out += "[";
67              }
68              out += ")";
69          }
70          if (isFinal()) {
71              out += "(final)";
72          }
73          System.out.println(toString(prefix) + out);
74          dumpChildren(prefix);
75      }
76  }