KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003-2006 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs;
21
22 import edu.umd.cs.findbugs.ba.Debug;
23 import edu.umd.cs.findbugs.ba.MethodUnprofitableException;
24 import edu.umd.cs.findbugs.ba.MissingClassException;
25 import edu.umd.cs.findbugs.classfile.ClassDescriptor;
26
27 public abstract class BugCollectionBugReporter extends TextUIBugReporter implements Debug {
28     private SortedBugCollection bugCollection;
29     private Project project;
30
31     public BugCollectionBugReporter(Project project) {
32         this.project = project;
33         this.bugCollection = new SortedBugCollection(getProjectStats());
34
35         bugCollection.setTimestamp(System.currentTimeMillis());
36     }
37
38     public Project getProject() {
39         return project;
40     }
41
42     public BugCollection getBugCollection() {
43         return bugCollection;
44     }
45
46     public void observeClass(ClassDescriptor classDescriptor) {
47     }
48
49     @Override JavaDoc
50     public void logError(String JavaDoc message) {
51         bugCollection.addError(message);
52         super.logError(message);
53     }
54
55     @Override JavaDoc
56     public void logError(String JavaDoc message, Throwable JavaDoc e) {
57         if (e instanceof MissingClassException) {
58             MissingClassException e2 = (MissingClassException)e;
59             reportMissingClass(e2.getClassNotFoundException());
60             return;
61         }
62         if (e instanceof MethodUnprofitableException) {
63             // TODO: log this
64
return;
65         }
66         bugCollection.addError(message, e);
67         super.logError(message, e);
68     }
69
70     @Override JavaDoc
71     public void reportMissingClass(ClassNotFoundException JavaDoc ex) {
72         bugCollection.addMissingClass(getMissingClassName(ex));
73         super.reportMissingClass(ex);
74     }
75
76     @Override JavaDoc
77     public void doReportBug(BugInstance bugInstance) {
78         if (VERIFY_INTEGRITY) checkBugInstance(bugInstance);
79         if (bugCollection.add(bugInstance))
80             notifyObservers(bugInstance);
81     }
82
83     /* (non-Javadoc)
84      * @see edu.umd.cs.findbugs.BugReporter#getRealBugReporter()
85      */

86     @Override JavaDoc
87     public BugReporter getRealBugReporter() {
88         return this;
89     }
90 }
91
92 // vim:ts=4
93
Popular Tags