use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class AnnotationModelStressTest method assertAdd.
private void assertAdd(AnnotationData data, ArrayList<AnnotationData> added) {
Annotation annotation = new Annotation(false);
Position position = new Position(data.offset, data.length);
IAnnotationModel model = getModel(data.annotationNumber);
model.addAnnotation(annotation, position);
assertTrue(model.getPosition(annotation) == position);
data.annotation = annotation;
data.position = position;
added.add(data);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class AnnotationModelStressTest method assertRemove.
private void assertRemove(ArrayList<AnnotationData> added) {
AnnotationData first = added.remove(0);
IAnnotationModel model = getModel(first.annotationNumber);
assertTrue(model.getPosition(first.annotation) == first.position);
model.removeAnnotation(first.annotation);
assertTrue(model.getPosition(first.annotation) == null);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class AnnotationModelStressTest method assertExistNew.
private void assertExistNew(ArrayList<AnnotationData> added) {
for (int i = 0, size = added.size(); i < size; i++) {
AnnotationData data = added.get(i);
IAnnotationModel model = getModel(data.annotationNumber);
assertTrue(model.getPosition(data.annotation) == data.position);
}
ArrayList<Annotation> annotations = getAllAnnotationsNew();
assertEquals(added.size(), annotations.size());
for (int i = 0, size = annotations.size(); i < size; i++) {
Annotation annotation = annotations.get(i);
AnnotationData data = getAnnotationData(added, annotation);
assertNotNull(data);
assertTrue(fAnnotationModel.getPosition(annotation) == data.position);
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method findAnnotation.
/**
* Returns the annotation closest to the given range respecting the given
* direction. If an annotation is found, the annotations current position
* is copied into the provided annotation position.
*
* @param offset the region offset
* @param length the region length
* @param forward <code>true</code> for forwards, <code>false</code> for backward
* @param annotationPosition the position of the found annotation
* @return the found annotation
* @since 3.2
*/
protected Annotation findAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {
Annotation nextAnnotation = null;
Position nextAnnotationPosition = null;
Annotation containingAnnotation = null;
Position containingAnnotationPosition = null;
boolean currentAnnotation = false;
IDocument document = getDocumentProvider().getDocument(getEditorInput());
int endOfDocument = 0;
if (document != null) {
endOfDocument = document.getLength();
}
int distance = Integer.MAX_VALUE;
IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
Iterator<Annotation> e = model.getAnnotationIterator();
while (e.hasNext()) {
Annotation a = e.next();
if (!isNavigationTarget(a))
continue;
Position p = model.getPosition(a);
if (p == null)
continue;
if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {
// || p.includes(offset)) {
if (containingAnnotation == null || (forward && p.length >= containingAnnotationPosition.length || !forward && p.length >= containingAnnotationPosition.length)) {
containingAnnotation = a;
containingAnnotationPosition = p;
currentAnnotation = p.length == length;
}
} else {
int currentDistance = 0;
if (forward) {
currentDistance = p.getOffset() - offset;
if (currentDistance < 0)
currentDistance = endOfDocument + currentDistance;
if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
distance = currentDistance;
nextAnnotation = a;
nextAnnotationPosition = p;
}
} else {
currentDistance = offset + length - (p.getOffset() + p.length);
if (currentDistance < 0)
currentDistance = endOfDocument + currentDistance;
if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
distance = currentDistance;
nextAnnotation = a;
nextAnnotationPosition = p;
}
}
}
}
if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) {
annotationPosition.setOffset(containingAnnotationPosition.getOffset());
annotationPosition.setLength(containingAnnotationPosition.getLength());
return containingAnnotation;
}
if (nextAnnotationPosition != null) {
annotationPosition.setOffset(nextAnnotationPosition.getOffset());
annotationPosition.setLength(nextAnnotationPosition.getLength());
}
return nextAnnotation;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method gotoMarker.
/**
* If the editor can be saved all marker ranges have been changed according to
* the text manipulations. However, those changes are not yet propagated to the
* marker manager. Thus, when opening a marker, the marker's position in the editor
* must be determined as it might differ from the position stated in the marker.
*
* @param marker the marker to go to
* @deprecated visibility will be reduced, use <code>getAdapter(IGotoMarker.class) for accessing this method</code>
*/
@Deprecated
public void gotoMarker(IMarker marker) {
if (fIsUpdatingMarkerViews)
return;
if (getSourceViewer() == null)
return;
int start = MarkerUtilities.getCharStart(marker);
int end = MarkerUtilities.getCharEnd(marker);
boolean selectLine = start < 0 || end < 0;
// look up the current range of the marker when the document has been edited
IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
if (model instanceof AbstractMarkerAnnotationModel) {
AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
Position pos = markerModel.getMarkerPosition(marker);
if (pos != null && !pos.isDeleted()) {
// use position instead of marker values
start = pos.getOffset();
end = pos.getOffset() + pos.getLength();
}
if (pos != null && pos.isDeleted()) {
// do nothing if position has been deleted
return;
}
}
IDocument document = getDocumentProvider().getDocument(getEditorInput());
if (selectLine) {
int line;
try {
if (start >= 0)
line = document.getLineOfOffset(start);
else {
line = MarkerUtilities.getLineNumber(marker);
// Marker line numbers are 1-based
--line;
start = document.getLineOffset(line);
}
end = start + document.getLineLength(line) - 1;
} catch (BadLocationException e) {
return;
}
}
int length = document.getLength();
if (end <= length && start <= length) {
fIsComingFromGotoMarker = true;
selectAndReveal(start, end - start);
}
}
Aggregations