1 2 3 package net.sourceforge.pmd.ast; 4 5 import net.sourceforge.pmd.Rule; 6 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 public class ASTAnnotation extends SimpleJavaNode { 11 public ASTAnnotation(int id) { 12 super(id); 13 } 14 15 public ASTAnnotation(JavaParser p, int id) { 16 super(p, id); 17 } 18 19 public boolean suppresses(Rule rule) { 20 final String ruleAnno = "\"PMD." + rule.getName() + "\""; 21 22 if (jjtGetChild(0) instanceof ASTSingleMemberAnnotation) { 23 ASTSingleMemberAnnotation n = (ASTSingleMemberAnnotation) jjtGetChild(0); 24 25 if (n.jjtGetChild(0) instanceof ASTName) { 26 ASTName annName = ((ASTName) n.jjtGetChild(0)); 27 28 if (annName.getImage().equals("SuppressWarnings")) { 29 List nodes = n.findChildrenOfType(ASTLiteral.class); 30 for (Iterator iter = nodes.iterator(); iter.hasNext();) { 31 ASTLiteral element = (ASTLiteral) iter.next(); 32 if (element.hasImageEqualTo("\"PMD\"") 33 || element.hasImageEqualTo(ruleAnno)) { 34 return true; 35 } 36 } 37 } 38 } 39 } 40 return false; 41 } 42 43 46 public Object jjtAccept(JavaParserVisitor visitor, Object data) { 47 return visitor.visit(this, data); 48 } 49 } 50 | Popular Tags |