Search in sources :

Example 21 with IJavaScriptElement

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

the class JFaceNodeAdapterForJs method hasChildren.

public boolean hasChildren(Object object) {
    if (object instanceof IJavaScriptElement) {
        return getJavaElementProvider().hasChildren(object);
    }
    Node node = (Node) object;
    if (node instanceof IJavaWebNode) {
        return ((IJavaWebNode) object).hasChildren();
    }
    if (isJSElementParent(node)) {
        Object[] nodes = getJSElementsFromNode(node.getFirstChild(), false);
        boolean hasElements = (nodes != null && nodes.length > 0);
        return hasElements;
    }
    return super.hasChildren(object);
}
Also used : Node(org.w3c.dom.Node) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement)

Example 22 with IJavaScriptElement

use of org.eclipse.wst.jsdt.core.IJavaScriptElement 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;
}
Also used : NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) Position(org.eclipse.jface.text.Position) JavaScriptModelException(org.eclipse.wst.jsdt.core.JavaScriptModelException) ArrayList(java.util.ArrayList) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) ArrayList(java.util.ArrayList) List(java.util.List) IMember(org.eclipse.wst.jsdt.core.IMember) Member(org.eclipse.wst.jsdt.internal.core.Member) ISourceRange(org.eclipse.wst.jsdt.core.ISourceRange) SourceRefElement(org.eclipse.wst.jsdt.internal.core.SourceRefElement)

Aggregations

IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)22 IResource (org.eclipse.core.resources.IResource)6 JavaScriptModelException (org.eclipse.wst.jsdt.core.JavaScriptModelException)6 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)6 ISelection (org.eclipse.jface.viewers.ISelection)4 IMember (org.eclipse.wst.jsdt.core.IMember)4 ISourceRange (org.eclipse.wst.jsdt.core.ISourceRange)4 ArrayList (java.util.ArrayList)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)3 IJavaScriptUnit (org.eclipse.wst.jsdt.core.IJavaScriptUnit)3 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)3 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)3 List (java.util.List)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)2 IRegion (org.eclipse.jface.text.IRegion)2