use of org.eclipse.jface.text.ITypedRegion in project eclipse.platform.text by eclipse.
the class ContentFormatter method getPartitioning.
/**
* Returns the partitioning of the given region of the document to be formatted.
* As one partition after the other will be formatted and formatting will
* probably change the length of the formatted partition, it must be kept
* track of the modifications in order to submit the correct partition to all
* formatting strategies. For this, all partitions are remembered as positions
* in a dedicated position category. (As formatting strategies might rely on each
* other, calling them in reversed order is not an option.)
*
* @param region the region for which the partitioning must be determined
* @return the partitioning of the specified region
* @exception BadLocationException of region is invalid in the document
* @since 3.0
*/
private TypedPosition[] getPartitioning(IRegion region) throws BadLocationException {
ITypedRegion[] regions = TextUtilities.computePartitioning(fDocument, fPartitioning, region.getOffset(), region.getLength(), false);
TypedPosition[] positions = new TypedPosition[regions.length];
for (int i = 0; i < regions.length; i++) {
positions[i] = new TypedPosition(regions[i]);
try {
fDocument.addPosition(PARTITIONING, positions[i]);
} catch (BadPositionCategoryException x) {
// should not happen
}
}
return positions;
}
use of org.eclipse.jface.text.ITypedRegion in project eclipse.platform.text by eclipse.
the class PresentationReconciler method getDamageEndOffset.
/**
* Returns the end offset of the damage. If a partition has been split by
* the given document event also the second half of the original
* partition must be considered. This is achieved by using the remembered
* partition range.
*
* @param e the event describing the change
* @return the damage end offset (excluding)
* @exception BadLocationException if method accesses invalid offset
*/
private int getDamageEndOffset(DocumentEvent e) throws BadLocationException {
IDocument d = e.getDocument();
int length = 0;
if (e.getText() != null) {
length = e.getText().length();
if (length > 0)
--length;
}
ITypedRegion partition = getPartition(d, e.getOffset() + length);
int endOffset = partition.getOffset() + partition.getLength();
if (endOffset == e.getOffset())
return -1;
int end = fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength();
if (endOffset < end && end < d.getLength())
partition = getPartition(d, end);
IPresentationDamager damager = getDamager(partition.getType());
if (damager == null)
return -1;
IRegion r = damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
return r.getOffset() + r.getLength();
}
use of org.eclipse.jface.text.ITypedRegion in project eclipse.platform.text by eclipse.
the class Reconciler method initialProcess.
@Override
protected void initialProcess() {
ITypedRegion[] regions = computePartitioning(0, getDocument().getLength());
List<String> contentTypes = new ArrayList<>(regions.length);
for (ITypedRegion region : regions) {
String contentType = region.getType();
if (contentTypes.contains(contentType))
continue;
contentTypes.add(contentType);
IReconcilingStrategy s = getReconcilingStrategy(contentType);
if (s instanceof IReconcilingStrategyExtension) {
IReconcilingStrategyExtension e = (IReconcilingStrategyExtension) s;
e.initialReconcile();
}
}
}
use of org.eclipse.jface.text.ITypedRegion in project eclipse.platform.text by eclipse.
the class DefaultDamagerRepairer method getDamageRegion.
/**
* {@inheritDoc}
* <p>
* This implementation damages entire lines unless clipped by the given partition.
* </p>
*
* @return the full lines containing the document changes described by the document event,
* clipped by the given partition. If there was a partitioning change then the whole
* partition is returned.
*/
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
IRegion info = fDocument.getLineInformationOfOffset(e.getOffset());
int start = Math.max(partition.getOffset(), info.getOffset());
int end = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
// optimize the case of the same line
end = info.getOffset() + info.getLength();
} else
end = endOfLineOf(end);
end = Math.min(partition.getOffset() + partition.getLength(), end);
return new Region(start, end - start);
} catch (BadLocationException x) {
}
}
return partition;
}
use of org.eclipse.jface.text.ITypedRegion in project eclipse.platform.text by eclipse.
the class DefaultPartitioner method computePartitioning.
@Override
public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
checkInitialization();
List<TypedRegion> list = new ArrayList<>();
try {
int endOffset = offset + length;
Position[] category = fDocument.getPositions(fPositionCategory);
TypedPosition previous = null, current = null;
int start, end, gapOffset;
Position gap = new Position(0);
int startIndex = getFirstIndexEndingAfterOffset(category, offset);
int endIndex = getFirstIndexStartingAfterOffset(category, endOffset);
for (int i = startIndex; i < endIndex; i++) {
current = (TypedPosition) category[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());
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
}
if (current.overlapsWith(offset, length)) {
start = Math.max(offset, current.getOffset());
end = Math.min(endOffset, current.getOffset() + current.getLength());
list.add(new TypedRegion(start, end - start, current.getType()));
}
previous = current;
}
if (previous != null) {
gapOffset = previous.getOffset() + previous.getLength();
gap.setOffset(gapOffset);
gap.setLength(fDocument.getLength() - gapOffset);
if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) || (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
start = Math.max(offset, gapOffset);
end = Math.min(endOffset, fDocument.getLength());
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
}
}
if (list.isEmpty())
list.add(new TypedRegion(offset, length, IDocument.DEFAULT_CONTENT_TYPE));
} catch (BadPositionCategoryException x) {
}
TypedRegion[] result = new TypedRegion[list.size()];
list.toArray(result);
return result;
}
Aggregations