KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ErrorCountingBugReporter


1 package edu.umd.cs.findbugs;
2
3 import java.util.HashSet JavaDoc;
4 import java.util.Set JavaDoc;
5
6 /**
7  * A delegating bug reporter which counts reported bug instances,
8  * missing classes, and serious analysis errors.
9  */

10 public class ErrorCountingBugReporter extends DelegatingBugReporter {
11     private int bugCount;
12     private int missingClassCount;
13     private int errorCount;
14     private Set JavaDoc<String JavaDoc> missingClassSet = new HashSet JavaDoc<String JavaDoc>();
15
16     public ErrorCountingBugReporter(BugReporter realBugReporter) {
17         super(realBugReporter);
18         this.bugCount = 0;
19         this.missingClassCount = 0;
20         this.errorCount = 0;
21
22         // Add an observer to record when bugs make it through
23
// all priority and filter criteria, so our bug count is
24
// accurate.
25
realBugReporter.addObserver(new BugReporterObserver() {
26             public void reportBug(BugInstance bugInstance) {
27                 ++bugCount;
28             }
29         });
30     }
31
32     public int getBugCount() {
33         return bugCount;
34     }
35
36     public int getMissingClassCount() {
37         return missingClassCount;
38     }
39
40     public int getErrorCount() {
41         return errorCount;
42     }
43
44     @Override JavaDoc
45     public void logError(String JavaDoc message) {
46         ++errorCount;
47         super.logError(message);
48     }
49
50     @Override JavaDoc
51     public void reportMissingClass(ClassNotFoundException JavaDoc ex) {
52         String JavaDoc missing = AbstractBugReporter.getMissingClassName(ex);
53         if (missingClassSet.add(missing))
54             ++missingClassCount;
55         super.reportMissingClass(ex);
56     }
57 }
58
Popular Tags