Search in sources :

Example 6 with NodeImpl

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;
}
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

NodeImpl (org.eclipse.wst.xml.core.internal.document.NodeImpl)6 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)3 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)3 IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)2 JavaScriptModelException (org.eclipse.wst.jsdt.core.JavaScriptModelException)2 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)2 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Position (org.eclipse.jface.text.Position)1 IMember (org.eclipse.wst.jsdt.core.IMember)1 ISourceRange (org.eclipse.wst.jsdt.core.ISourceRange)1 Member (org.eclipse.wst.jsdt.internal.core.Member)1