String data = ((CharacterData) node).getData();
String source = node.getSource();
if (data.equals(source)) {
return new DOMPosition(node, offset - start);
}
IStructuredDocumentRegion r = node
.getFirstStructuredDocumentRegion();
int countedData = 0;
// TODO: dead? int offsetInNode = offset - start;
while (r != null) {
if (DOMRegionContext.XML_CHAR_REFERENCE.equals(r.getType())
|| DOMRegionContext.XML_ENTITY_REFERENCE.equals(r
.getType())) {
countedData += 1; // FIXME: what if the entity reference's
// corresponding data is more than 1
// char?
// where can we get that information?
if (r.getEnd() >= offset) {
return new DOMPosition(node, countedData);
}
} else {
if (r.getEnd() >= offset) {
return new DOMPosition(node, countedData + offset
- r.getStart());
}
countedData += r.getLength();
}
r = r.getNext();
}
return new DOMRefPosition(node, true);
} else if (node instanceof Element) {
CMElementDeclaration cm = CMUtil
.getElementDeclaration((Element) node);
if (cm != null && cm.getContentType() == CMElementDeclaration.EMPTY) {
// this node can't have children.
return new DOMRefPosition(node, true);
}
IStructuredDocumentRegion startRegion = node
.getStartStructuredDocumentRegion();
if (startRegion == null) {
return new DOMRefPosition(node, true);
}
int startRegionEnd = node.getStartStructuredDocumentRegion()