if (!(viewer instanceof ISourceViewer)) {
return;
}
IAnnotationModel model = ((ISourceViewer) viewer).getAnnotationModel();
for (Iterator<Annotation> it = model.getAnnotationIterator(); it
.hasNext();) {
Annotation annotation = it.next();
if (annotation instanceof ViewportAnnotation) {
if (((ViewportAnnotation) annotation).getSource()
.equals(source))
model.removeAnnotation(annotation);
}
}
IDocument document = viewer.getDocument();
try {
int lines = document.getNumberOfLines();
top = Math.max(0, Math.min(lines - 1, top));
bottom = Math.max(0, Math.min(lines - 1, bottom));
int start = document.getLineOffset(top);
if (start == -1)
throw new BadLocationException("Start line -1");
int end = document.getLineOffset(bottom);
if (end == -1 || end < start)
throw new BadLocationException("End line -1 or less than start");
SarosAnnotation annotation = new ViewportAnnotation(source);
Position position = new Position(start, end - start);
model.addAnnotation(annotation, position);
} catch (BadLocationException e) {
log.warn("Internal Error:", e);
}
}