Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 34 |  | Methods: | 2
| NCLOC: | 25 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
LocalVariableCouldBeFinal.java | 75% | 90.9% | 100% | 85.7% |

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 net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
7 |  | import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration;
8 |  | import net.sourceforge.pmd.ast.ASTMethodDeclaration;
9 |  |
10 |  | public class LocalVariableCouldBeFinal extends AbstractOptimizationRule {
11 |  |
12 | 9 | public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
13 | 9 | if (node.isInterface()) {
14 | 0 | return data;
15 |  | }
16 | 9 | return super.visit(node, data);
17 |  | }
18 |  |
19 | 12 | public Object visit(ASTLocalVariableDeclaration node, Object data) {
20 | 12 | if (node.isFinal()) {
21 | 1 | return data;
22 |  | }
23 | 11 | final String varName = getVarName(node);
24 |  |
25 | 11 | ASTMethodDeclaration md = (ASTMethodDeclaration) node.getFirstParentOfType(ASTMethodDeclaration.class);
26 | 11 | if (md != null) {
27 | 11 | if (!isVarWritterInMethod(varName, md)) {
28 | 4 | addViolation(data, node);
29 |  | }
30 |  | }
31 | 11 | return data;
32 |  | }
33 |  |
34 |  | }