001: /*
002: * FindBugs - Find bugs in Java programs
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs;
021:
022: /**
023: * A BugPattern object collects all of the metadata for a particular
024: * species of BugInstance. Specifically, it stores the human-readable
025: * text for displaying a bug instance. BugPatterns derive from the
026: * BugPattern elements in the "findbugs.xml" and "messages.xml"
027: * found in a FindBugs plugin.
028: *
029: * @author David Hovemeyer
030: * @see BugInstance
031: */
032: public class BugPattern implements Comparable<BugPattern> {
033: final private String type;
034: final private String abbrev;
035: final private String category;
036: final private boolean experimental;
037: final private String shortDescription;
038: final private String longDescription;
039: final private String detailText;
040: private String detailHTML;
041: final int cweid;
042:
043: /**
044: * Constructor.
045: *
046: * @param type the type (species) of BugInstance
047: * @param abbrev the abbreviation or "bug code"; see {@link BugCode}
048: * @param category the category
049: * @param experimental true if the bug pattern is experimental
050: * @param shortDescription short one-line description of the bug species
051: * @param longDescription longer one-line description; may contain placeholders
052: * for use by {@link FindBugsMessageFormat} to format BugAnnotations
053: * @param detailText HTML text containing a full description of the bug species
054: */
055: public BugPattern(String type, String abbrev, String category,
056: boolean experimental, String shortDescription,
057: String longDescription, String detailText) {
058: this (type, abbrev, category, experimental, shortDescription,
059: longDescription, detailText, 0);
060: }
061:
062: /**
063: * Constructor.
064: *
065: * @param type the type (species) of BugInstance
066: * @param abbrev the abbreviation or "bug code"; see {@link BugCode}
067: * @param category the category
068: * @param experimental true if the bug pattern is experimental
069: * @param shortDescription short one-line description of the bug species
070: * @param longDescription longer one-line description; may contain placeholders
071: * for use by {@link FindBugsMessageFormat} to format BugAnnotations
072: * @param detailText HTML text containing a full description of the bug species
073: */
074: public BugPattern(String type, String abbrev, String category,
075: boolean experimental, String shortDescription,
076: String longDescription, String detailText, int cweid) {
077:
078: this .type = type;
079: this .abbrev = abbrev;
080: this .category = category;
081: this .experimental = experimental;
082: this .shortDescription = shortDescription;
083: this .longDescription = longDescription;
084: this .detailText = detailText;
085: this .cweid = cweid;
086: }
087:
088: static final BugPattern REALLY_UNKNOWN = new BugPattern(
089: "REALLY_UNKNOWN",
090: "TEST",
091: "CORRECTNESS",
092: false,
093: "Unknown warning; core bug patterns not found",
094: "Unknown warning BUG_PATTERN in {1}; core bug patterns not found",
095: "<p>A warning was recorded, but findbugs can't find the description of this bug pattern "
096: + "and so can't describe it. This should occur only in cases of a bug in FindBugs or its configuration, "
097: + "or perhaps if an analysis was generated using a plugin, but that plugin is not currently loaded. "
098: + "</p>");
099:
100: /**
101: * Get the type (species).
102: */
103: public String getType() {
104: return type;
105: }
106:
107: /**
108: * Get the abbreviation or "bug code".
109: */
110: public String getAbbrev() {
111: return abbrev;
112: }
113:
114: /**
115: * Get the category.
116: */
117: public String getCategory() {
118: return category;
119: }
120:
121: public String getCategoryAbbrev() {
122: String categoryAbbrev = null;
123: BugCategory bcat = I18N.instance()
124: .getBugCategory(getCategory());
125: if (bcat != null)
126: categoryAbbrev = bcat.getAbbrev();
127: if (categoryAbbrev == null)
128: categoryAbbrev = TextUIBugReporter.OTHER_CATEGORY_ABBREV;
129: return categoryAbbrev;
130: }
131:
132: /**
133: * Is the bug pattern experimental?
134: */
135: public boolean isExperimental() {
136: return experimental;
137: }
138:
139: /**
140: * Get the short description.
141: */
142: public String getShortDescription() {
143: return shortDescription;
144: }
145:
146: /**
147: * Get the long description.
148: */
149: public String getLongDescription() {
150: return longDescription;
151: }
152:
153: /**
154: * Get the HTML detail text describing the bug.
155: */
156: public String getDetailText() {
157: return detailText;
158: }
159:
160: /**
161: * Get the detail text as a complete HTML document.
162: */
163: public String getDetailHTML() {
164: if (detailHTML == null) {
165: StringBuffer buf = new StringBuffer();
166: buf
167: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
168: buf.append("<HTML><HEAD><TITLE>");
169: buf.append(getShortDescription());
170: buf.append("</TITLE></HEAD><BODY><H1>");
171: buf.append(getShortDescription());
172: buf.append("</H1>\n");
173: buf.append(getDetailText());
174: buf.append("</BODY></HTML>\n");
175: detailHTML = buf.toString();
176: }
177: return detailHTML;
178: }
179:
180: public int compareTo(BugPattern other) {
181: return type.compareTo(other.type);
182: }
183:
184: @Override
185: public int hashCode() {
186: return type.hashCode();
187: }
188:
189: @Override
190: public boolean equals(Object o) {
191: if (!(o instanceof BugPattern))
192: return false;
193: BugPattern other = (BugPattern) o;
194: return type.equals(other.type);
195: }
196:
197: /**
198: * @return Returns the cweid.
199: */
200: public int getCWEid() {
201: return cweid;
202: }
203: }
204:
205: // vim:ts=4
|