Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 35 |  | Methods: | 1
| NCLOC: | 27 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
LocalVariableCouldBeFinal.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.optimization;
5 |  |
6 |  | import java.util.Iterator;
7 |  | import java.util.List;
8 |  | import java.util.Map;
9 |  |
10 |  | import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration;
11 |  | import net.sourceforge.pmd.symboltable.Scope;
12 |  | import net.sourceforge.pmd.symboltable.VariableNameDeclaration;
13 |  |
14 |  | public class LocalVariableCouldBeFinal extends AbstractOptimizationRule {
15 |  |
16 | 12 | public Object visit(ASTLocalVariableDeclaration node, Object data) {
17 | 12 | if (node.isFinal()) {
18 | 1 | return data;
19 |  | }
20 | 11 | Scope s = node.getScope();
21 | 11 | Map decls = s.getVariableDeclarations();
22 | 11 | for (Iterator i = decls.entrySet().iterator(); i.hasNext();) {
23 | 19 | Map.Entry entry = (Map.Entry) i.next();
24 | 19 | VariableNameDeclaration var = (VariableNameDeclaration) entry.getKey();
25 | 19 | if (var.getAccessNodeParent() != node) {
26 | 8 | continue;
27 |  | }
28 | 11 | if (!assigned((List) entry.getValue())) {
29 | 4 | addViolation(data, var.getAccessNodeParent(), var.getImage());
30 |  | }
31 |  | }
32 | 11 | return data;
33 |  | }
34 |  |
35 |  | }