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