Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 31 |  | Methods: | 1
| NCLOC: | 24 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

AvoidReassigningParameters.java

100%

100%

100%

100%

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.ast.ASTMethodDeclarator;
8 |  | import net.sourceforge.pmd.symboltable.NameOccurrence;
9 |  | import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
10 |  |
11 |  | import java.util.Iterator;
12 |  | import java.util.List;
13 |  | import java.util.Map;
14 |  |
15 |  | public class AvoidReassigningParameters extends AbstractRule {
16 |  |
17 | 9 | public Object visit(ASTMethodDeclarator node, Object data) {
18 | 9 | Map params = node.getScope().getVariableDeclarations();
19 | 9 | for (Iterator i = params.keySet().iterator(); i.hasNext();) {
20 | 9 | VariableNameDeclaration decl = (VariableNameDeclaration) i.next();
21 | 9 | List usages = (List) params.get(decl);
22 | 9 | for (Iterator j = usages.iterator(); j.hasNext();) {
23 | 7 | NameOccurrence occ = (NameOccurrence) j.next();
24 | 7 | if ((occ.isOnLeftHandSide() || occ.isSelfAssignment()) && occ.getNameForWhichThisIsAQualifier() == null && !decl.isArray()) {
25 | 4 | addViolation(data, decl.getNode(), decl.getImage());
26 |  | }
27 |  | }
28 |  | }
29 | 9 | return super.visit(node, data);
30 |  | }
31 |  | }