001: package tide.exttools.findbugs;
002:
003: import tide.editor.linemessages.*;
004: import tide.utils.SyntaxUtils;
005: import java.awt.Color;
006: import snow.html.HTMLUtils;
007: import snow.utils.StringUtils;
008: import snow.utils.storage.StorageVector;
009:
010: public final class FBLineMessage extends LineMessage {
011: private final String mess;
012: private String messShort;
013: private int priority = 1;
014: private String category = "";
015: private String fullBugName = "";
016:
017: public FBLineMessage(String javaName, String mess, int line,
018: String messShort, int priority, String category, // Style, Bad Practice, ...
019: String fullBugName, long created) {
020: super (javaName, line, created);
021:
022: this .mess = mess;
023: this .messShort = messShort;
024: this .priority = priority;
025: this .category = category;
026:
027: if (fullBugName == null || fullBugName.length() == 0) {
028: this .fullBugName = StringUtils
029: .extractFromFirstToNext_Excluded(mess, "Bug ", ","); // null if not found
030: } else {
031: this .fullBugName = fullBugName;
032: }
033: }
034:
035: /** old version 1 */
036: private FBLineMessage(String javaName, String mess, int line,
037: long created) {
038: super (javaName, line, created);
039: this .mess = mess;
040: // remove first line
041: messShort = StringUtils.removeFirstLine(mess);
042: // TODO: sometimes repeating ! => (look in fb)
043: messShort = messShort.replace("\n", " ");
044: // ignore lines in short message:
045: int posAt = messShort.indexOf("\tat ");
046: if (posAt > 0)
047: messShort = messShort.substring(0, posAt).trim();
048:
049: this .messShort = SyntaxUtils
050: .makeAllJavaNamesSimpleInText(messShort);
051:
052: try {
053: priority = Integer.parseInt(StringUtils
054: .extractFromFirstToNext_Excluded(mess, "priority=",
055: ","));
056: } catch (Exception e) {
057: e.printStackTrace();
058: }
059:
060: category = StringUtils.extractFromFirstToNext_Excluded(mess,
061: "cat=", "\n");
062: fullBugName = StringUtils.extractFromFirstToNext_Excluded(mess,
063: "Bug ", ",");
064: }
065:
066: @Override
067: public String toStringHTML() {
068: return HTMLUtils.createCODEHTMLFromText("FB: " + messShort);
069: }
070:
071: @Override
072: public String getMessage() {
073: return mess;
074: }
075:
076: @Override
077: public Color getColor() {
078: return Color.RED;
079: }
080:
081: @Override
082: public String getLetter() {
083: return null;
084: } // point
085:
086: @Override
087: public int getShiftX() {
088: return 1;
089: }
090:
091: @Override
092: public String getMessageOriginator() {
093: return "FindBugs";
094: }
095:
096: @Override
097: public String getMessageForTableColumn() {
098: return messShort;
099: }
100:
101: @Override
102: public String getCategory() {
103: return category + ": " + fullBugName;
104: }
105:
106: @Override
107: public int getPriority() {
108: return priority;
109: }
110:
111: @Override
112: public StorageVector getStorageRepresentation() {
113: StorageVector sv = new StorageVector();
114: sv.add(2);
115: sv.add("FBLineMessage"); //FBLineMessage.class.getName());
116: sv.add(javaName); // 2
117: sv.add(mess); // 3
118: sv.add(line); // 4
119: sv.add(messShort); // 5
120: sv.add(priority); // 6
121: sv.add(category); // 7
122: sv.add(created); // 8
123: sv.add(fullBugName);
124: return sv;
125: }
126:
127: public static FBLineMessage createFromStorageVector(StorageVector sv) {
128: int version = (Integer) sv.get(0);
129: if (version == 1) {
130: return new FBLineMessage((String) sv.get(2), (String) sv
131: .get(3), (Integer) sv.get(4), System
132: .currentTimeMillis());
133: } else {
134: long created = sv.size() > 8 ? (Long) sv.get(8) : System
135: .currentTimeMillis();
136: String fullBugName = sv.size() > 9 ? (String) sv.get(9)
137: : "";
138: return new FBLineMessage((String) sv.get(2), (String) sv
139: .get(3), (Integer) sv.get(4), (String) sv.get(5),
140: (Integer) sv.get(6), (String) sv.get(7),
141: fullBugName, created);
142: }
143: }
144:
145: }
|