1
2
3 package net.sourceforge.pmd.ast;
4
5 public class ASTLocalVariableDeclaration extends AccessNode implements Dimensionable {
6
7 public ASTLocalVariableDeclaration(int id) {
8 super(id);
9 }
10
11 public ASTLocalVariableDeclaration(JavaParser p, int id) {
12 super(p, id);
13 }
14
15 /***
16 * Accept the visitor. *
17 */
18 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
19 return visitor.visit(this, data);
20 }
21
22 public boolean isArray() {
23 return checkType() + checkDecl() > 0;
24 }
25
26 public int getArrayDepth() {
27 if (!isArray()) {
28 return 0;
29 }
30 return checkType() + checkDecl();
31 }
32
33 private int checkType() {
34 if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) {
35 return 0;
36 }
37 return ((ASTType) jjtGetChild(0)).getArrayDepth();
38 }
39
40 private int checkDecl() {
41 if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
42 return 0;
43 }
44 return ((ASTVariableDeclaratorId) (jjtGetChild(1).jjtGetChild(0))).getArrayDepth();
45 }
46
47 public void dump(String prefix) {
48 String out = "";
49 if (isArray()) {
50 out += "(array";
51 for (int i = 0; i < getArrayDepth(); i++) {
52 out += "[";
53 }
54 out += ")";
55 }
56 System.out.println(toString(prefix) + out);
57 dumpChildren(prefix);
58 }
59 }