Search in sources :

Example 6 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DocumentPositionMapImpl method computeIndexInPositionList.

protected int computeIndexInPositionList(final List<TypedPosition> positions, final int offset, final boolean orderedByOffset) {
    if (positions.size() == 0) {
        return 0;
    }
    int left = 0;
    int right = positions.size() - 1;
    int mid = 0;
    Position p = null;
    while (left < right) {
        mid = (left + right) / 2;
        p = positions.get(mid);
        final int pOffset = getOffset(orderedByOffset, p);
        if (offset < pOffset) {
            if (left == mid) {
                right = left;
            } else {
                right = mid - 1;
            }
        } else if (offset > pOffset) {
            if (right == mid) {
                left = right;
            } else {
                left = mid + 1;
            }
        } else if (offset == pOffset) {
            left = right = mid;
        }
    }
    int pos = left;
    p = positions.get(pos);
    int pPosition = getOffset(orderedByOffset, p);
    if (offset > pPosition) {
        // append to the end
        pos++;
    } else {
        // entry will become the first of all entries with the same offset
        do {
            --pos;
            if (pos < 0) {
                break;
            }
            p = positions.get(pos);
            pPosition = getOffset(orderedByOffset, p);
        } while (offset == pPosition);
        ++pos;
    }
    Assert.isTrue(0 <= pos && pos <= positions.size());
    return pos;
}
Also used : TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) Position(org.eclipse.che.ide.api.editor.text.Position)

Example 7 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DocumentPositionMapImpl method getPositions.

@Override
public List<TypedPosition> getPositions(String category, int offset, int length, boolean canStartBefore, boolean canEndAfter) throws BadPositionCategoryException {
    if (canStartBefore && canEndAfter || (!canStartBefore && !canEndAfter)) {
        List<TypedPosition> documentPositions;
        if (canStartBefore && canEndAfter) {
            if (offset < this.contentLength / 2) {
                documentPositions = getStartingPositions(category, 0, offset + length);
            } else {
                documentPositions = getEndingPositions(category, offset, this.contentLength - offset + 1);
            }
        } else {
            documentPositions = getStartingPositions(category, offset, length);
        }
        final List<TypedPosition> list = new ArrayList<TypedPosition>(documentPositions.size());
        final Position region = new Position(offset, length);
        for (final TypedPosition position : documentPositions) {
            if (isWithinRegion(region, position, canStartBefore, canEndAfter)) {
                list.add(position);
            }
        }
        return list;
    } else if (canStartBefore) {
        final List<TypedPosition> list = getEndingPositions(category, offset, length);
        return list;
    } else {
        Assert.isLegal(canEndAfter && !canStartBefore);
        final List<TypedPosition> list = getStartingPositions(category, offset, length);
        return list;
    }
}
Also used : TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class RegionIterator method findNext.

private Annotation findNext() {
    while (parentIterator.hasNext()) {
        final Annotation next = parentIterator.next();
        final Position position = model.getPosition(next);
        if (position != null) {
            final int offset = position.getOffset();
            if (isWithinRegion(offset, position.getLength())) {
                return next;
            }
        }
    }
    return null;
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 9 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DefaultPartitioner method getFirstIndexStartingAfterOffset.

/**
     * Returns the index of the first position which starts at or after the given offset.
     *
     * @param positions the positions in linear order
     * @param offset the offset
     * @return the index of the first position which starts after the offset
     */
private static int getFirstIndexStartingAfterOffset(List<TypedPosition> positions, int offset) {
    int i = -1;
    int j = positions.size();
    while (j - i > 1) {
        final int k = (i + j) >> 1;
        final Position p = positions.get(k);
        if (p.getOffset() >= offset) {
            j = k;
        } else {
            i = k;
        }
    }
    return j;
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition)

Example 10 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class JavaAnnotationModel method reportProblems.

private void reportProblems(final List<Problem> problems) {
    boolean temporaryProblemsChanged = false;
    if (!generatedAnnotations.isEmpty()) {
        temporaryProblemsChanged = true;
        super.clear();
        generatedAnnotations.clear();
    }
    if (reportedProblems != null && !reportedProblems.isEmpty()) {
        for (final Problem problem : reportedProblems) {
            final Position position = createPositionFromProblem(problem);
            if (position != null) {
                final ProblemAnnotation annotation = new ProblemAnnotation(problem);
                addAnnotation(annotation, position, false);
                generatedAnnotations.add(annotation);
                temporaryProblemsChanged = true;
            }
        }
    }
    if (temporaryProblemsChanged) {
        fireModelChanged();
    }
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem)

Aggregations

Position (org.eclipse.che.ide.api.editor.text.Position)36 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)14 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)14 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)8 BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)7 ArrayList (java.util.ArrayList)6 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)3 Element (elemental.dom.Element)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 DiagnosticDTO (org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 EditorWithAutoSave (org.eclipse.che.ide.api.editor.EditorWithAutoSave)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1