try {
Position[] category = fDocument.getPositions(fPositionCategory);
if (category == null || category.length == 0)
return new TypedRegion(0, fDocument.getLength(),
IDocument.DEFAULT_CONTENT_TYPE);
if (DEBUG) {
DebugUtils.printMessage(getClass(), "");
for (int x = 0; x < category.length; x++) {
DebugUtils.printMessage(getClass(), "cats: " + category[x].toString());
}
}
int index = fDocument.computeIndexInCategory(fPositionCategory,
offset);
if (index < category.length) {
CFEPartition next = (CFEPartition) 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);
CFEPartition previous = (CFEPartition) 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);
}
CFEPartition previous = (CFEPartition) 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);
}