Search in sources :

Example 1 with IMember

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

the class AddJavaDocStubAction method run.

public void run(IAction action) {
    IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(selection);
    if (elements == null || elements.length < 1) {
        return;
    }
    IJavaScriptElement parent = elements[0].getParent();
    /* find the cu */
    while (parent != null && !(parent instanceof IJavaScriptUnit)) {
    }
    if (parent != null) {
        ArrayList members = new ArrayList();
        for (int i = 0; i < elements.length; i++) {
            if (elements[i] instanceof IMember) {
                members.add(elements[i]);
            }
        }
        JsJfaceNode[] node = SimpleJSDTActionProxy.getJsJfaceNodesFromSelection(selection);
        /* only should be one node */
        run((IJavaScriptUnit) parent, (IMember[]) members.toArray(new IMember[members.size()]), node[0]);
    }
}
Also used : IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) ArrayList(java.util.ArrayList) JsJfaceNode(org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode) IJavaScriptUnit(org.eclipse.wst.jsdt.core.IJavaScriptUnit) IMember(org.eclipse.wst.jsdt.core.IMember)

Example 2 with IMember

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

the class JSDTHoverProcessor method getHoverInfo.

private String getHoverInfo(IJavaScriptElement[] result) {
    StringBuffer buffer = new StringBuffer();
    int nResults = result.length;
    if (nResults == 0) {
        return null;
    }
    if (nResults > 1) {
        for (int i = 0; i < result.length; i++) {
            HTMLPrinter.startBulletList(buffer);
            IJavaScriptElement curr = result[i];
            if (curr instanceof IMember || curr.getElementType() == IJavaScriptElement.LOCAL_VARIABLE) {
                HTMLPrinter.addBullet(buffer, getInfoText(curr));
            }
            HTMLPrinter.endBulletList(buffer);
        }
    } else {
        IJavaScriptElement curr = result[0];
        if (curr == null) {
            return null;
        }
        if (curr instanceof IMember) {
            IMember member = (IMember) curr;
            HTMLPrinter.addSmallHeader(buffer, getInfoText(member));
            Reader reader;
            try {
                reader = JSdocContentAccess.getHTMLContentReader(member, true, true);
            } catch (JavaScriptModelException ex) {
                return null;
            }
            if (reader != null) {
                HTMLPrinter.addParagraph(buffer, reader);
            }
        } else if (curr.getElementType() == IJavaScriptElement.LOCAL_VARIABLE) {
            HTMLPrinter.addSmallHeader(buffer, getInfoText(curr));
        }
    }
    if (buffer.length() > 0) {
        HTMLPrinter.insertPageProlog(buffer, 0);
        HTMLPrinter.addPageEpilog(buffer);
        return buffer.toString();
    }
    return null;
}
Also used : JavaScriptModelException(org.eclipse.wst.jsdt.core.JavaScriptModelException) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) Reader(java.io.Reader) IMember(org.eclipse.wst.jsdt.core.IMember)

Example 3 with IMember

use of org.eclipse.wst.jsdt.core.IMember 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

IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)3 IMember (org.eclipse.wst.jsdt.core.IMember)3 JavaScriptModelException (org.eclipse.wst.jsdt.core.JavaScriptModelException)2 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Position (org.eclipse.jface.text.Position)1 IJavaScriptUnit (org.eclipse.wst.jsdt.core.IJavaScriptUnit)1 ISourceRange (org.eclipse.wst.jsdt.core.ISourceRange)1 JavaElement (org.eclipse.wst.jsdt.internal.core.JavaElement)1 Member (org.eclipse.wst.jsdt.internal.core.Member)1 JsJfaceNode (org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode)1 Node (org.w3c.dom.Node)1