001: package tide.exttools.lint4j;
002:
003: import tide.editor.linemessages.*;
004: import java.awt.Color;
005: import tide.editor.MainEditorFrame;
006: import snow.utils.storage.StorageVector;
007:
008: public final class Lint4JLineMessage extends LineMessage {
009: String mess;
010: int priority;
011: String category = "Lint4J";
012:
013: private Lint4JLineMessage(String javaName, String mess, int line,
014: int priority, long created) {
015: super (javaName, line, created);
016: this .mess = mess;
017: this .priority = priority;
018:
019: if (mess.indexOf("shadows") > 0) {
020: category = "Shadowing";
021: } else if (mess.indexOf("strongly recommended") > 0) {
022: category = "Strong recommendation";
023: } else if (mess.indexOf("should") > 0
024: || mess.indexOf("could be") > 0) {
025: category = "Recommendation";
026: } else if (mess.indexOf("Possible debug call") >= 0) {
027: category = "Possible debug call";
028: } else if (mess.indexOf("instead") > 0) {
029: category = "Bad practice";
030: } else if (mess.indexOf("unexpected behavior") > 0) {
031: category = "Unexpected behavior";
032: } else if (mess.indexOf("slows down") > 0
033: || mess.indexOf("significantly better") > 0) {
034: category = "Performance";
035: } else if (mess.indexOf("possible scoping problem") > 0) {
036: category = "Possible scoping problem";
037: }
038:
039: }
040:
041: public static boolean createAndAdd(final String line,
042: boolean ignoreIrrelevant) {
043:
044: int pos = line.indexOf(".java:");
045: if (pos == -1)
046: return false;
047: String javaName = line.substring(0, pos);
048: String pa = MainEditorFrame.instance.getActualProject()
049: .getSources_Home().getAbsolutePath();
050: if (!pa.endsWith("\\"))
051: pa += "\\";
052:
053: // TODO: startswithIgnoreCase !!!!
054: if (javaName.startsWith(pa)) {
055: javaName = javaName.substring(pa.length());
056: }
057:
058: javaName = javaName.replace('\\', '.');
059:
060: int posEnd = line.indexOf(':', pos + 6);
061: int lineNr = -1;
062: if (posEnd > 0) {
063: try {
064: lineNr = Integer.parseInt(line.substring(pos + 6,
065: posEnd));
066: } catch (Exception e) {
067: e.printStackTrace();
068: }
069: }
070:
071: String messLine = line.substring(posEnd + 1).trim();
072: int priority = 1;
073: try {
074: priority = Integer.parseInt(messLine.substring(1, 2));
075: messLine = messLine.substring(5);
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079:
080: Lint4JLineMessage lm = new Lint4JLineMessage(javaName,
081: messLine, lineNr, priority, System.currentTimeMillis());
082:
083: if (ignoreIrrelevant
084: && LineMessagesManager.getInstance()
085: .getIrrelevantCategories().contains(
086: lm.getCategory())) {
087: return false;
088: }
089:
090: LineMessagesManager.getInstance().add(lm);
091: return true;
092: }
093:
094: @Override
095: public String toStringHTML() {
096: return "Lint4J: " + mess;
097: }
098:
099: @Override
100: public String getMessage() {
101: return mess;
102: }
103:
104: @Override
105: public Color getColor() {
106: return Color.magenta;
107: }
108:
109: @Override
110: public String getLetter() {
111: return null;
112: } // point
113:
114: @Override
115: public int getShiftX() {
116: return 2;
117: }
118:
119: @Override
120: public String getMessageOriginator() {
121: return "Lint4J";
122: }
123:
124: @Override
125: public int getPriority() {
126: return priority;
127: }
128:
129: @Override
130: public String getCategory() {
131: return category;
132: } // manually parsed and guessed
133:
134: @Override
135: public StorageVector getStorageRepresentation() {
136: StorageVector sv = new StorageVector();
137: sv.add(1);
138: sv.add("Lint4JLineMessage");
139: sv.add(javaName);
140: sv.add(mess);
141: sv.add(line);
142: sv.add(priority);
143: sv.add(created);
144: return sv;
145: }
146:
147: public static Lint4JLineMessage createFromStorageVector(
148: StorageVector sv) {
149: long created = sv.size() > 6 ? (Long) sv.get(6) : System
150: .currentTimeMillis();
151: return new Lint4JLineMessage((String) sv.get(2), (String) sv
152: .get(3), (Integer) sv.get(4), (Integer) sv.get(5),
153: created);
154: }
155: }
|