KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003,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;
21
22 /**
23  * A BugPattern object collects all of the metadata for a particular
24  * species of BugInstance. Specifically, it stores the human-readable
25  * text for displaying a bug instance. BugPatterns derive from the
26  * BugPattern elements in the "findbugs.xml" and "messages.xml"
27  * found in a FindBugs plugin.
28  *
29  * @author David Hovemeyer
30  * @see BugInstance
31  */

32 public class BugPattern implements Comparable JavaDoc<BugPattern> {
33     private String JavaDoc type;
34     private String JavaDoc abbrev;
35     private String JavaDoc category;
36     private boolean experimental;
37     private String JavaDoc shortDescription;
38     private String JavaDoc longDescription;
39     private String JavaDoc detailText;
40     private String JavaDoc detailHTML;
41
42     /**
43      * Constructor.
44      *
45      * @param type the type (species) of BugInstance
46      * @param abbrev the abbreviation or "bug code"; see {@link BugCode}
47      * @param category the category
48      * @param experimental true if the bug pattern is experimental
49      * @param shortDescription short one-line description of the bug species
50      * @param longDescription longer one-line description; may contain placeholders
51      * for use by {@link FindBugsMessageFormat} to format BugAnnotations
52      * @param detailText HTML text containing a full description of the bug species
53      */

54     public BugPattern(String JavaDoc type, String JavaDoc abbrev, String JavaDoc category, boolean experimental,
55                       String JavaDoc shortDescription, String JavaDoc longDescription, String JavaDoc detailText) {
56         this.type = type;
57         this.abbrev = abbrev;
58         this.category = category;
59         this.experimental = experimental;
60         this.shortDescription = shortDescription;
61         this.longDescription = longDescription;
62         this.detailText = detailText;
63     }
64
65     /**
66      * Get the type (species).
67      */

68     public String JavaDoc getType() {
69         return type;
70     }
71
72     /**
73      * Get the abbreviation or "bug code".
74      */

75     public String JavaDoc getAbbrev() {
76         return abbrev;
77     }
78
79     /**
80      * Get the category.
81      */

82     public String JavaDoc getCategory() {
83         return category;
84     }
85
86     /**
87      * Is the bug pattern experimental?
88      */

89     public boolean isExperimental() {
90         return experimental;
91     }
92
93     /**
94      * Get the short description.
95      */

96     public String JavaDoc getShortDescription() {
97         return shortDescription;
98     }
99
100     /**
101      * Get the long description.
102      */

103     public String JavaDoc getLongDescription() {
104         return longDescription;
105     }
106
107     /**
108      * Get the HTML detail text describing the bug.
109      */

110     public String JavaDoc getDetailText() {
111         return detailText;
112     }
113
114     /**
115      * Get the detail text as a complete HTML document.
116      */

117     public String JavaDoc getDetailHTML() {
118         if (detailHTML == null) {
119             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
120             buf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
121             buf.append("<HTML><HEAD><TITLE>");
122             buf.append(getShortDescription());
123             buf.append("</TITLE></HEAD><BODY><H1>");
124             buf.append(getShortDescription());
125             buf.append("</H1>\n");
126             buf.append(getDetailText());
127             buf.append("</BODY></HTML>\n");
128             detailHTML = buf.toString();
129         }
130         return detailHTML;
131     }
132
133     public int compareTo(BugPattern other) {
134         return type.compareTo(other.type);
135     }
136
137     @Override JavaDoc
138     public int hashCode() {
139         return type.hashCode();
140     }
141
142     @Override JavaDoc
143     public boolean equals(Object JavaDoc o) {
144         if (!(o instanceof BugPattern))
145             return false;
146         BugPattern other = (BugPattern) o;
147         return type.equals(other.type);
148     }
149
150 }
151
152 // vim:ts=4
153
Popular Tags