Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 97   Methods: 4
NCLOC: 57   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
UselessAssignment.java 0% 0% 0% 0%
coverage
 1    package net.sourceforge.pmd.rules;
 2   
 3    import net.sourceforge.pmd.AbstractRule;
 4    import net.sourceforge.pmd.RuleContext;
 5    import net.sourceforge.pmd.ast.ASTMethodDeclaration;
 6    import net.sourceforge.pmd.ast.SimpleNode;
 7    import net.sourceforge.pmd.dfa.IDataFlowNode;
 8    import net.sourceforge.pmd.dfa.pathfinder.DAAPathFinder;
 9    import net.sourceforge.pmd.dfa.pathfinder.Executable;
 10    import net.sourceforge.pmd.dfa.variableaccess.VariableAccess;
 11   
 12    import java.util.ArrayList;
 13    import java.util.HashMap;
 14    import java.util.List;
 15    import java.util.Map;
 16   
 17    public class UselessAssignment extends AbstractRule implements Executable {
 18   
 19    private RuleContext rc;
 20   
 21  0 public Object visit(ASTMethodDeclaration node, Object data) {
 22  0 this.rc = (RuleContext) data;
 23   
 24    /*
 25    IDataFlowNode n1 = node.getDataFlowNode();
 26    List f = n1.getFlow();
 27    for (Iterator i = f.iterator(); i.hasNext();) {
 28    DataFlowNode dfan = (DataFlowNode)i.next();
 29    System.out.println(dfan);
 30    List va = dfan.getVariableAccess();
 31    for (Iterator j = va.iterator(); j.hasNext();) {
 32    VariableAccess o = (VariableAccess)j.next();
 33    System.out.println(o);
 34    }
 35    }
 36    */
 37   
 38  0 DAAPathFinder a = new DAAPathFinder((IDataFlowNode) node.getDataFlowNode().getFlow().get(0), this);
 39  0 a.run();
 40   
 41  0 return data;
 42    }
 43   
 44    private static class Usage {
 45    public int accessType;
 46    public int line;
 47  0 public Usage(int accessType, int line) {
 48  0 this.accessType = accessType;
 49  0 this.line = line;
 50    }
 51  0 public String toString() {
 52  0 return "accessType = " + accessType + ", line = " + line;
 53    }
 54    }
 55   
 56  0 public void execute(List path) {
 57  0 Map hash = new HashMap();
 58  0 System.out.println("path size is " + path.size());
 59  0 for (int i = 0; i < path.size(); i++) {
 60    //System.out.println("i = " + i);
 61  0 IDataFlowNode inode = (IDataFlowNode) path.get(i);
 62  0 if (inode.getVariableAccess() == null) {
 63  0 continue;
 64    }
 65  0 for (int j = 0; j < inode.getVariableAccess().size(); j++) {
 66  0 VariableAccess va = (VariableAccess) inode.getVariableAccess().get(j);
 67  0 System.out.println("inode = " + inode + ", va = " + va);
 68  0 Object o = hash.get(va.getVariableName());
 69  0 if (o != null) {
 70  0 Usage u = (Usage) o;
 71    // At some point investigate and possibly reintroduce this line2 thing
 72    //int line2 = ((Integer) array.get(1)).intValue();
 73   
 74    // DD - definition followed by another definition
 75  0 if (va.isDefinition() && va.accessTypeMatches(u.accessType)) {
 76  0 System.out.println(va.getVariableName() + ":" + u);
 77  0 addViolation(rc, inode.getSimpleNode(), va.getVariableName());
 78    }
 79    /* // UR - ??
 80    else if (last == VariableAccess.UNDEFINITION && va.isReference()) {
 81    //this.rc.getReport().addRuleViolation(createRuleViolation(rc, inode.getSimpleNode(), va.getVariableName(), "UR"));
 82    }
 83    // DU - variable is defined and then goes out of scope
 84    // i.e., unused parameter
 85    else if (last == VariableAccess.DEFINITION && va.isUndefinition()) {
 86    if (inode.getSimpleNode() != null) {
 87    this.rc.getReport().addRuleViolation(createRuleViolation(rc, tmp, va.getVariableName(), "DU"));
 88    }
 89    }
 90    */
 91    }
 92  0 Usage u = new Usage(va.getAccessType(), inode.getLine());
 93  0 hash.put(va.getVariableName(), u);
 94    }
 95    }
 96    }
 97    }