Search in sources :

Example 1 with AbstractDocument

use of org.eclipse.jface.text.AbstractDocument in project eclipse.platform.text by eclipse.

the class AnnotationModel method getRegionAnnotationIterator.

/**
 * Returns an iterator as specified in {@link IAnnotationModelExtension2#getAnnotationIterator(int, int, boolean, boolean)}
 *
 * @param offset region start
 * @param length region length
 * @param canStartBefore position can start before region
 * @param canEndAfter position can end after region
 * @return an iterator to iterate over annotations in region
 * @see IAnnotationModelExtension2#getAnnotationIterator(int, int, boolean, boolean)
 * @since 3.4
 */
private Iterator<Annotation> getRegionAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) {
    if (!(fDocument instanceof AbstractDocument))
        return new RegionIterator(getAnnotationIterator(true), this, offset, length, canStartBefore, canEndAfter);
    AbstractDocument document = (AbstractDocument) fDocument;
    cleanup(true);
    try {
        Position[] positions = document.getPositions(IDocument.DEFAULT_CATEGORY, offset, length, canStartBefore, canEndAfter);
        return new AnnotationsInterator(positions, fPositions);
    } catch (BadPositionCategoryException e) {
        // can happen if e.g. the document doesn't contain such a category, or when removed in a different thread
        return Collections.<Annotation>emptyList().iterator();
    }
}
Also used : AbstractDocument(org.eclipse.jface.text.AbstractDocument) Position(org.eclipse.jface.text.Position) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException)

Aggregations

AbstractDocument (org.eclipse.jface.text.AbstractDocument)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1 Position (org.eclipse.jface.text.Position)1