1
2
3
4
5
6 package net.sourceforge.pmd.lang.java.ast;
7
8 import net.sourceforge.pmd.Rule;
9
10 public class ASTFormalParameter extends AbstractJavaAccessNode implements Dimensionable, CanSuppressWarnings {
11
12 private boolean isVarargs;
13
14
15 public void setVarargs() {
16 isVarargs = true;
17 }
18
19 public boolean isVarargs() {
20 return isVarargs;
21 }
22
23 public ASTFormalParameter(int id) {
24 super(id);
25 }
26
27 public ASTFormalParameter(JavaParser p, int id) {
28 super(p, id);
29 }
30
31 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
32 return visitor.visit(this, data);
33 }
34
35 public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
36 for (int i = 0; i < jjtGetNumChildren(); i++) {
37 if (jjtGetChild(i) instanceof ASTAnnotation) {
38 ASTAnnotation a = (ASTAnnotation) jjtGetChild(i);
39 if (a.suppresses(rule)) {
40 return true;
41 }
42 }
43 }
44 return false;
45 }
46
47 public boolean isArray() {
48 return checkType() + checkDecl() > 0;
49 }
50
51 public int getArrayDepth() {
52 if (!isArray()) {
53 return 0;
54 }
55 return checkType() + checkDecl();
56 }
57
58 public ASTType getTypeNode() {
59 for (int i = 0; i < jjtGetNumChildren(); i++) {
60 if (jjtGetChild(i) instanceof ASTType) {
61 return (ASTType) jjtGetChild(i);
62 }
63 }
64 throw new IllegalStateException("ASTType not found");
65 }
66
67 private int checkType() {
68 return getTypeNode().getArrayDepth();
69 }
70
71 protected ASTVariableDeclaratorId getDecl() {
72 try {
73 return (ASTVariableDeclaratorId) jjtGetChild(jjtGetNumChildren()-1);
74 } catch (ClassCastException c) {
75 System.out.println("CLASS CAST: " + this.getBeginLine() + ":" + this.getBeginColumn() + " " + this.toString());
76 return null;
77 }
78 }
79
80 private int checkDecl() {
81 return getDecl().getArrayDepth();
82 }
83
84 }