}
ITextRegion region = null;
int offset = documentPosition;
IStructuredDocumentRegion flatNode = null;
IDOMNode node = (IDOMNode) domnode;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
if (node.getStructuredDocument().getLength() == 0) {
return null;
}
ITextRegion result = node.getStructuredDocument()
.getRegionAtCharacterOffset(offset)
.getRegionAtCharacterOffset(offset);
while (result == null) {
offset--;
result = node.getStructuredDocument()
.getRegionAtCharacterOffset(offset)
.getRegionAtCharacterOffset(offset);
}
return result;
}
IStructuredDocumentRegion startTag = node
.getStartStructuredDocumentRegion();
IStructuredDocumentRegion endTag = node
.getEndStructuredDocumentRegion();
// Determine if the offset is within the start
// IStructuredDocumentRegion, end IStructuredDocumentRegion, or
// somewhere within the Node's XML content.
if ((startTag != null) && (startTag.getStartOffset() <= offset)
&& (offset < startTag.getStartOffset() + startTag.getLength())) {
flatNode = startTag;
} else if ((endTag != null) && (endTag.getStartOffset() <= offset)
&& (offset < endTag.getStartOffset() + endTag.getLength())) {
flatNode = endTag;
}
if (flatNode != null) {
// the offset is definitely within the start or end tag, continue
// on and find the region
region = getCompletionRegion(offset, flatNode);
} else {
// Start test code added by Gavin Lei
System.out
.println("Build ITextRegion instance with char '< or $' start node instance:"
+ node.getClass());
IStructuredDocumentRegion preFlatNode = node
.getStructuredDocument().getRegionAtCharacterOffset(
offset - 1);
System.out.println(node.getStructuredDocument().getClass());
System.out.println(preFlatNode.getPrevious().toString());
// the docPosition is neither within the start nor the end, so it
// must be content
flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(
offset);
// (pa) ITextRegion refactor
// if (flatNode.contains(documentPosition)) {
if ((flatNode.getStartOffset() <= documentPosition)