@SuppressWarnings("unchecked") protected Annotation[] mergeFoldingRegions(Collection<FoldedPosition> foldedPositions, ProjectionAnnotationModel projectionAnnotationModel) { List<Annotation> deletions = new ArrayList<Annotation>(); for (Iterator<Annotation> iterator = projectionAnnotationModel.getAnnotationIterator(); iterator.hasNext();) { Annotation annotation = iterator.next(); if (annotation instanceof ProjectionAnnotation) { Position position = projectionAnnotationModel.getPosition(annotation); if (!foldedPositions.remove(position)) { deletions.add(annotation); } } } return deletions.toArray(new Annotation[deletions.size()]); }
private Annotation[] computeDifferences(ProjectionAnnotationModel model, Set<?> additions) { List<Object> deletions = new ArrayList<>(); for (Iterator<?> iter = model.getAnnotationIterator(); iter.hasNext();) { Object annotation = iter.next(); if (annotation instanceof ProjectionAnnotation) { Position position = model.getPosition((Annotation) annotation); if (additions.contains(position)) { additions.remove(position); } else { deletions.add(annotation); } } } return deletions.toArray(new Annotation[deletions.size()]); }
private Annotation[] computeDifferences(ProjectionAnnotationModel model, Set<Position> additions) { List<Annotation> deletions = new ArrayList<>(); for (Iterator<Annotation> iter = model.getAnnotationIterator(); iter.hasNext();) { Object annotation = iter.next(); if (annotation instanceof ProjectionAnnotation) { Annotation annot = (Annotation) annotation; Position position = model.getPosition(annot); if (additions.contains(position)) { additions.remove(position); } else { deletions.add(annot); } } } return deletions.toArray(new Annotation[deletions.size()]); }
private void computeDifferences( ProjectionAnnotationModel model, Map positionToAnnotationMap, List annotationsToDeleteList, Map annotationsToAddMap ) { for ( Iterator iter = model.getAnnotationIterator(); iter.hasNext(); ) { Object annotation = iter.next(); if ( annotation instanceof ProjectionAnnotation ) { Position position = model.getPosition( ( Annotation ) annotation ); if ( positionToAnnotationMap.containsKey( position ) ) positionToAnnotationMap.remove( position ); else annotationsToDeleteList.add( annotation ); } } for ( Iterator iter = positionToAnnotationMap.keySet().iterator(); iter.hasNext(); ) { Position position = ( Position ) iter.next(); ProjectionAnnotation annotation = ( ProjectionAnnotation ) positionToAnnotationMap.get( position ); annotationsToAddMap.put( annotation, position ); } }
private ProjectionAnnotation[] computeCollapsedNestedAnnotations(int offset, int length) { List<ProjectionAnnotation> annotations= new ArrayList<>(5); Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(offset, length, false, false); while (e.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); if (position == null) { // annotation might already be deleted, we will be informed later on about this deletion continue; } annotations.add(annotation); } } if (annotations.size() > 0) { ProjectionAnnotation[] result= new ProjectionAnnotation[annotations.size()]; annotations.toArray(result); return result; } return null; }
private ProjectionAnnotation[] computeCollapsedNestedAnnotations(int offset, int length) { List<ProjectionAnnotation> annotations= new ArrayList<>(5); Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(offset, length, false, false); while (e.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); if (position == null) { // annotation might already be deleted, we will be informed later on about this deletion continue; } annotations.add(annotation); } } if (annotations.size() > 0) { ProjectionAnnotation[] result= new ProjectionAnnotation[annotations.size()]; annotations.toArray(result); return result; } return null; }
private Map<IJavaElement, List<Tuple>> computeCurrentStructure(FoldingStructureComputationContext ctx) { Map<IJavaElement, List<Tuple>> map= new HashMap<>(); ProjectionAnnotationModel model= ctx.getModel(); Iterator<Annotation> e= model.getAnnotationIterator(); while (e.hasNext()) { Object annotation= e.next(); if (annotation instanceof JavaProjectionAnnotation) { JavaProjectionAnnotation java= (JavaProjectionAnnotation) annotation; Position position= model.getPosition(java); Assert.isNotNull(position); List<Tuple> list= map.get(java.getElement()); if (list == null) { list= new ArrayList<>(2); map.put(java.getElement(), list); } list.add(new Tuple(java, position)); } } Comparator<Tuple> comparator= new Comparator<Tuple>() { @Override public int compare(Tuple o1, Tuple o2) { return o1.position.getOffset() - o2.position.getOffset(); } }; for (Iterator<List<Tuple>> it= map.values().iterator(); it.hasNext();) { List<Tuple> list= it.next(); Collections.sort(list, comparator); } return map; }
/** * Returns the positions of all annotations that intersect with * <code>modelSelection</code> and that are at least partly visible. * @param modelSelection a model range * @return the positions of all annotations that intersect with * <code>modelSelection</code> * @since 3.1 */ private Position[] computeOverlappingAnnotationPositions(IRegion modelSelection) { List<Position> positions= new ArrayList<>(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); Position position= fProjectionAnnotationModel.getPosition(annotation); if (position != null && position.overlapsWith(modelSelection.getOffset(), modelSelection.getLength()) && modelRange2WidgetRange(position) != null) positions.add(position); } return positions.toArray(new Position[positions.size()]); }
/** * Returns the positions of all annotations that intersect with * <code>modelSelection</code> and that are at least partly visible. * @param modelSelection a model range * @return the positions of all annotations that intersect with * <code>modelSelection</code> * @since 3.1 */ private Position[] computeOverlappingAnnotationPositions(IRegion modelSelection) { List<Position> positions= new ArrayList<>(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); Position position= fProjectionAnnotationModel.getPosition(annotation); if (position != null && position.overlapsWith(modelSelection.getOffset(), modelSelection.getLength()) && modelRange2WidgetRange(position) != null) positions.add(position); } return positions.toArray(new Position[positions.size()]); }
@Override public void setRangeIndication(int offset, int length, boolean moveCursor) { IRegion rangeIndication= getRangeIndication(); if (moveCursor && fProjectionAnnotationModel != null && (rangeIndication == null || offset != rangeIndication.getOffset() || length != rangeIndication.getLength())) { List<ProjectionAnnotation> expand= new ArrayList<>(2); // expand the immediate affected collapsed regions Iterator<Annotation> iterator= fProjectionAnnotationModel.getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation)iterator.next(); if (annotation.isCollapsed() && willAutoExpand(fProjectionAnnotationModel.getPosition(annotation), offset, length)) expand.add(annotation); } if (!expand.isEmpty()) { Iterator<ProjectionAnnotation> e= expand.iterator(); while (e.hasNext()) fProjectionAnnotationModel.expand(e.next()); } } super.setRangeIndication(offset, length, moveCursor); }
@Override public void setRangeIndication(int offset, int length, boolean moveCursor) { IRegion rangeIndication= getRangeIndication(); if (moveCursor && fProjectionAnnotationModel != null && (rangeIndication == null || offset != rangeIndication.getOffset() || length != rangeIndication.getLength())) { List<ProjectionAnnotation> expand= new ArrayList<>(2); // expand the immediate affected collapsed regions Iterator<Annotation> iterator= fProjectionAnnotationModel.getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation)iterator.next(); if (annotation.isCollapsed() && willAutoExpand(fProjectionAnnotationModel.getPosition(annotation), offset, length)) expand.add(annotation); } if (!expand.isEmpty()) { Iterator<ProjectionAnnotation> e= expand.iterator(); while (e.hasNext()) fProjectionAnnotationModel.expand(e.next()); } } super.setRangeIndication(offset, length, moveCursor); }
/** * Collapses all annotations that overlap with the given range and are collapsed. * * @param offset the range offset * @param length the range length * @return <code>true</code> if any annotation has been collapse, <code>false</code> * otherwise * @since 3.2 */ public boolean collapseAll(int offset, int length) { boolean collapsing= false; Iterator<Annotation> iterator= getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); if (!annotation.isCollapsed()) { Position position= getPosition(annotation); if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) { annotation.markCollapsed(); modifyAnnotation(annotation, false); collapsing= true; } } } if (collapsing) fireModelChanged(); return collapsing; }
/** * Collapses all annotations that overlap with the given range and are collapsed. * * @param offset the range offset * @param length the range length * @return <code>true</code> if any annotation has been collapse, <code>false</code> * otherwise * @since 3.2 */ public boolean collapseAll(int offset, int length) { boolean collapsing= false; Iterator<Annotation> iterator= getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); if (!annotation.isCollapsed()) { Position position= getPosition(annotation); if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) { annotation.markCollapsed(); modifyAnnotation(annotation, false); collapsing= true; } } } if (collapsing) fireModelChanged(); return collapsing; }
/** * Expands all annotations that overlap with the given range and are collapsed. Fires a model change event if * requested. * * @param offset the offset of the range * @param length the length of the range * @param fireModelChanged <code>true</code> if a model change event * should be fired, <code>false</code> otherwise * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise */ protected boolean expandAll(int offset, int length, boolean fireModelChanged) { boolean expanding= false; Iterator<Annotation> iterator= getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); if (annotation.isCollapsed()) { Position position= getPosition(annotation); if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) { annotation.markExpanded(); modifyAnnotation(annotation, false); expanding= true; } } } if (expanding && fireModelChanged) fireModelChanged(); return expanding; }
private void expand() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || position.includes(found.offset) && position.includes(found.offset + found.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.expand(bestMatch); revealRange(selection.x, selection.y); } } }
private void collapse() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (!annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.collapse(bestMatch); revealRange(selection.x, selection.y); } } }
private void collapse() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (!annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.collapse(bestMatch); revealRange(selection.x, selection.y); } } }
private void expand() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || position.includes(found.offset) && position.includes(found.offset + found.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.expand(bestMatch); revealRange(selection.x, selection.y); } } }
private void processChanges(Annotation[] annotations, boolean fireRedraw, List<Position> coverage) throws BadLocationException { for (int i= 0; i < annotations.length; i++) { ProjectionAnnotation annotation= (ProjectionAnnotation) annotations[i]; Position position= fProjectionAnnotationModel.getPosition(annotation); if (position == null) continue; if (!covers(coverage, position)) { if (annotation.isCollapsed()) { coverage.add(position); IRegion[] regions= computeCollapsedRegions(position); if (regions != null) for (int j= 0; j < regions.length; j++) collapse(regions[j].getOffset(), regions[j].getLength(), fireRedraw); } else { expand(position.getOffset(), position.getLength(), fireRedraw); } } } }
private void processChanges(Annotation[] annotations, boolean fireRedraw, List<Position> coverage) throws BadLocationException { for (int i= 0; i < annotations.length; i++) { ProjectionAnnotation annotation= (ProjectionAnnotation) annotations[i]; Position position= fProjectionAnnotationModel.getPosition(annotation); if (position == null) continue; if (!covers(coverage, position)) { if (annotation.isCollapsed()) { coverage.add(position); IRegion[] regions= computeCollapsedRegions(position); if (regions != null) for (int j= 0; j < regions.length; j++) collapse(regions[j].getOffset(), regions[j].getLength(), fireRedraw); } else { expand(position.getOffset(), position.getLength(), fireRedraw); } } } }