Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 38 |  | Methods: | 1
| NCLOC: | 24 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
SuspiciousHashcodeMethodName.java | 75% | 100% | 100% | 92.9% |

1 |  | package net.sourceforge.pmd.rules.naming;
2 |  |
3 |  | import net.sourceforge.pmd.AbstractRule;
4 |  | import net.sourceforge.pmd.ast.ASTMethodDeclaration;
5 |  | import net.sourceforge.pmd.ast.ASTMethodDeclarator;
6 |  | import net.sourceforge.pmd.ast.ASTPrimitiveType;
7 |  | import net.sourceforge.pmd.ast.ASTResultType;
8 |  | import net.sourceforge.pmd.ast.SimpleJavaNode;
9 |  |
10 |  | public class SuspiciousHashcodeMethodName extends AbstractRule {
11 |  |
12 | 4 | public Object visit(ASTMethodDeclaration node, Object data) {
13 |  | /* original XPath rule was
14 |  | //MethodDeclaration
15 |  | [ResultType
16 |  | //PrimitiveType
17 |  | [@Image='int']
18 |  | [//MethodDeclarator
19 |  | [@Image='hashcode' or @Image='HashCode' or @Image='Hashcode']
20 |  | [not(FormalParameters/*)]]]
21 |  | */
22 |  |
23 | 4 | ASTResultType type = (ASTResultType) node.getFirstChildOfType(ASTResultType.class);
24 | 4 | ASTMethodDeclarator decl = (ASTMethodDeclarator) node.getFirstChildOfType(ASTMethodDeclarator.class);
25 | 4 | String name = decl.getImage();
26 | 4 | if (name.equalsIgnoreCase("hashcode") && !name.equals("hashCode")
27 |  | && decl.jjtGetChild(0).jjtGetNumChildren() == 0
28 |  | && type.jjtGetNumChildren() != 0) {
29 | 3 | SimpleJavaNode t = (SimpleJavaNode) type.jjtGetChild(0).jjtGetChild(0);
30 | 3 | if (t instanceof ASTPrimitiveType && "int".equals(t.getImage())) {
31 | 3 | addViolation(data, node);
32 | 3 | return data;
33 |  | }
34 |  | }
35 | 1 | return super.visit(node, data);
36 |  | }
37 |  |
38 |  | }