use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.
the class MinimapAnnotationRenderer method removeAnnotationItem.
private void removeAnnotationItem(final AnnotationModelEvent event, final Annotation annotation, final Map<Integer, List<Annotation>> toRestore) {
final Position position = event.getPositionOfRemovedAnnotation(annotation);
final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
final int line = textPosition.getLine();
// remove all marks on the line
this.minimap.removeMarks(line, line);
// restore marks that are not removed
final LinearRange rangeForLine = this.document.getLinearRangeForLine(line);
final AnnotationModel model = event.getAnnotationModel();
final Iterator<Annotation> it = model.getAnnotationIterator(rangeForLine.getStartOffset(), rangeForLine.getLength(), false, true);
while (it.hasNext()) {
final Annotation current = it.next();
List<Annotation> lineAnnotations = toRestore.get(line);
if (!current.equals(annotation)) {
if (lineAnnotations == null) {
lineAnnotations = new ArrayList<>();
toRestore.put(line, lineAnnotations);
}
lineAnnotations.add(current);
} else {
if (lineAnnotations != null) {
lineAnnotations.removeAll(Collections.singletonList(current));
if (lineAnnotations.isEmpty()) {
toRestore.remove(line);
}
}
}
}
}
use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.
the class JavaQuickAssistProcessor method computeQuickAssistProposals.
@Override
public void computeQuickAssistProposals(final QuickAssistInvocationContext quickAssistContext, final CodeAssistCallback callback) {
final TextEditor textEditor = quickAssistContext.getTextEditor();
final Document document = textEditor.getDocument();
LinearRange tempRange;
tempRange = textEditor.getSelectedLinearRange();
final LinearRange range = tempRange;
final boolean goToClosest = (range.getLength() == 0);
final QueryAnnotationsEvent.AnnotationFilter filter = new QueryAnnotationsEvent.AnnotationFilter() {
@Override
public boolean accept(final Annotation annotation) {
if (!(annotation instanceof JavaAnnotation)) {
return false;
} else {
JavaAnnotation javaAnnotation = (JavaAnnotation) annotation;
return (!javaAnnotation.isMarkedDeleted());
}
}
};
final QueryAnnotationsEvent.QueryCallback queryCallback = new QueryAnnotationsEvent.QueryCallback() {
@Override
public void respond(final Map<Annotation, Position> annotations) {
List<Problem> problems = new ArrayList<>();
/*final Map<Annotation, Position> problems =*/
int offset = collectQuickFixableAnnotations(range, document, annotations, goToClosest, problems);
if (offset != range.getStartOffset()) {
TextEditor presenter = ((TextEditor) textEditor);
presenter.getCursorModel().setCursorPosition(offset);
}
setupProposals(callback, textEditor, offset, problems);
}
};
final QueryAnnotationsEvent event = new QueryAnnotationsEvent.Builder().withFilter(filter).withCallback(queryCallback).build();
document.getDocumentHandle().getDocEventBus().fireEvent(event);
}
use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.
the class JavaQuickAssistProcessor method collectQuickFixableAnnotations.
private int collectQuickFixableAnnotations(final LinearRange lineRange, Document document, final Map<Annotation, Position> annotations, final boolean goToClosest, List<Problem> resultingProblems) {
int invocationLocation = lineRange.getStartOffset();
if (goToClosest) {
LinearRange line = document.getLinearRangeForLine(document.getPositionFromIndex(lineRange.getStartOffset()).getLine());
int rangeStart = line.getStartOffset();
int rangeEnd = rangeStart + line.getLength();
ArrayList<Position> allPositions = new ArrayList<>();
List<JavaAnnotation> allAnnotations = new ArrayList<>();
int bestOffset = Integer.MAX_VALUE;
for (Annotation problem : annotations.keySet()) {
if (problem instanceof JavaAnnotation) {
JavaAnnotation ann = ((JavaAnnotation) problem);
Position pos = annotations.get(problem);
if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) {
// inside our range?
allAnnotations.add(ann);
allPositions.add(pos);
bestOffset = processAnnotation(problem, pos, invocationLocation, bestOffset);
}
}
}
if (bestOffset == Integer.MAX_VALUE) {
return invocationLocation;
}
for (int i = 0; i < allPositions.size(); i++) {
Position pos = allPositions.get(i);
if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) {
resultingProblems.add(createProblem(allAnnotations.get(i), pos));
}
}
return bestOffset;
} else {
for (Annotation problem : annotations.keySet()) {
Position pos = annotations.get(problem);
if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) {
resultingProblems.add(createProblem((JavaAnnotation) problem, pos));
}
}
return invocationLocation;
}
}
Aggregations