KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.rules;
5
6 import net.sourceforge.pmd.AbstractRule;
7 import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
8 import net.sourceforge.pmd.ast.ASTMethodDeclaration;
9
10 public class AvoidNonConstructorMethodsWithClassName extends AbstractRule {
11
12     public Object JavaDoc visit(ASTClassOrInterfaceDeclaration node, Object JavaDoc data) {
13         if (node.isInterface()) {
14             return data;
15         }
16         return super.visit(node, data);
17     }
18
19     public Object JavaDoc visit(ASTMethodDeclaration node, Object JavaDoc data) {
20         String JavaDoc declaringType = getDeclaringType(node);
21         if (node.getMethodName().equals(declaringType)) {
22             addViolation(data, node, node.getMethodName());
23         }
24         return data;
25     }
26
27 }
28
Popular Tags