Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 37   Methods: 1
NCLOC: 28   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AvoidReassigningParameters.java 100% 100% 100% 100%
coverage
 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 java.util.Iterator;
 7    import java.util.List;
 8    import java.util.Map;
 9   
 10    import net.sourceforge.pmd.AbstractRule;
 11    import net.sourceforge.pmd.ast.ASTMethodDeclarator;
 12    import net.sourceforge.pmd.symboltable.NameOccurrence;
 13    import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
 14   
 15    public class AvoidReassigningParameters extends AbstractRule {
 16   
 17  11 public Object visit(ASTMethodDeclarator node, Object data) {
 18  11 Map params = node.getScope().getVariableDeclarations();
 19  11 for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
 20  11 Map.Entry entry = (Map.Entry) i.next();
 21   
 22  11 VariableNameDeclaration decl = (VariableNameDeclaration) entry.getKey();
 23  11 List usages = (List) entry.getValue();
 24  11 for (Iterator j = usages.iterator(); j.hasNext();) {
 25  9 NameOccurrence occ = (NameOccurrence) j.next();
 26  9 if ((occ.isOnLeftHandSide() || occ.isSelfAssignment()) &&
 27    occ.getNameForWhichThisIsAQualifier() == null &&
 28    (!decl.isArray() || occ.getLocation().jjtGetParent().jjtGetParent().jjtGetNumChildren() == 1))
 29    {
 30    // not an array or no primary suffix to access the array values
 31  5 addViolation(data, decl.getNode(), decl.getImage());
 32    }
 33    }
 34    }
 35  11 return super.visit(node, data);
 36    }
 37    }