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;
}
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);
}
}
}
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;
}
Aggregations