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