01: /* Generated By:JJTree: Do not edit this line. ASTAnnotation.java */
02:
03: package net.sourceforge.pmd.ast;
04:
05: import net.sourceforge.pmd.Rule;
06:
07: import java.util.Arrays;
08: import java.util.List;
09:
10: public class ASTAnnotation extends SimpleJavaNode {
11:
12: private static List unusedRules = Arrays.asList(new String[] {
13: "UnusedPrivateField", "UnusedLocalVariable",
14: "UnusedPrivateMethod", "UnusedFormalParameter" });
15:
16: public ASTAnnotation(int id) {
17: super (id);
18: }
19:
20: public ASTAnnotation(JavaParser p, int id) {
21: super (p, id);
22: }
23:
24: public boolean suppresses(Rule rule) {
25: final String ruleAnno = "\"PMD." + rule.getName() + "\"";
26:
27: if (jjtGetChild(0) instanceof ASTSingleMemberAnnotation) {
28: ASTSingleMemberAnnotation n = (ASTSingleMemberAnnotation) jjtGetChild(0);
29:
30: if (n.jjtGetChild(0) instanceof ASTName) {
31: ASTName annName = ((ASTName) n.jjtGetChild(0));
32:
33: if (annName.getImage().equals("SuppressWarnings")) {
34: List<ASTLiteral> nodes = n
35: .findChildrenOfType(ASTLiteral.class);
36: for (ASTLiteral element : nodes) {
37: if (element.hasImageEqualTo("\"PMD\"")
38: || element.hasImageEqualTo(ruleAnno)
39: // the SuppressWarnings("unused") annotation allows unused code
40: // to be igored and is a Java standard annotation
41: || (element
42: .hasImageEqualTo("\"unused\"") && unusedRules
43: .contains(rule.getName()))) {
44: return true;
45: }
46: }
47: }
48: }
49: }
50: return false;
51: }
52:
53: /**
54: * Accept the visitor.
55: */
56: public Object jjtAccept(JavaParserVisitor visitor, Object data) {
57: return visitor.visit(this, data);
58: }
59: }
|