View Javadoc

    1   /* Generated By:JJTree: Do not edit this line. ASTAnnotation.java */
    2
    3   package net.sourceforge.pmd.ast;
    4
    5   import net.sourceforge.pmd.Rule;
    6
    7   import java.util.Arrays;
    8   import java.util.List;
    9
    10  public class ASTAnnotation extends SimpleJavaNode {
    11
    12      private static List unusedRules = Arrays.asList(new String[]{"UnusedPrivateField","UnusedLocalVariable","UnusedPrivateMethod","UnusedFormalParameter"});
    13
    14      private static List<String> serialRules = Arrays.asList(new String[] { "BeanMembersShouldSerialize", "MissingSerialVersionUID"});
    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.findChildrenOfType(ASTLiteral.class);
    35                      for (ASTLiteral element: nodes) {
    36                          if (element.hasImageEqualTo("\"PMD\"")
    37                                  || element.hasImageEqualTo(ruleAnno)
    38                                  // Check for standard annotations values
    39                                  || element.hasImageEqualTo("\"all\"")
    40                                  || element.hasImageEqualTo("\"serial\"") && serialRules.contains(rule.getName())
    41                                  || (element.hasImageEqualTo("\"unused\"") && unusedRules.contains(rule.getName()))) {
    42                              return true;
    43                          }
    44                      }
    45                  }
    46              }
    47          }
    48          return false;
    49      }
    50
    51      /**
    52       * Accept the visitor.
    53       */
    54      public Object jjtAccept(JavaParserVisitor visitor, Object data) {
    55          return visitor.visit(this, data);
    56      }
    57  }