KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > tools > html > PrintBugDescriptions


1 /*
2  * Generate HTML file containing bug descriptions
3  * Copyright (C) 2004, 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.tools.html;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import edu.umd.cs.findbugs.BugPattern;
28 import edu.umd.cs.findbugs.DetectorFactory;
29 import edu.umd.cs.findbugs.DetectorFactoryCollection;
30 import edu.umd.cs.findbugs.I18N;
31
32 public abstract class PrintBugDescriptions {
33     public void print() throws IOException JavaDoc {
34         // Ensure bug patterns are loaded
35
DetectorFactoryCollection factories = DetectorFactoryCollection.instance();
36
37         // Find all bug patterns reported by at least one non-disabled detector.
38
Collection JavaDoc<BugPattern> enabledPatternSet = new HashSet JavaDoc<BugPattern>();
39         for (Iterator JavaDoc<DetectorFactory> i = factories.factoryIterator(); i.hasNext(); ) {
40             DetectorFactory factory = i.next();
41             if (isEnabled(factory))
42                 enabledPatternSet.addAll(factory.getReportedBugPatterns());
43         }
44
45         prologue();
46
47         Iterator JavaDoc<BugPattern> i = I18N.instance().bugPatternIterator();
48         while (i.hasNext()) {
49             BugPattern bugPattern = i.next();
50             if (!enabledPatternSet.contains(bugPattern))
51                 continue;
52             emit(bugPattern);
53         }
54
55         epilogue();
56     }
57
58     protected boolean isEnabled(DetectorFactory factory) {
59         return factory.isDefaultEnabled();
60     }
61
62     protected abstract void prologue() throws IOException JavaDoc;
63
64     protected abstract void emit(BugPattern bugPattern) throws IOException JavaDoc;
65
66     protected abstract void epilogue() throws IOException JavaDoc;
67 }
68
69 // vim:ts=3
70
Popular Tags