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 import net.sourceforge.pmd.ast.Node;
10 import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
11
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.Map;
15
16 public class UnusedFormalParameterRule extends AbstractRule {
17
18 public Object visit(ASTMethodDeclaration node, Object data) {
19 if (!node.isPrivate() && !hasProperty("checkall")) {
20 return data;
21 }
22
23 if (!node.isNative()) {
24 Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
25 if (parent instanceof ASTClassOrInterfaceDeclaration && !((ASTClassOrInterfaceDeclaration)parent).isInterface()) {
26 Map vars = node.getScope().getVariableDeclarations();
27 for (Iterator i = vars.keySet().iterator(); i.hasNext();) {
28 VariableNameDeclaration nameDecl = (VariableNameDeclaration) i.next();
29 if (!((List) vars.get(nameDecl)).isEmpty()) {
30 continue;
31 }
32 addViolation(data, node, nameDecl.getImage());
33 }
34 }
35 }
36 return data;
37 }
38 }