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