1 |
| |
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 |
0
| public ASTLocalVariableDeclaration(int id) {
|
10 |
0
| super(id);
|
11 |
| } |
12 |
| |
13 |
505
| public ASTLocalVariableDeclaration(JavaParser p, int id) {
|
14 |
505
| super(p, id);
|
15 |
| } |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
1349
| public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
21 |
1349
| return visitor.visit(this, data);
|
22 |
| } |
23 |
| |
24 |
68
| public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
|
25 |
68
| for (int i = 0; i < jjtGetNumChildren(); i++) {
|
26 |
137
| if (jjtGetChild(i) instanceof ASTAnnotation) {
|
27 |
1
| ASTAnnotation a = (ASTAnnotation) jjtGetChild(i);
|
28 |
1
| if (a.suppresses(rule)) {
|
29 |
1
| return true;
|
30 |
| } |
31 |
| } |
32 |
| } |
33 |
67
| return false;
|
34 |
| } |
35 |
| |
36 |
47
| public boolean isArray() {
|
37 |
47
| return checkType() + checkDecl() > 0;
|
38 |
| } |
39 |
| |
40 |
3
| public int getArrayDepth() {
|
41 |
3
| if (!isArray()) {
|
42 |
0
| return 0;
|
43 |
| } |
44 |
3
| return checkType() + checkDecl();
|
45 |
| } |
46 |
| |
47 |
50
| private int checkType() {
|
48 |
50
| if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) {
|
49 |
0
| return 0;
|
50 |
| } |
51 |
50
| return ((ASTType) jjtGetChild(0)).getArrayDepth();
|
52 |
| } |
53 |
| |
54 |
50
| private int checkDecl() {
|
55 |
50
| if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) {
|
56 |
0
| return 0;
|
57 |
| } |
58 |
50
| return ((ASTVariableDeclaratorId) (jjtGetChild(1).jjtGetChild(0))).getArrayDepth();
|
59 |
| } |
60 |
| |
61 |
0
| public void dump(String prefix) {
|
62 |
0
| String out = "";
|
63 |
0
| if (isArray()) {
|
64 |
0
| out += "(array";
|
65 |
0
| for (int i = 0; i < getArrayDepth(); i++) {
|
66 |
0
| out += "[";
|
67 |
| } |
68 |
0
| out += ")";
|
69 |
| } |
70 |
0
| if (isFinal()) {
|
71 |
0
| out += "(final)";
|
72 |
| } |
73 |
0
| System.out.println(toString(prefix) + out);
|
74 |
0
| dumpChildren(prefix);
|
75 |
| } |
76 |
| } |