forked from ariatemplates/editor-frontend-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOCDocument.java
More file actions
92 lines (73 loc) · 2.55 KB
/
POCDocument.java
File metadata and controls
92 lines (73 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package poc.document;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
public class POCDocument extends Document {
private Map<String, Object> GUID = null;
private IFile file = null;
public Map<String, Object> getGUID() {
return this.GUID;
}
public void setGUID(Map<String, Object> GUID) {
this.GUID = GUID;
}
public IFile getFile() {
return file;
}
public void setFile(IFile file) {
this.file = file;
}
@SuppressWarnings("unchecked")
public void addMarkerAnnotation(Map<String, ?> config, int severity) {
try {
IMarker marker = file.createMarker("com.ariatemplates.tools.ide.error");
marker.setAttribute(IMarker.SEVERITY, severity);
Map<String, ?> location = ((Map<String, ?>) config.get("location"));
int charStart = ((Double) ((Map<String, ?>) location.get("start")).get("index")).intValue();
int charEnd = ((Double) ((Map<String, ?>) location.get("end")).get("index")).intValue();
marker.setAttribute(IMarker.CHAR_START, charStart);
marker.setAttribute(IMarker.CHAR_END, charEnd);
marker.setAttribute(IMarker.LINE_NUMBER, this.getLineOfOffset(charStart));
String message = this.formatMessages((ArrayList<String>) config.get("messages"));
marker.setAttribute(IMarker.MESSAGE, message);
} catch (CoreException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
}
public void clearMarkerAnnotations() {
try {
file.deleteMarkers("com.ariatemplates.tools.ide.error", true, 1);
} catch (CoreException e) {
e.printStackTrace();
}
}
public String formatMessages(ArrayList<String> messages) {
Object[] messagesArray = (Object[]) messages.toArray();
StringBuilder out = new StringBuilder();
for (int k = 0; k < messagesArray.length; k++) {
if (k > 0) {
out.append("\n");
}
out.append("- ").append(messagesArray[k]);
}
return out.toString();
}
@SuppressWarnings("unchecked")
public void addAllMarkerAnnotations(Map<String, Object> messages) {
List<Map<String, ?>> errors = (List<Map<String, ?>>) messages.get("errors");
for (Map<String, ?> err : errors) {
this.addMarkerAnnotation(err, IMarker.SEVERITY_ERROR);
}
List<Map<String, ?>> warnings = (List<Map<String, ?>>) messages.get("warnings");
for (Map<String, ?> warns : warnings) {
this.addMarkerAnnotation(warns, IMarker.SEVERITY_WARNING);
}
}
}