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.RuleContext;
8 import net.sourceforge.pmd.ast.ASTMethodDeclaration;
9 import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
10
11 import java.text.MessageFormat;
12 import java.util.Iterator;
13
14 public class UnusedFormalParameterRule extends AbstractRule {
15
16 public Object visit(ASTMethodDeclaration node, Object data) {
17 if (node.isPrivate() && !node.isNative()) {
18 RuleContext ctx = (RuleContext) data;
19 for (Iterator i = node.getScope().getVariableDeclarations(false).keySet().iterator(); i.hasNext();) {
20 VariableNameDeclaration nameDecl = (VariableNameDeclaration) i.next();
21 ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine(), MessageFormat.format(getMessage(), new Object[]{nameDecl.getImage()})));
22 }
23 }
24 return data;
25 }
26 }