use of org.eclipse.jface.text.ISynchronizable in project mylyn.docs by eclipse.
the class AnnotationMarkupValidator method createProblems.
@SuppressWarnings("unchecked")
@Override
protected void createProblems(IProgressMonitor monitor, IDocument document, IRegion region, List<ValidationProblem> problems) throws CoreException {
Object lockObject;
if (annotationModel instanceof ISynchronizable) {
lockObject = ((ISynchronizable) annotationModel).getLockObject();
} else {
lockObject = annotationModel;
}
synchronized (lockObject) {
List<Annotation> toRemove = null;
Iterator<Annotation> annotationIterator = annotationModel.getAnnotationIterator();
while (annotationIterator.hasNext()) {
Annotation annotation = annotationIterator.next();
if (ValidationProblemAnnotation.isValidationAnnotation(annotation)) {
Position position = annotationModel.getPosition(annotation);
int offset = position.getOffset();
if (overlaps(region, offset, position.getLength()) || offset >= document.getLength()) {
if (toRemove == null) {
toRemove = new ArrayList<>();
}
toRemove.add(annotation);
}
}
}
Map<Annotation, Position> annotationsToAdd = new HashMap<>();
for (ValidationProblem problem : problems) {
annotationsToAdd.put(new ValidationProblemAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
if (toRemove != null && annotationModel instanceof IAnnotationModelExtension) {
Annotation[] annotationsToRemove = toRemove.toArray(new Annotation[toRemove.size()]);
((IAnnotationModelExtension) annotationModel).replaceAnnotations(annotationsToRemove, annotationsToAdd);
} else {
if (toRemove != null) {
for (Annotation annotation : toRemove) {
annotationModel.removeAnnotation(annotation);
}
}
for (Map.Entry<Annotation, Position> entry : annotationsToAdd.entrySet()) {
annotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
}
}
use of org.eclipse.jface.text.ISynchronizable in project eclipse.jdt.ls by eclipse.
the class DocumentAdapter method setContents.
@Override
public void setContents(String contents) {
synchronized (lock) {
if (fDocument == null) {
if (fTextFileBuffer != null) {
fDocument = fTextFileBuffer.getDocument();
} else {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
fDocument = manager.createEmptyDocument(fFile.getFullPath(), LocationKind.IFILE);
}
fDocument.addDocumentListener(this);
((ISynchronizable) fDocument).setLockObject(lock);
}
}
if (!contents.equals(fDocument.get())) {
fDocument.set(contents);
}
}
Aggregations