Search in sources :

Example 1 with JavaElement

use of org.eclipse.wst.jsdt.internal.core.JavaElement in project webtools.sourceediting by eclipse.

the class JFaceNodeAdapterForJs method getChildren.

public Object[] getChildren(Object object) {
    if (object instanceof IJavaScriptElement) {
        return getJavaElementProvider().getChildren(object);
    }
    if (object instanceof IJavaWebNode) {
        JavaElement enclosedElement = (JavaElement) ((IJavaWebNode) object).getJavaElement();
        if (enclosedElement != null) {
            try {
                IJavaScriptElement[] children = enclosedElement.getChildren();
                if (children == null) {
                    return new IJavaScriptElement[0];
                }
                Object[] nodes = new Object[children.length];
                Node parent = ((IJavaWebNode) object).getParentNode();
                for (int i = 0; i < children.length; i++) {
                    // int htmllength = ((SourceRefElement) (children[i])).getSourceRange().getLength();
                    // int htmloffset = ((SourceRefElement) (children[i])).getSourceRange().getOffset();
                    IJavaScriptElement javaElement = children[i];
                    ISourceRange range = null;
                    if (javaElement instanceof Member) {
                        range = ((IMember) javaElement).getNameRange();
                    } else {
                        range = ((ISourceReference) javaElement).getSourceRange();
                    }
                    int htmllength = range.getLength();
                    int htmloffset = range.getOffset();
                    Position position = new Position(htmloffset, htmllength);
                    nodes[i] = getJsNode(parent, javaElement, position);
                }
                return nodes;
            } catch (JavaScriptModelException ex) {
            }
        }
    }
    Node node = (Node) object;
    if (isJSElementParent(node)) {
        Object[] results = getJSElementsFromNode(node.getFirstChild(), true);
        return filter(results);
    }
    return super.getChildren(object);
}
Also used : JavaElement(org.eclipse.wst.jsdt.internal.core.JavaElement) Position(org.eclipse.jface.text.Position) JavaScriptModelException(org.eclipse.wst.jsdt.core.JavaScriptModelException) Node(org.w3c.dom.Node) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) IMember(org.eclipse.wst.jsdt.core.IMember) Member(org.eclipse.wst.jsdt.internal.core.Member) ISourceRange(org.eclipse.wst.jsdt.core.ISourceRange)

Aggregations

Position (org.eclipse.jface.text.Position)1 IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)1 IMember (org.eclipse.wst.jsdt.core.IMember)1 ISourceRange (org.eclipse.wst.jsdt.core.ISourceRange)1 JavaScriptModelException (org.eclipse.wst.jsdt.core.JavaScriptModelException)1 JavaElement (org.eclipse.wst.jsdt.internal.core.JavaElement)1 Member (org.eclipse.wst.jsdt.internal.core.Member)1 Node (org.w3c.dom.Node)1