use of org.eclipse.jface.text.TypedRegion in project eclipse.platform.text by eclipse.
the class RuleBasedPartitioner method getPartition.
/*
* @see IDocumentPartitioner#getPartition
*/
@Override
public ITypedRegion getPartition(int offset) {
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 webtools.sourceediting by eclipse.
the class JavaHeuristicScanner method getPartition.
/**
* Returns the partition at <code>position</code>.
*
* @param position
* the position to get the partition for
* @return the partition at <code>position</code> or a dummy zero-length
* partition if accessing the document fails
*/
private ITypedRegion getPartition(int position) {
Assert.isTrue(position >= 0);
Assert.isTrue(position <= fDocument.getLength());
try {
return TextUtilities.getPartition(fDocument, fPartitioning, position, false);
} catch (BadLocationException e) {
// $NON-NLS-1$
return new TypedRegion(position, 0, "__no_partition_at_all");
}
}
use of org.eclipse.jface.text.TypedRegion in project webtools.sourceediting by eclipse.
the class BasicStructuredDocument method getPartition.
public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException {
if ((0 > offset) || (offset > getLength()))
throw new BadLocationException();
ITypedRegion result = null;
IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
if (partitioner instanceof IDocumentPartitionerExtension2) {
result = ((IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions);
} else if (partitioner != null) {
result = partitioner.getPartition(offset);
} else if (IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING.equals(partitioning)) {
result = new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE);
} else
throw new BadPartitioningException();
return result;
}
use of org.eclipse.jface.text.TypedRegion in project xtext-eclipse by eclipse.
the class DocumentPartitioner method getPartition.
/**
* {@inheritDoc}
* <p>
* May be replaced or extended by subclasses.
* </p>
*
* @since 2.2
*/
@Override
public synchronized 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());
}
if (isOpenSingleLineCommentPartition(previous, offset)) {
return new TypedRegion(previous.getOffset(), previous.getLength() + 1, 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-eclipse by eclipse.
the class SemanticHighlightingTest method addPosition.
@Override
public void addPosition(int offset, int length, String... id) {
assertEquals(1, id.length);
TypedRegion region = new TypedRegion(offset, length, id[0]);
assertFalse(region.toString(), expectedRegions.isEmpty());
assertTrue("expected: " + expectedRegions.toString() + " but was: " + region, expectedRegions.remove(region));
}
Aggregations