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.Iterator ; 8 import java.util.List ; 9 10 public class MethodWithSameNameAsEnclosingClass extends AbstractRule { 11 12 public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { 13 List methods = node.findChildrenOfType(ASTMethodDeclarator.class); 14 for (Iterator i = methods.iterator(); i.hasNext();) { 15 ASTMethodDeclarator m = (ASTMethodDeclarator) i.next(); 16 if (m.hasImageEqualTo(node.getImage())) { 17 addViolation(data, m); 18 } 19 } 20 return super.visit(node, data); 21 } 22 } 23 | Popular Tags |