Search in sources :

Example 1 with BadPositionCategoryException

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

the class DefaultPartitioner method getPartition.

@Override
public TypedRegion getPartition(final int offset) {
    final int contentLength = getContentLength();
    List<TypedPosition> category = null;
    try {
        category = getPositions();
    } catch (final BadPositionCategoryException e) {
        Log.warn(DefaultPartitioner.class, "Invalid position cateory... with default category! ", e);
        return defaultRegion();
    }
    if (category == null || category.size() == 0) {
        return defaultRegion();
    }
    Integer index = null;
    try {
        index = this.documentPositionMap.computeIndexInCategory(positionCategory, offset);
    } catch (final BadLocationException e) {
        Log.warn(DefaultPartitioner.class, "Invalid location " + offset + " (max=" + contentLength + ").");
        return defaultRegion();
    } catch (final BadPositionCategoryException e) {
        Log.warn(DefaultPartitioner.class, "Invalid position cateory... with default category " + positionCategory + "!", e);
        return defaultRegion();
    }
    if (index == null) {
        return defaultRegion();
    }
    if (index < category.size()) {
        final TypedPosition next = category.get(index);
        if (offset == next.offset) {
            return new TypedRegionImpl(next.getOffset(), next.getLength(), next.getType());
        }
        if (index == 0) {
            return new TypedRegionImpl(0, next.offset, DEFAULT_CONTENT_TYPE);
        }
        final TypedPosition previous = category.get(index - 1);
        if (previous.includes(offset)) {
            return new TypedRegionImpl(previous.getOffset(), previous.getLength(), previous.getType());
        }
        final int endOffset = previous.getOffset() + previous.getLength();
        return new TypedRegionImpl(endOffset, next.getOffset() - endOffset, DEFAULT_CONTENT_TYPE);
    }
    final TypedPosition previous = category.get(category.size() - 1);
    if (previous.includes(offset)) {
        return new TypedRegionImpl(previous.getOffset(), previous.getLength(), previous.getType());
    }
    final int endOffset = previous.getOffset() + previous.getLength();
    return new TypedRegionImpl(endOffset, contentLength - endOffset, DEFAULT_CONTENT_TYPE);
}
Also used : TypedRegionImpl(org.eclipse.che.ide.api.editor.text.TypedRegionImpl) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException) BadLocationException(org.eclipse.che.ide.api.editor.text.BadLocationException)

Example 2 with BadPositionCategoryException

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

the class AbstractDocument method addPosition.

/*
     * @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
     */
public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
    if (category == null)
        throw new BadPositionCategoryException();
    if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength()))
        throw new BadLocationException();
    List<Position> list = fPositions.get(category);
    if (list == null)
        throw new BadPositionCategoryException();
    list.add(computeIndexInPositionList(list, position.offset, true), position);
    List<Position> endPositions = fEndPositions.get(category);
    if (endPositions == null)
        throw new BadPositionCategoryException();
    endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position);
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException) BadLocationException(org.eclipse.che.ide.api.editor.text.BadLocationException)

Example 3 with BadPositionCategoryException

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

the class AbstractDocument method getStartingPositions.

/**
     * A list of positions in the given category with an offset 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
     */
private List<Position> getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException {
    List<Position> positions = fPositions.get(category);
    if (positions == null)
        throw new BadPositionCategoryException();
    int indexStart = computeIndexInPositionList(positions, offset, true);
    int indexEnd = computeIndexInPositionList(positions, offset + length, true);
    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 4 with BadPositionCategoryException

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

the class AbstractDocument method getPositions.

/* @see org.eclipse.jface.text.IDocument#getPositions(java.lang.String) */
public Position[] getPositions(String category) throws BadPositionCategoryException {
    if (category == null)
        throw new BadPositionCategoryException();
    List<Position> c = fPositions.get(category);
    if (c == null)
        throw new BadPositionCategoryException();
    Position[] positions = new Position[c.size()];
    c.toArray(positions);
    return positions;
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)

Example 5 with BadPositionCategoryException

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

the class AbstractDocument method removePositionCategory.

/*
     * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String)
     */
public void removePositionCategory(String category) throws BadPositionCategoryException {
    if (category == null)
        return;
    if (!containsPositionCategory(category))
        throw new BadPositionCategoryException();
    fPositions.remove(category);
    fEndPositions.remove(category);
}
Also used : BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)

Aggregations

BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)9 Position (org.eclipse.che.ide.api.editor.text.Position)7 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)3 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)3 TypedRegionImpl (org.eclipse.che.ide.api.editor.text.TypedRegionImpl)2 ArrayList (java.util.ArrayList)1 TypedRegion (org.eclipse.che.ide.api.editor.text.TypedRegion)1 Token (org.eclipse.che.ide.api.editor.text.rules.Token)1