Search in sources :

Example 1 with TypedRegion

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

the class AbstractDocument method getPartition.

/* @see org.eclipse.jface.text.IDocument#getPartition(int) */
public TypedRegion getPartition(int offset) throws BadLocationException {
    TypedRegion partition = null;
    try {
        partition = getPartition(DEFAULT_PARTITIONING, offset, false);
        Assert.isNotNull(partition);
    } catch (BadPartitioningException e) {
        Assert.isTrue(false);
    }
    return partition;
}
Also used : TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion)

Example 2 with TypedRegion

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

the class ReconcilerWithAutoSave method process.

/**
     * Processes a dirty region. If the dirty region is <code>null</code> the whole document is consider being dirty. The dirty region is
     * partitioned by the document and each partition is handed over to a reconciling strategy registered for the partition's content type.
     *
     * @param dirtyRegion the dirty region to be processed
     */
protected void process(final DirtyRegion dirtyRegion) {
    Region region = dirtyRegion;
    if (region == null) {
        region = new RegionImpl(0, getDocument().getContents().length());
    }
    final List<TypedRegion> regions = computePartitioning(region.getOffset(), region.getLength());
    for (final TypedRegion r : regions) {
        final ReconcilingStrategy strategy = getReconcilingStrategy(r.getType());
        if (strategy == null) {
            continue;
        }
        if (dirtyRegion != null) {
            strategy.reconcile(dirtyRegion, r);
        } else {
            strategy.reconcile(r);
        }
    }
}
Also used : Region(org.eclipse.che.ide.api.editor.text.Region) TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion) TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion) RegionImpl(org.eclipse.che.ide.api.editor.text.RegionImpl)

Example 3 with TypedRegion

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

the class DefaultPartitioner method computePartitioning.

private List<TypedRegion> computePartitioning(final int offset, final int length, final boolean includeZeroLengthPartitions) {
    final List<TypedRegion> result = new ArrayList<>();
    final int contentLength = getContentLength();
    try {
        final int endOffset = offset + length;
        final List<TypedPosition> category = getPositions();
        TypedPosition previous = null;
        TypedPosition current = null;
        int start, end, gapOffset;
        final Position gap = new Position(0);
        final int startIndex = getFirstIndexEndingAfterOffset(category, offset);
        final int endIndex = getFirstIndexStartingAfterOffset(category, endOffset);
        for (int i = startIndex; i < endIndex; i++) {
            current = category.get(i);
            gapOffset = (previous != null) ? previous.getOffset() + previous.getLength() : 0;
            gap.setOffset(gapOffset);
            gap.setLength(current.getOffset() - gapOffset);
            if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
                start = Math.max(offset, gapOffset);
                end = Math.min(endOffset, gap.getOffset() + gap.getLength());
                result.add(new TypedRegionImpl(start, end - start, DEFAULT_CONTENT_TYPE));
            }
            if (current.overlapsWith(offset, length)) {
                start = Math.max(offset, current.getOffset());
                end = Math.min(endOffset, current.getOffset() + current.getLength());
                result.add(new TypedRegionImpl(start, end - start, current.getType()));
            }
            previous = current;
        }
        if (previous != null) {
            gapOffset = previous.getOffset() + previous.getLength();
            gap.setOffset(gapOffset);
            gap.setLength(contentLength - gapOffset);
            if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
                start = Math.max(offset, gapOffset);
                end = Math.min(endOffset, contentLength);
                result.add(new TypedRegionImpl(start, end - start, DEFAULT_CONTENT_TYPE));
            }
        }
        if (result.isEmpty()) {
            result.add(new TypedRegionImpl(offset, length, DEFAULT_CONTENT_TYPE));
        }
    } catch (final BadPositionCategoryException ex) {
        Logger.getLogger(DefaultPartitioner.class.getName()).fine("Bad position in computePartitioning.");
    } catch (final RuntimeException ex) {
        Logger.getLogger(DefaultPartitioner.class.getName()).warning("computePartitioning failed.");
        throw ex;
    }
    return result;
}
Also used : TypedRegionImpl(org.eclipse.che.ide.api.editor.text.TypedRegionImpl) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) ArrayList(java.util.ArrayList) BadPositionCategoryException(org.eclipse.che.ide.api.editor.text.BadPositionCategoryException) TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion)

Aggregations

TypedRegion (org.eclipse.che.ide.api.editor.text.TypedRegion)3 ArrayList (java.util.ArrayList)1 BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)1 Position (org.eclipse.che.ide.api.editor.text.Position)1 Region (org.eclipse.che.ide.api.editor.text.Region)1 RegionImpl (org.eclipse.che.ide.api.editor.text.RegionImpl)1 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)1 TypedRegionImpl (org.eclipse.che.ide.api.editor.text.TypedRegionImpl)1