KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui > SwingGUIBugReporter


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003-2005, 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 package edu.umd.cs.findbugs.gui;
20
21 import edu.umd.cs.findbugs.SortedBugCollection;
22 import edu.umd.cs.findbugs.TextUIBugReporter;
23 import edu.umd.cs.findbugs.classfile.ClassDescriptor;
24
25 /**
26  * BugReporter used by AnalysisRun.
27  */

28 public class SwingGUIBugReporter extends TextUIBugReporter {
29     private final AnalysisRun analysisRun;
30     private SortedBugCollection bugCollection;
31     private AnalysisErrorDialog errorDialog;
32     private int errorCount;
33     
34     /**
35      * Constructor.
36      *
37      * @param analysisRun
38      */

39     public SwingGUIBugReporter(AnalysisRun analysisRun) {
40         this.analysisRun = analysisRun;
41         this.bugCollection = new SortedBugCollection(getProjectStats());
42     }
43     
44     public SortedBugCollection getBugCollection() {
45         return bugCollection;
46     }
47     
48     public boolean errorsOccurred() {
49         return errorCount > 0;
50     }
51     
52     public AnalysisErrorDialog getErrorDialog() {
53         return errorDialog;
54     }
55     
56     public void observeClass(ClassDescriptor classDescriptor) {
57     }
58     
59     @Override JavaDoc
60     public void reportMissingClass(ClassNotFoundException JavaDoc ex) {
61         ++errorCount;
62         super.reportMissingClass(ex);
63         String JavaDoc message = getMissingClassName(ex);
64         bugCollection.addMissingClass(message);
65     }
66     
67     @Override JavaDoc
68     public void logError(String JavaDoc message) {
69         ++errorCount;
70         analysisRun.getFrame().getLogger().logMessage(ConsoleLogger.WARNING, message);
71         super.logError(message);
72         bugCollection.addError(message);
73     }
74     
75     public void finish() {
76     }
77     
78     @Override JavaDoc
79     public void doReportBug(edu.umd.cs.findbugs.BugInstance bugInstance) {
80         checkBugInstance(bugInstance);
81         if (bugCollection.add(bugInstance))
82             notifyObservers(bugInstance);
83     }
84
85     private void createDialog() {
86         if (errorDialog == null) {
87             errorDialog = new AnalysisErrorDialog(analysisRun.getFrame(), true, this);
88         }
89     }
90     
91     //@Override
92
@Override JavaDoc
93     public void reportQueuedErrors() {
94         createDialog();
95         errorDialog.clear();
96         super.reportQueuedErrors();
97         errorDialog.finish();
98     }
99     
100     //@Override
101
@Override JavaDoc
102     protected void emitLine(String JavaDoc line) {
103         line = line.replaceAll("\t", " ");
104         errorDialog.addLine(line);
105     }
106 }
107
Popular Tags