View Javadoc

    1   package net.sourceforge.pmd.lang.java.rule.naming;
    2
    3   import java.util.List;
    4
    5   import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
    6   import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
    7   import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
    8
    9   public class MethodWithSameNameAsEnclosingClassRule extends AbstractJavaRule {
    10
    11      @Override
    12      public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
    13          List<ASTMethodDeclarator> methods = node.findDescendantsOfType(ASTMethodDeclarator.class);
    14          for (ASTMethodDeclarator m: methods) {
    15              if (m.hasImageEqualTo(node.getImage())) {
    16                  addViolation(data, m);
    17              }
    18          }
    19          return super.visit(node, data);
    20      }
    21  }