Search in sources :

Example 1 with SourceRefElement

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

Example 2 with SourceRefElement

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;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) SourceRefElement(org.eclipse.wst.jsdt.internal.core.SourceRefElement)

Aggregations

SourceRefElement (org.eclipse.wst.jsdt.internal.core.SourceRefElement)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 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 Member (org.eclipse.wst.jsdt.internal.core.Member)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1 NodeImpl (org.eclipse.wst.xml.core.internal.document.NodeImpl)1