Search in sources :

Example 11 with Annotation

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);
                }
            }
        }
    }
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 12 with Annotation

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);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) ArrayList(java.util.ArrayList) Document(org.eclipse.che.ide.api.editor.document.Document) QueryAnnotationsEvent(org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Map(java.util.Map)

Example 13 with Annotation

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;
    }
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) Position(org.eclipse.che.ide.api.editor.text.Position) ArrayList(java.util.ArrayList) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Aggregations

Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)13 Position (org.eclipse.che.ide.api.editor.text.Position)8 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)5 ArrayList (java.util.ArrayList)4 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)4 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)4 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 NoSuchElementException (java.util.NoSuchElementException)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1 QueryAnnotationsEvent (org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent)1 Document (org.eclipse.che.ide.api.editor.document.Document)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 OrionProblemOverlay (org.eclipse.che.ide.editor.orion.client.jso.OrionProblemOverlay)1 Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)1