final IErlElement de = delta.getElement();
if (de instanceof IErlModule && de != fModule) {
return;
}
final ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor
.getAdapter(ProjectionAnnotationModel.class);
if (model == null) {
return;
}
final IDocumentProvider provider = fEditor.getDocumentProvider();
try {
fCachedModel = model;
fCachedDocument = provider.getDocument(fEditor.getEditorInput());
if (fCachedDocument.getNumberOfLines() > PerformanceTuning.get()
.getFoldingLimit()) {
// disable folding for files larger than this
model.removeAllAnnotations();
return;
}
final Map<ErlangProjectionAnnotation, Position> additions = new HashMap<ErlangProjectionAnnotation, Position>();
final List<ErlangProjectionAnnotation> deletions = new ArrayList<ErlangProjectionAnnotation>();
final List<ErlangProjectionAnnotation> updates = new ArrayList<ErlangProjectionAnnotation>();
// use a linked map to maintain ordering of comments
final Map<ErlangProjectionAnnotation, Position> updated = new LinkedHashMap<ErlangProjectionAnnotation, Position>();
computeAdditions(fModule, updated);
final Map<Object, List<Tuple>> previous = createAnnotationMap(model);
for (final Entry<ErlangProjectionAnnotation, Position> entry : updated
.entrySet()) {
final ErlangProjectionAnnotation newAnnotation = entry.getKey();
final IErlElement element = newAnnotation.getElement();
final Position newPosition = entry.getValue();
final List<Tuple> annotations = previous.get(element);
if (annotations == null) {
additions.put(newAnnotation, newPosition);
} else {
final Iterator<Tuple> x = annotations.iterator();
boolean matched = false;
while (x.hasNext()) {
final Tuple tuple = x.next();
final ErlangProjectionAnnotation existingAnnotation = tuple.annotation;
final Position existingPosition = tuple.position;
if (newAnnotation.isComment() == existingAnnotation.isComment()) {
if (existingPosition != null
&& !newPosition.equals(existingPosition)) {
existingPosition.setOffset(newPosition.getOffset());
existingPosition.setLength(newPosition.getLength());
updates.add(existingAnnotation);
}
matched = true;
x.remove();
break;
}
}
if (!matched) {
additions.put(newAnnotation, newPosition);
}
if (annotations.isEmpty()) {
previous.remove(element);
}
}
}
for (final List<Tuple> l : previous.values()) {
for (final Tuple t : l) {
deletions.add(t.annotation);
}
}
match(deletions, additions, updates);
final Annotation[] removals = new Annotation[deletions.size()];
deletions.toArray(removals);
final Annotation[] changes = new Annotation[updates.size()];
updates.toArray(changes);
model.modifyAnnotations(removals, additions, changes);
fFirstTimeInitialCollapse = false;
} finally {
fCachedDocument = null;
fCachedModel = null;