Search in sources :

Example 31 with Position

use of org.eclipse.che.ide.api.editor.text.Position 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)

Example 32 with Position

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

the class JavaRefactoringRename method activateLinkedModeIntoEditor.

private void activateLinkedModeIntoEditor(final RenameRefactoringSession session, final Document document) {
    mode = linkedEditor.getLinkedMode();
    LinkedModel model = linkedEditor.createLinkedModel();
    LinkedModeModel linkedModeModel = session.getLinkedModeModel();
    List<LinkedModelGroup> groups = new ArrayList<>();
    for (LinkedPositionGroup positionGroup : linkedModeModel.getGroups()) {
        LinkedModelGroup group = linkedEditor.createLinkedGroup();
        LinkedData data = positionGroup.getData();
        if (data != null) {
            LinkedModelData modelData = linkedEditor.createLinkedModelData();
            modelData.setType("link");
            modelData.setValues(data.getValues());
            group.setData(modelData);
        }
        List<Position> positions = new ArrayList<>();
        for (Region region : positionGroup.getPositions()) {
            positions.add(new Position(region.getOffset(), region.getLength()));
        }
        group.setPositions(positions);
        groups.add(group);
    }
    model.setGroups(groups);
    disableAutoSave();
    mode.enterLinkedMode(model);
    mode.addListener(new LinkedMode.LinkedModeListener() {

        @Override
        public void onLinkedModeExited(boolean successful, int start, int end) {
            boolean isSuccessful = false;
            try {
                if (successful) {
                    isSuccessful = true;
                    newName = document.getContentRange(start, end - start);
                    performRename(session);
                }
            } finally {
                mode.removeListener(this);
                isActiveLinkedEditor = false;
                if (!isSuccessful && linkedEditor instanceof EditorWithAutoSave) {
                    ((EditorWithAutoSave) linkedEditor).enableAutoSave();
                }
            }
        }
    });
}
Also used : LinkedModel(org.eclipse.che.ide.api.editor.link.LinkedModel) Position(org.eclipse.che.ide.api.editor.text.Position) HasLinkedMode(org.eclipse.che.ide.api.editor.link.HasLinkedMode) LinkedMode(org.eclipse.che.ide.api.editor.link.LinkedMode) ArrayList(java.util.ArrayList) LinkedModeModel(org.eclipse.che.ide.ext.java.shared.dto.LinkedModeModel) LinkedModelGroup(org.eclipse.che.ide.api.editor.link.LinkedModelGroup) LinkedPositionGroup(org.eclipse.che.ide.ext.java.shared.dto.LinkedPositionGroup) EditorWithAutoSave(org.eclipse.che.ide.api.editor.EditorWithAutoSave) LinkedData(org.eclipse.che.ide.ext.java.shared.dto.LinkedData) Region(org.eclipse.che.ide.ext.java.shared.dto.Region) LinkedModelData(org.eclipse.che.ide.api.editor.link.LinkedModelData)

Example 33 with Position

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

the class AbstractDocument method getEndingPositions.

/**
     * A list of positions in the given category with an end position inside the given region. The order of the positions is
     * arbitrary.
     *
     * @param category
     *         the position category
     * @param offset
     *         the offset of the region
     * @param length
     *         the length of the region
     * @return a list of the positions in the region
     * @throws BadPositionCategoryException
     *         if category is undefined in this document
     * @since 3.4
     */
private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException {
    List<Position> positions = fEndPositions.get(category);
    if (positions == null)
        throw new BadPositionCategoryException();
    int indexStart = computeIndexInPositionList(positions, offset, false);
    int indexEnd = computeIndexInPositionList(positions, offset + length, false);
    return positions.subList(indexStart, indexEnd);
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)

Example 34 with Position

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

the class AbstractDocument method removePosition.

/*
     * @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
     */
public void removePosition(String category, Position position) throws BadPositionCategoryException {
    if (position == null)
        return;
    if (category == null)
        throw new BadPositionCategoryException();
    List<Position> c = fPositions.get(category);
    if (c == null)
        throw new BadPositionCategoryException();
    removeFromPositionsList(c, position, true);
    List<Position> endPositions = fEndPositions.get(category);
    if (endPositions == null)
        throw new BadPositionCategoryException();
    removeFromPositionsList(endPositions, position, false);
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)

Example 35 with Position

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

the class AnnotationModelImpl method removeAnnotation.

/**
     * Removes the given annotation from the annotation model. If requested inform all model change listeners about this change.
     *
     * @param annotation the annotation to be removed
     * @param fireModelChanged indicates whether to notify all model listeners
     */
protected void removeAnnotation(final Annotation annotation, final boolean fireModelChanged) {
    if (annotations.containsKey(annotation)) {
        Position pos = null;
        pos = annotations.get(annotation);
        annotations.remove(annotation);
        positions.remove(pos);
        getAnnotationModelEvent().annotationRemoved(annotation, pos);
        if (fireModelChanged) {
            fireModelChanged();
        }
    }
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition)

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