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