001: package tide.exttools.JLint;
002:
003: import tide.editor.linemessages.*;
004: import java.awt.Color;
005: import tide.editor.MainEditorFrame;
006: import snow.utils.storage.StorageVector;
007: import tide.utils.SyntaxUtils;
008: import snow.utils.StringUtils;
009:
010: /** From the parsed output.
011: */
012: public final class JLintLineMessage extends LineMessage {
013: String mess, shortMess;
014: String category = ""; // guessed
015: int priority = 1;
016:
017: private JLintLineMessage(String javaName, String mess, int line,
018: long created) {
019: super (javaName, line, created);
020: this .mess = mess;
021:
022: shortMess = SyntaxUtils.makeAllJavaNamesSimpleInText(mess);
023:
024: String jnPack = StringUtils.removeAfterLastIncluded(javaName,
025: ".");
026: if (jnPack != null) {
027: jnPack = jnPack.replace(".", "/") + "/";
028: shortMess = shortMess.replace(jnPack, "");
029: }
030:
031: // manual categorization based on doc and text part (tricky but good results !)
032: category = shortMess;
033:
034: // Bounds, Domain, Zero Result, Not Overridden
035: if (category.indexOf("is not synchronized") > 0) {
036: category = "Not synchronized";
037: } else if (category.endsWith("not overridden")) {
038: category = "Not overridden";
039: } else if (category.indexOf("can cause deadlock") > 0) {
040: category = "Can cause deadlock";
041: } else if (category
042: .startsWith("Data can be lost as a result of truncation")) {
043: category = "Data can be lost as a result of truncation";
044: } else if (category
045: .indexOf("forms the loop in class dependency graph") > 0) {
046: category = "Loop in class dependency graph";
047: } else if (category.indexOf("may be out of array bounds") > 0) {
048: priority = 2;
049: category = "Potential out of array bound";
050: } else if (category.indexOf("is out of array bounds") > 0) {
051: category = "Out of array bound";
052: } else if (category.indexOf("requested while holding lock") > 0) {
053: category = "Potential locking problem";
054: } else if (category
055: .indexOf("can be accessed from different threads") > 0) {
056: category = "Thread access issue";
057: } else if (category.indexOf("without check for NULL") > 0) {
058: category = "Missing check for null";
059: } else if (category.indexOf("is not overridden by method") > 0) {
060: category = "Missing override";
061: } else if (category.indexOf("changed outside synchronization") > 0) {
062: category = "Missing synchronization";
063: } else if (category.indexOf("Zero operand for") >= 0) {
064: category = "Zero operand";
065: }
066:
067: else {
068: // remove names..
069: category = StringUtils
070: .balancedRemoveAll(category, "'", "'");
071: }
072: }
073:
074: public static void createAndAdd(final String line,
075: boolean ignoreIrrelevant) {
076: int pos = line.indexOf(".java:");
077: if (pos == -1)
078: return;
079: String javaName = line.substring(0, pos);
080: String pa = MainEditorFrame.instance.getActualProject()
081: .getSources_Home().getAbsolutePath();
082: if (!pa.endsWith("\\"))
083: pa += "\\";
084: if (javaName.startsWith(pa)) {
085: javaName = javaName.substring(pa.length());
086: }
087:
088: javaName = javaName.replace('\\', '.');
089:
090: //System.out.println("JN="+javaName);
091:
092: int posEnd = line.indexOf(':', pos + 6);
093: int lineNr = -1;
094: if (posEnd > 0) {
095: try {
096: lineNr = Integer.parseInt(line.substring(pos + 6,
097: posEnd));
098: } catch (Exception e) {
099: e.printStackTrace();
100: }
101: }
102:
103: String mess = line.substring(posEnd + 1).trim();
104: if (mess.endsWith(".")) {
105: mess = mess.substring(0, mess.length() - 1);
106: }
107: JLintLineMessage lm = new JLintLineMessage(javaName, mess,
108: lineNr, System.currentTimeMillis());
109:
110: if (ignoreIrrelevant
111: && LineMessagesManager.getInstance()
112: .getIrrelevantCategories().contains(
113: lm.getCategory()))
114: return;
115:
116: LineMessagesManager.getInstance().add(lm);
117: }
118:
119: @Override
120: public String getMessage() {
121: return mess;
122: }
123:
124: @Override
125: public String getCategory() {
126: return category;
127: } // manually parsed and guessed
128:
129: @Override
130: public int getPriority() {
131: return priority;
132: }
133:
134: @Override
135: public String getMessageForTableColumn() {
136: return shortMess;
137: }
138:
139: @Override
140: public String toStringHTML() {
141: return "JLint: " + shortMess;
142: }
143:
144: @Override
145: public Color getColor() {
146: return Color.cyan;
147: }
148:
149: @Override
150: public String getLetter() {
151: return null;
152: } // point
153:
154: @Override
155: public int getShiftX() {
156: return 4;
157: }
158:
159: @Override
160: public String getMessageOriginator() {
161: return "JLint";
162: }
163:
164: @Override
165: public StorageVector getStorageRepresentation() {
166: StorageVector sv = new StorageVector();
167: sv.add(1);
168: sv.add("JLintLineMessage");
169: sv.add(javaName);
170: sv.add(mess);
171: sv.add(line);
172: sv.add(created);
173: return sv;
174: }
175:
176: public static JLintLineMessage createFromStorageVector(
177: StorageVector sv) {
178: long created = sv.size() > 5 ? (Long) sv.get(5) : System
179: .currentTimeMillis();
180:
181: return new JLintLineMessage((String) sv.get(2), (String) sv
182: .get(3), (Integer) sv.get(4), created);
183: }
184: }
|