KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > rules > MethodWithSameNameAsEnclosingClass


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 JavaDoc;
8 import java.util.List JavaDoc;
9
10 public class MethodWithSameNameAsEnclosingClass extends AbstractRule {
11
12     public Object JavaDoc visit(ASTClassOrInterfaceDeclaration node, Object JavaDoc data) {
13         List JavaDoc methods = node.findChildrenOfType(ASTMethodDeclarator.class);
14         for (Iterator JavaDoc 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