use of org.eclipse.jface.text.TypedRegion in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method computePartitioning.
public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
List<TypedRegion> list = new ArrayList<TypedRegion>();
try {
int endOffset = offset + length;
Position[] category = document.getPositions(positionCategory);
TypedPosition previous = null;
TypedPosition current = null;
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];
int gapOffset = previous == null ? 0 : previous.getOffset() + previous.getLength();
gap.setOffset(gapOffset);
gap.setLength(current.getOffset() - gapOffset);
if (includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length) || gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
int start = Math.max(offset, gapOffset);
int end = Math.min(endOffset, gap.getOffset() + gap.getLength());
// $NON-NLS-1$
list.add(new TypedRegion(start, end - start, "__dftl_partition_content_type"));
}
if (current.overlapsWith(offset, length)) {
int start = Math.max(offset, current.getOffset());
int end = Math.min(endOffset, current.getOffset() + current.getLength());
list.add(new TypedRegion(start, end - start, current.getType()));
}
previous = current;
}
if (previous != null) {
int gapOffset = previous.getOffset() + previous.getLength();
gap.setOffset(gapOffset);
gap.setLength(document.getLength() - gapOffset);
if (includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length) || gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
int start = Math.max(offset, gapOffset);
int end = Math.min(endOffset, document.getLength());
// $NON-NLS-1$
list.add(new TypedRegion(start, end - start, "__dftl_partition_content_type"));
}
}
if (list.isEmpty()) {
// $NON-NLS-1$
list.add(new TypedRegion(offset, length, "__dftl_partition_content_type"));
}
} catch (BadPositionCategoryException _ex) {
}
TypedRegion[] result = new TypedRegion[list.size()];
list.toArray(result);
return result;
}
use of org.eclipse.jface.text.TypedRegion in project eclipse.platform.text by eclipse.
the class DefaultPartitioner method getPartition.
@Override
public ITypedRegion getPartition(int offset) {
checkInitialization();
try {
Position[] category = fDocument.getPositions(fPositionCategory);
if (category == null || category.length == 0)
return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
int index = fDocument.computeIndexInCategory(fPositionCategory, offset);
if (index < category.length) {
TypedPosition next = (TypedPosition) category[index];
if (offset == next.offset)
return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
if (index == 0)
return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE);
TypedPosition previous = (TypedPosition) category[index - 1];
if (previous.includes(offset))
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
int endOffset = previous.getOffset() + previous.getLength();
return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
}
TypedPosition previous = (TypedPosition) category[category.length - 1];
if (previous.includes(offset))
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
int endOffset = previous.getOffset() + previous.getLength();
return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
} catch (BadPositionCategoryException x) {
} catch (BadLocationException x) {
}
return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
}
use of org.eclipse.jface.text.TypedRegion in project eclipse.platform.text by eclipse.
the class FastPartitioner method getPartition.
/**
* {@inheritDoc}
* <p>
* May be replaced or extended by subclasses.
* </p>
*/
@Override
public ITypedRegion getPartition(int offset) {
checkInitialization();
try {
Position[] category = getPositions();
if (category == null || category.length == 0)
return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
int index = fDocument.computeIndexInCategory(fPositionCategory, offset);
if (index < category.length) {
TypedPosition next = (TypedPosition) category[index];
if (offset == next.offset)
return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
if (index == 0)
return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE);
TypedPosition previous = (TypedPosition) category[index - 1];
if (previous.includes(offset))
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
int endOffset = previous.getOffset() + previous.getLength();
return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
}
TypedPosition previous = (TypedPosition) category[category.length - 1];
if (previous.includes(offset))
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
int endOffset = previous.getOffset() + previous.getLength();
return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
} catch (BadPositionCategoryException x) {
} catch (BadLocationException x) {
}
return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
}
use of org.eclipse.jface.text.TypedRegion in project xtext-xtend by eclipse.
the class TypedRegionMerger method merge.
public ITypedRegion[] merge(ITypedRegion[] original) {
if (original == null || original.length == 0)
return original;
ITypedRegion[] result = new ITypedRegion[original.length];
String contentType = original[0].getType();
result[0] = original[0];
for (int i = 1; i < original.length; i++) {
ITypedRegion copyMe = original[i];
result[i] = new TypedRegion(copyMe.getOffset(), copyMe.getLength(), contentType);
}
return result;
}
use of org.eclipse.jface.text.TypedRegion in project xtext-eclipse by eclipse.
the class TaskHighlightingTest method addPosition.
@Override
public void addPosition(int offset, int length, String... id) {
Assert.assertEquals(1, id.length);
TypedRegion region = new TypedRegion(offset, length, id[0]);
Assert.assertFalse(region.toString(), expectedRegions.isEmpty());
Assert.assertTrue("expected: " + expectedRegions.toString() + " but was: " + region, expectedRegions.remove(region));
}
Aggregations