01: package org.acm.seguin.pmd.rules;
02:
03: import org.acm.seguin.pmd.AbstractRule;
04: import org.acm.seguin.pmd.RuleContext;
05: import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
06: import org.acm.seguin.pmd.symboltable.Scope;
07: import org.acm.seguin.pmd.symboltable.VariableNameDeclaration;
08:
09: import java.text.MessageFormat;
10: import java.util.Iterator;
11:
12: public class UnusedFormalParameterRule extends AbstractRule {
13:
14: public Object visit(ASTMethodDeclaration node, Object data) {
15: if (node.isPrivate() && !node.isNative()) { // make sure it's both private and not native
16: RuleContext ctx = (RuleContext) data;
17: for (Iterator i = ((Scope) node.getScope())
18: .getVariableDeclarations(false).keySet().iterator(); i
19: .hasNext();) {
20: VariableNameDeclaration nameDecl = (VariableNameDeclaration) i
21: .next();
22: ctx.getReport().addRuleViolation(
23: createRuleViolation(ctx, node.getBeginLine(),
24: MessageFormat.format(getMessage(),
25: new Object[] { nameDecl
26: .getImage() })));
27: }
28: }
29: return data;
30: }
31: }
|