01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.rules;
04:
05: import net.sourceforge.pmd.AbstractRule;
06: import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
07: import net.sourceforge.pmd.ast.ASTMethodDeclaration;
08:
09: public class AvoidNonConstructorMethodsWithClassName extends
10: AbstractRule {
11:
12: public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
13: if (node.isInterface()) {
14: return data;
15: }
16: return super .visit(node, data);
17: }
18:
19: public Object visit(ASTMethodDeclaration node, Object data) {
20: String declaringType = getDeclaringType(node);
21: if (node.getMethodName().equals(declaringType)) {
22: addViolation(data, node, node.getMethodName());
23: }
24: return data;
25: }
26:
27: }
|