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