|
1 |
| |
|
2 |
| |
|
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 |
6
| public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
|
13 |
6
| if (node.isInterface()) {
|
|
14 |
1
| return data;
|
|
15 |
| } |
|
16 |
5
| return super.visit(node, data);
|
|
17 |
| } |
|
18 |
| |
|
19 |
5
| public Object visit(ASTMethodDeclaration node, Object data) {
|
|
20 |
5
| String declaringType = getDeclaringType(node);
|
|
21 |
5
| if (node.getMethodName().equals(declaringType)) {
|
|
22 |
5
| addViolation(data, node, node.getMethodName());
|
|
23 |
| } |
|
24 |
5
| return data;
|
|
25 |
| } |
|
26 |
| |
|
27 |
| } |