01: /* Generated By:JJTree: Do not edit this line. ASTLocalVariableDeclaration.java */
02:
03: package net.sourceforge.pmd.ast;
04:
05: import net.sourceforge.pmd.Rule;
06:
07: public class ASTLocalVariableDeclaration extends AccessNode implements
08: Dimensionable, CanSuppressWarnings {
09:
10: public ASTLocalVariableDeclaration(int id) {
11: super (id);
12: }
13:
14: public ASTLocalVariableDeclaration(JavaParser p, int id) {
15: super (p, id);
16: }
17:
18: /**
19: * Accept the visitor. *
20: */
21: public Object jjtAccept(JavaParserVisitor visitor, Object data) {
22: return visitor.visit(this , data);
23: }
24:
25: public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
26: for (int i = 0; i < jjtGetNumChildren(); i++) {
27: if (jjtGetChild(i) instanceof ASTAnnotation) {
28: ASTAnnotation a = (ASTAnnotation) jjtGetChild(i);
29: if (a.suppresses(rule)) {
30: return true;
31: }
32: }
33: }
34: return false;
35: }
36:
37: public boolean isArray() {
38: return checkType() + checkDecl() > 0;
39: }
40:
41: public int getArrayDepth() {
42: return checkType() + checkDecl();
43: }
44:
45: public ASTType getTypeNode() {
46: for (int i = 0; i < jjtGetNumChildren(); i++) {
47: if (jjtGetChild(i) instanceof ASTType) {
48: return (ASTType) jjtGetChild(i);
49: }
50: }
51: throw new IllegalStateException("ASTType not found");
52: }
53:
54: private int checkType() {
55: return getTypeNode().getArrayDepth();
56: }
57:
58: private ASTVariableDeclaratorId getDecl() {
59: return (ASTVariableDeclaratorId) jjtGetChild(
60: jjtGetNumChildren() - 1).jjtGetChild(0);
61: }
62:
63: private int checkDecl() {
64: return getDecl().getArrayDepth();
65: }
66:
67: public void dump(String prefix) {
68: String out = "";
69: if (isArray()) {
70: out += "(array";
71: for (int i = 0; i < getArrayDepth(); i++) {
72: out += "[";
73: }
74: out += ")";
75: }
76: if (isFinal()) {
77: out += "(final)";
78: }
79: System.out.println(toString(prefix) + out);
80: dumpChildren(prefix);
81: }
82:
83: /**
84: * Gets the variable name of this field.
85: * This method searches the first VariableDeclartorId node and returns it's image or <code>null</code> if the child node is not found.
86: *
87: * @return a String representing the name of the variable
88: */
89: public String getVariableName() {
90: ASTVariableDeclaratorId decl = getFirstChildOfType(ASTVariableDeclaratorId.class);
91: if (decl != null) {
92: return decl.getImage();
93: }
94: return null;
95: }
96: }
|