Search in sources :

Example 11 with IJavaScriptElement

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

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

the class JsJfaceNode method getJavaElement.

public synchronized IJavaScriptElement getJavaElement() {
    /*
		 * since this may become 'stale' we need to rediscover our element every
		 * time we're asked
		 */
    IJsTranslation tran = getTranslation();
    int startOffset = getStartOffset();
    int endOffset = getLength();
    if (typeName != null) {
        IJavaScriptElement myType = tran.getCompilationUnit().getType(typeName);
        return myType;
    }
    IJavaScriptElement[] elements = tran.getAllElementsInJsRange(startOffset, startOffset + endOffset);
    if (elements != null) {
        return elements[0];
    } else {
        // $NON-NLS-1$
        System.out.println(Messages.getString("JsJfaceNode.1"));
        return null;
    }
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement)

Example 13 with IJavaScriptElement

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

the class JsTranslation method getAllElementsInJsRange.

/* (non-Javadoc)
	 * @see org.eclipse.wst.jsdt.web.core.internal.java.IJsTranslation#getAllElementsInJsRange(int, int)
	 */
public IJavaScriptElement[] getAllElementsInJsRange(int javaPositionStart, int javaPositionEnd) {
    IJavaScriptElement[] EMTPY_RESULT_SET = new IJavaScriptElement[0];
    IJavaScriptElement[] result = EMTPY_RESULT_SET;
    IJavaScriptElement[] allChildren = null;
    try {
        allChildren = getCompilationUnit().getChildren();
    } catch (JavaScriptModelException e) {
    }
    Vector validChildren = new Vector();
    for (int i = 0; i < allChildren.length; i++) {
        ISourceRange range = getJSSourceRangeOf(allChildren[i]);
        if (javaPositionStart <= range.getOffset() && range.getLength() + range.getOffset() <= (javaPositionEnd)) {
            validChildren.add(allChildren[i]);
        } else if (allChildren[i].getElementType() == IJavaScriptElement.TYPE) {
            validChildren.add(allChildren[i]);
        }
    }
    if (validChildren.size() > 0) {
        result = (IJavaScriptElement[]) validChildren.toArray(new IJavaScriptElement[] {});
    }
    if (result == null || result.length == 0) {
        return EMTPY_RESULT_SET;
    }
    return result;
}
Also used : JavaScriptModelException(org.eclipse.wst.jsdt.core.JavaScriptModelException) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) Vector(java.util.Vector) ISourceRange(org.eclipse.wst.jsdt.core.ISourceRange)

Example 14 with IJavaScriptElement

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

the class ShowHistoryAction method run.

public void run(IAction action) {
    IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(getCurrentSelection());
    if (elements == null || elements.length == 0) {
        return;
    }
    IResource resource = null;
    if (elements[0].isVirtual()) {
        resource = getHostResource(elements[0]);
    } else {
        resource = elements[0].getResource();
    }
    if (resource == null) {
        return;
    }
    try {
        IWorkbenchPage page = targetWorkbenchPart.getSite().getPage();
        IViewPart view = page.showView(IPageLayout.ID_RES_NAV);
        if (view instanceof ISetSelectionTarget) {
            ISelection selection = new StructuredSelection(resource);
            ((ISetSelectionTarget) view).selectReveal(selection);
        }
    } catch (PartInitException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        ExceptionHandler.handle(e, targetWorkbenchPart.getSite().getShell(), Messages.getString("ShowHistoryAction.0"), Messages.getString("ShowHistoryAction.1") + e);
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource)

Example 15 with IJavaScriptElement

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

the class ShowInScriptExplorerAction method run.

public void run(IAction action) {
    IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(getCurrentSelection());
    if (elements == null || elements.length == 0) {
        return;
    }
    IResource resource = null;
    if (elements[0].isVirtual()) {
        resource = getHostResource(elements[0]);
    } else {
        resource = elements[0].getResource();
    }
    if (resource == null) {
        return;
    }
    try {
        PackageExplorerPart view = PackageExplorerPart.openInActivePerspective();
        view.tryToReveal(resource);
        // IViewPart view= page.showView(IPageLayout.ID_RES_NAV);
        if (view instanceof ISetSelectionTarget) {
            ISelection selection = new StructuredSelection(resource);
            ((ISetSelectionTarget) view).selectReveal(selection);
        }
    } catch (Exception e) {
    // ExceptionHandler.handle(e,
    // targetWorkbenchPart.getSite().getShell(), "Error Opening in
    // Script View", "Error while displaying element in Script View:\n"
    // + e);
    }
}
Also used : IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) PackageExplorerPart(org.eclipse.wst.jsdt.internal.ui.packageview.PackageExplorerPart) IResource(org.eclipse.core.resources.IResource)

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