Search in sources :

Example 6 with IJavaScriptElement

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

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

the class JsFindOccurrencesProcessor method getJavaElementsForCurrentSelection.

/**
 * uses JSPTranslation to get currently selected Java elements.
 *
 * @return currently selected IJavaElements
 */
private IJavaScriptElement[] getJavaElementsForCurrentSelection(IDocument document, ITextSelection selection) {
    IJavaScriptElement[] elements = new IJavaScriptElement[0];
    // get JSP translation object for this viewer's document
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (model != null && model instanceof IDOMModel) {
            IDOMDocument xmlDoc = ((IDOMModel) model).getDocument();
            JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
            if (adapter != null) {
                IJsTranslation translation = adapter.getJsTranslation(false);
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102211
                elements = translation.getElementsFromJsRange(translation.getJavaScriptOffset(selection.getOffset()), translation.getJavaScriptOffset(selection.getOffset() + selection.getLength()));
            }
        }
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return elements;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)

Example 8 with IJavaScriptElement

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

the class JsTranslation method getElementsFromJsRange.

/* (non-Javadoc)
	 * @see org.eclipse.wst.jsdt.web.core.internal.java.IJsTranslation#getElementsFromJsRange(int, int)
	 */
public IJavaScriptElement[] getElementsFromJsRange(int javaPositionStart, int javaPositionEnd) {
    IJavaScriptElement[] EMTPY_RESULT_SET = new IJavaScriptElement[0];
    IJavaScriptElement[] result = EMTPY_RESULT_SET;
    try {
        IJavaScriptUnit cu = getCompilationUnit();
        if (cu != null) {
            synchronized (fLock) {
                int cuDocLength = cu.getBuffer().getLength();
                int javaLength = javaPositionEnd - javaPositionStart;
                if (cuDocLength > 0 && javaPositionStart >= 0 && javaLength >= 0 && javaPositionEnd <= cuDocLength) {
                    result = cu.codeSelect(javaPositionStart, javaLength, getWorkingCopyOwner());
                }
            }
        }
        if (result == null || result.length == 0) {
            return EMTPY_RESULT_SET;
        }
    } catch (JavaScriptModelException x) {
        Logger.logException(x);
    }
    return result;
}
Also used : JavaScriptModelException(org.eclipse.wst.jsdt.core.JavaScriptModelException) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) IJavaScriptUnit(org.eclipse.wst.jsdt.core.IJavaScriptUnit)

Example 9 with IJavaScriptElement

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

the class JSPRenameElementActionDelegate method run.

public void run(IAction action) {
    IJavaScriptElement element = getSelectedElement();
    if (element != null) {
        RenameSupport renameSupport = null;
        try {
            switch(element.getElementType()) {
                case IJavaScriptElement.TYPE:
                    renameSupport = RenameSupport.create((IType) element, element.getElementName(), RenameSupport.UPDATE_REFERENCES);
                    break;
                case IJavaScriptElement.METHOD:
                    renameSupport = RenameSupport.create((IFunction) element, element.getElementName(), RenameSupport.UPDATE_REFERENCES);
                    break;
                case IJavaScriptElement.PACKAGE_FRAGMENT:
                    renameSupport = RenameSupport.create((IPackageFragment) element, element.getElementName(), RenameSupport.UPDATE_REFERENCES);
                    break;
            }
            if (renameSupport != null) {
                renameSupport.openDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                PlatformStatusLineUtil.clearStatusLine();
            }
        } catch (CoreException e) {
            Logger.logException(e);
        }
    } else {
        PlatformStatusLineUtil.displayErrorMessage(JsUIMessages.JSPRenameElementAction_0);
        PlatformStatusLineUtil.addOneTimeClearListener();
    }
}
Also used : IPackageFragment(org.eclipse.wst.jsdt.core.IPackageFragment) CoreException(org.eclipse.core.runtime.CoreException) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) IFunction(org.eclipse.wst.jsdt.core.IFunction) RenameSupport(org.eclipse.wst.jsdt.ui.refactoring.RenameSupport) IType(org.eclipse.wst.jsdt.core.IType)

Example 10 with IJavaScriptElement

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

the class ShowInNavigatorAction 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("ShowInNavigatorAction.0"), Messages.getString("ShowInNavigatorAction.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)

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