Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT
file stats: LOC: 247   Methods: 30
NCLOC: 187   Classes: 4
 
 Source file Conditionals Statements Methods TOTAL
Report.java 60.7% 61.3% 63.3% 61.6%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd;
 5   
 6    import net.sourceforge.pmd.dfa.report.ReportTree;
 7    import net.sourceforge.pmd.stat.Metric;
 8   
 9    import java.util.ArrayList;
 10    import java.util.HashMap;
 11    import java.util.HashSet;
 12    import java.util.Iterator;
 13    import java.util.List;
 14    import java.util.Map;
 15    import java.util.Set;
 16    import java.util.TreeSet;
 17   
 18    public class Report {
 19   
 20    public static class ReadableDuration {
 21    private long duration;
 22   
 23  10 public ReadableDuration(long duration) {
 24  10 this.duration = duration;
 25    }
 26   
 27  10 public String getTime() {
 28  10 long seconds = 0;
 29  10 long minutes = 0;
 30  10 long hours = 0;
 31   
 32  10 if (duration > 1000) {
 33  4 seconds = duration / 1000;
 34    }
 35   
 36  10 if (seconds > 60) {
 37  3 minutes = seconds / 60;
 38  3 seconds = seconds % 60;
 39    }
 40   
 41  10 if (minutes > 60) {
 42  1 hours = minutes / 60;
 43  1 minutes = minutes % 60;
 44    }
 45   
 46  10 StringBuffer res = new StringBuffer();
 47  10 if (hours > 0) {
 48  1 res.append(hours + "h ");
 49    }
 50  10 if (hours > 0 || minutes > 0) {
 51  3 res.append(minutes + "m ");
 52    }
 53  10 res.append(seconds + "s");
 54  10 return res.toString();
 55    }
 56    }
 57   
 58    public static class ProcessingError {
 59    private String msg;
 60    private String file;
 61   
 62  1 public ProcessingError(String msg, String file) {
 63  1 this.msg = msg;
 64  1 this.file = file;
 65    }
 66   
 67  1 public String getMsg() {
 68  1 return msg;
 69    }
 70   
 71  1 public String getFile() {
 72  1 return file;
 73    }
 74    }
 75   
 76    public static class SuppressedViolation {
 77    private IRuleViolation rv;
 78    private boolean isNOPMD;
 79   
 80  13 public SuppressedViolation(IRuleViolation rv, boolean isNOPMD) {
 81  13 this.isNOPMD = isNOPMD;
 82  13 this.rv = rv;
 83    }
 84   
 85  0 public boolean suppressedByNOPMD() {
 86  0 return this.isNOPMD;
 87    }
 88   
 89  0 public boolean suppressedByAnnotation() {
 90  0 return !this.isNOPMD;
 91    }
 92   
 93  0 public IRuleViolation getRuleViolation() {
 94  0 return this.rv;
 95    }
 96    }
 97   
 98    /*
 99    * The idea is to store the violations in a tree instead of a list, to do
 100    * better and faster sort and filter mechanism and to visualize the result
 101    * als tree. (ide plugins).
 102    * */
 103    private ReportTree violationTree = new ReportTree();
 104   
 105    // Note that this and the above data structure are both being maintained for a bit
 106    private Set violations = new TreeSet(new RuleViolation.RuleViolationComparator());
 107    private Set metrics = new HashSet();
 108    private List listeners = new ArrayList();
 109    private List errors = new ArrayList();
 110    private Set linesToExclude = new HashSet();
 111    private long start;
 112    private long end;
 113   
 114    private List suppressedRuleViolations = new ArrayList();
 115   
 116  1056 public void exclude(Set lines) {
 117  1056 linesToExclude = lines;
 118    }
 119   
 120  0 public Map getCountSummary() {
 121  0 Map summary = new HashMap();
 122  0 for (Iterator iter = violationTree.iterator(); iter.hasNext();) {
 123  0 IRuleViolation rv = (IRuleViolation) iter.next();
 124  0 String key = (rv.getPackageName() == "" ? "" : (rv.getPackageName() + ".")) + rv.getClassName();
 125  0 Object o = summary.get(key);
 126  0 if (o == null) {
 127  0 Integer value = new Integer(1);
 128  0 summary.put(key, value);
 129    } else {
 130  0 Integer value = (Integer) o;
 131  0 summary.put(key, new Integer(value.intValue() + 1));
 132    }
 133    }
 134  0 return summary;
 135    }
 136   
 137  0 public ReportTree getViolationTree() {
 138  0 return this.violationTree;
 139    }
 140   
 141   
 142    /**
 143    * @return a Map summarizing the Report: String (rule name) ->Integer (count of violations)
 144    */
 145  0 public Map getSummary() {
 146  0 Map summary = new HashMap();
 147  0 for (Iterator i = violations.iterator(); i.hasNext();) {
 148  0 IRuleViolation rv = (IRuleViolation) i.next();
 149  0 if (!summary.containsKey(rv.getRule().getName())) {
 150  0 summary.put(rv.getRule().getName(), new Integer(0));
 151    }
 152  0 Integer count = (Integer) summary.get(rv.getRule().getName());
 153  0 count = new Integer(count.intValue() + 1);
 154  0 summary.put(rv.getRule().getName(), count);
 155    }
 156  0 return summary;
 157    }
 158   
 159  1 public void addListener(ReportListener listener) {
 160  1 listeners.add(listener);
 161    }
 162   
 163  7 public List getSuppressedRuleViolations() {
 164  7 return this.suppressedRuleViolations;
 165    }
 166   
 167  2673 public void addRuleViolation(IRuleViolation violation) {
 168    // NOPMD excluder
 169  2673 if (linesToExclude.contains(new Integer(violation.getBeginLine()))) {
 170  3 suppressedRuleViolations.add(new SuppressedViolation(violation, true));
 171  3 return;
 172    }
 173   
 174  2670 if (violation.isSuppressed()) {
 175  10 suppressedRuleViolations.add(new SuppressedViolation(violation, false));
 176  10 return;
 177    }
 178   
 179   
 180  2660 violations.add(violation);
 181  2660 violationTree.addRuleViolation(violation);
 182  2660 for (Iterator i = listeners.iterator(); i.hasNext();) {
 183  1 ReportListener listener = (ReportListener) i.next();
 184  1 listener.ruleViolationAdded(violation);
 185    }
 186    }
 187   
 188  176 public void addMetric(Metric metric) {
 189  176 metrics.add(metric);
 190  176 for (Iterator i = listeners.iterator(); i.hasNext();) {
 191  0 ReportListener listener = (ReportListener) i.next();
 192  0 listener.metricAdded(metric);
 193    }
 194    }
 195   
 196  1 public void addError(ProcessingError error) {
 197  1 errors.add(error);
 198    }
 199   
 200  3 public boolean hasMetrics() {
 201  3 return !metrics.isEmpty();
 202    }
 203   
 204  2 public Iterator metrics() {
 205  2 return metrics.iterator();
 206    }
 207   
 208  5 public boolean isEmpty() {
 209  5 return !violations.iterator().hasNext() && errors.isEmpty();
 210    }
 211   
 212  0 public boolean treeIsEmpty() {
 213  0 return !violationTree.iterator().hasNext();
 214    }
 215   
 216  0 public Iterator treeIterator() {
 217  0 return violationTree.iterator();
 218    }
 219   
 220  13 public Iterator iterator() {
 221  13 return violations.iterator();
 222    }
 223   
 224  5 public Iterator errors() {
 225  5 return errors.iterator();
 226    }
 227   
 228  0 public int treeSize() {
 229  0 return violationTree.size();
 230    }
 231   
 232  1246 public int size() {
 233  1246 return violations.size();
 234    }
 235   
 236  0 public void start() {
 237  0 start = System.currentTimeMillis();
 238    }
 239   
 240  0 public void end() {
 241  0 end = System.currentTimeMillis();
 242    }
 243   
 244  5 public long getElapsedTimeInMillis() {
 245  5 return end - start;
 246    }
 247    }