/** * 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(); } }
/** * 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(); } }
@Override public Annotation next() { Annotation result= fNext; fNext= findNext(); return result; }
/** * @param positions positions to iterate over * @param map a map to map positions to annotations */ public AnnotationsInterator(Position[] positions, Map<Position, Annotation> map) { fPositions= positions; fIndex= 0; fMap= map; fNext= findNext(); }
/** * @param positions positions to iterate over * @param map a map to map positions to annotations */ public AnnotationsInterator(Position[] positions, Map<Position, Annotation> map) { fPositions= positions; fIndex= 0; fMap= map; fNext= findNext(); }
@Override public Annotation next() { Annotation result= fNext; fNext= findNext(); return result; }