use of org.eclipse.wst.xml.core.internal.document.NodeImpl in project webtools.sourceediting by eclipse.
the class JFaceNodeAdapterForJs method filterChildrenForRange.
private Object[] filterChildrenForRange(IJavaScriptElement[] allChildren, Node node) {
int javaPositionEnd = ((NodeImpl) node).getEndOffset();
int javaPositionStart = ((NodeImpl) node).getStartOffset();
javaPositionStart = getTranslation(node).getJavaScriptOffset(((NodeImpl) node).getStartOffset());
if (javaPositionStart < 0)
javaPositionStart = ((NodeImpl) node).getStartOffset();
javaPositionEnd = getTranslation(node).getJavaScriptOffset(((NodeImpl) node).getEndOffset() - 1);
if (javaPositionEnd < 0)
javaPositionEnd = ((NodeImpl) node).getEndOffset();
List validChildren = new ArrayList();
for (int i = 0; i < allChildren.length; i++) {
ISourceRange range = null;
if (allChildren[i] instanceof Member) {
try {
range = ((Member) allChildren[i]).getNameRange();
} catch (JavaScriptModelException e) {
Logger.logException("Error getting range of Member child.", e);
}
} else if (allChildren[i] instanceof SourceRefElement) {
try {
range = ((SourceRefElement) allChildren[i]).getSourceRange();
} catch (JavaScriptModelException e) {
Logger.logException("Error getting range of SourceRefElement child.", e);
}
}
if (range != null && javaPositionStart <= range.getOffset() && (range.getLength() + range.getOffset()) <= (javaPositionEnd)) {
int htmlLength = range.getLength();
int htmlOffset = range.getOffset();
if (htmlLength >= 0 && htmlOffset >= 0) {
Position position = new Position(htmlOffset, htmlLength);
validChildren.add(getJsNode(node.getParentNode(), allChildren[i], position));
}
}
}
Object[] result = new Object[0];
if (validChildren.size() > 0) {
result = validChildren.toArray();
}
if (result == null || result.length == 0) {
return new IJavaScriptElement[0];
}
return result;
}
Aggregations