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.ASTUnmodifiedClassDeclaration;
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 UnusedPrivateFieldRule extends AbstractRule {
13:
14: public Object visit(ASTUnmodifiedClassDeclaration node, Object data) {
15: for (Iterator i = ((Scope) node.getScope())
16: .getVariableDeclarations(false).keySet().iterator(); i
17: .hasNext();) {
18: VariableNameDeclaration decl = (VariableNameDeclaration) i
19: .next();
20: if (decl.getAccessNodeParent().isPrivate()
21: && !decl.getImage().equals("serialVersionUID")
22: && !decl.getImage()
23: .equals("serialPersistentFields")
24: && !decl.getImage().equals("IDENT")) {
25: RuleContext ctx = (RuleContext) data;
26: ctx
27: .getReport()
28: .addRuleViolation(
29: createRuleViolation(ctx,
30: decl.getLine(),
31: MessageFormat.format(
32: getMessage(),
33: new Object[] { decl
34: .getImage() })));
35: }
36: }
37: return super.visit(node, data);
38: }
39:
40: }
|