View Javadoc

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