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]);
}
}
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;
}
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;
}
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();
}
}
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);
}
}
Aggregations