use of org.eclipse.wst.jsdt.internal.core.SourceRefElement 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;
}
use of org.eclipse.wst.jsdt.internal.core.SourceRefElement in project webtools.sourceediting by eclipse.
the class JFaceNodeAdapterForJs method getJsNode.
private Object getJsNode(Node parent, IJavaScriptElement root, Position position) {
JsJfaceNode instance = null;
if (root.getElementType() == IJavaScriptElement.TYPE) {
instance = new JsJfaceNode(parent, root, position, ((SourceRefElement) root).getElementName());
} else if (root.getElementType() == IJavaScriptElement.FIELD) {
/* Field refrence, possibly to a type may need to implement later */
instance = new JsJfaceNode(parent, root, position);
} else {
instance = new JsJfaceNode(parent, root, position);
}
String name = getJavaElementLabelProvider().getText(root);
instance.setName(name);
// ((JsJfaceNode)instance).setAdapterRegistry(registry);
INodeAdapter adapter = (instance).getAdapterFor(IJFaceNodeAdapter.class);
if (!(adapter instanceof JFaceNodeAdapterForJs)) {
(instance).removeAdapter(adapter);
(instance).addAdapter(this);
}
return instance;
}
Aggregations