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.ASTLocalVariableDeclaration;
06: import net.sourceforge.jrefactory.ast.ASTVariableDeclaratorId;
07: import org.acm.seguin.pmd.symboltable.Scope;
08: import org.acm.seguin.pmd.symboltable.VariableNameDeclaration;
09:
10: import java.text.MessageFormat;
11: import java.util.Iterator;
12:
13: public class UnusedLocalVariableRule extends AbstractRule {
14: public Object visit(ASTVariableDeclaratorId node, Object data) {
15: if (node.jjtGetParent().jjtGetParent() instanceof ASTLocalVariableDeclaration) {
16: RuleContext ctx = (RuleContext) data;
17: for (Iterator i = ((Scope) node.getScope())
18: .getVariableDeclarations(false).keySet().iterator(); i
19: .hasNext();) {
20: VariableNameDeclaration decl = (VariableNameDeclaration) i
21: .next();
22: ctx
23: .getReport()
24: .addRuleViolation(
25: createRuleViolation(ctx,
26: decl.getLine(),
27: MessageFormat.format(
28: getMessage(),
29: new Object[] { decl
30: .getImage() })));
31: }
32: }
33: return data;
34: }
35: }
|