001: package tide.exttools.PMD;
002:
003: import tide.editor.linemessages.*;
004: import java.awt.Color;
005: import tide.utils.SyntaxUtils;
006: import snow.html.HTMLUtils;
007: import snow.utils.storage.StorageVector;
008:
009: /** From the parsed pmd outputs.
010: */
011: public final class PMDMessage extends LineMessage {
012: String mess;
013: String shortMess; // remove "Violation: "
014: String category = "?";
015:
016: int priority = 1;
017: int col;
018:
019: /** mess example:
020: snow.lookandfeel.CustomOceanEditor.java:25:Violation: Unused Code Rules: UnusedFormalParameter (priority 3)
021: Avoid unused constructor parameters such as 'props'
022: at C:\sources\other\Script\src\snow\lookandfeel\CustomOceanEditor.java:25
023: */
024: private PMDMessage(String javaName, String mess, int line, int col,
025: long created) {
026: super (javaName, line, created);
027: this .mess = mess;
028: this .col = col;
029:
030: // ignore lines in short message:
031: this .shortMess = mess;
032: int posAt = shortMess.indexOf("\n at ");
033: if (posAt > 0)
034: shortMess = shortMess.substring(0, posAt).trim();
035:
036: shortMess = shortMess.replace("\n", " ");
037:
038: if (shortMess.startsWith("Violation: ")) {
039: shortMess = shortMess.substring(11);
040: int pos = shortMess.indexOf(" (");
041: category = shortMess.substring(0, pos);
042: shortMess = shortMess.substring(pos).trim();
043:
044: if (shortMess.startsWith("(priority ")) {
045: pos = shortMess.indexOf(')', 10);
046: if (pos > 0) {
047: try {
048: priority = Integer.parseInt(shortMess
049: .substring(10, pos));
050: } catch (Exception e) {
051: e.printStackTrace();
052: }
053: shortMess = shortMess.substring(pos + 1).trim();
054: }
055: }
056: shortMess = SyntaxUtils
057: .makeAllJavaNamesSimpleInText(shortMess);
058: }
059: }
060:
061: public static PMDMessage createAndAdd(final String javaName,
062: final String mess, final int lineNr, int col,
063: boolean ignoreIrrelevant) {
064: PMDMessage lm = new PMDMessage(javaName, mess, lineNr, col,
065: System.currentTimeMillis());
066:
067: if (ignoreIrrelevant
068: && LineMessagesManager.getInstance()
069: .getIrrelevantCategories().contains(
070: lm.getCategory()))
071: return lm;
072:
073: LineMessagesManager.getInstance().add(lm);
074: return lm;
075: }
076:
077: @Override
078: public String toStringHTML() {
079: return HTMLUtils.createCODEHTMLFromText("PMD: " + shortMess);
080: }
081:
082: @Override
083: public String getMessage() {
084: return mess;
085: }
086:
087: @Override
088: public String getMessageForTableColumn() {
089: return shortMess;
090: }
091:
092: @Override
093: public String getCategory() {
094: return category;
095: }
096:
097: @Override
098: public Color getColor() {
099: return Color.PINK;
100: }
101:
102: @Override
103: public String getLetter() {
104: return null;
105: } // point
106:
107: @Override
108: public int getShiftX() {
109: return 8;
110: }
111:
112: @Override
113: public int getColumn() {
114: return col;
115: }
116:
117: @Override
118: public String getMessageOriginator() {
119: return "PMD";
120: }
121:
122: @Override
123: public int getPriority() {
124: return priority;
125: }
126:
127: @Override
128: public StorageVector getStorageRepresentation() {
129: StorageVector sv = new StorageVector();
130: sv.add(1);
131: sv.add("PMDMessage");
132: sv.add(javaName);
133: sv.add(mess);
134: sv.add(line);
135: sv.add(created);
136: sv.add(col);
137: return sv;
138: }
139:
140: public static PMDMessage createFromStorageVector(StorageVector sv) {
141: long created = sv.size() > 5 ? (Long) sv.get(5) : System
142: .currentTimeMillis();
143: int col = sv.size() > 6 ? (Integer) sv.get(6) : -1;
144: return new PMDMessage((String) sv.get(2), (String) sv.get(3),
145: (Integer) sv.get(4), col, created);
146: }
147:
148: }
|