List of usage examples for org.eclipse.jdt.core IJavaElement getAttachedJavadoc
String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException;
Returns the Javadoc as HTML source if this element has attached Javadoc, null
otherwise.
This should be used only for binary elements.
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Gets an IJavaElement's Javadoc comment content from the source or Javadoc attachment * and renders the tags and links in HTML. * Returns <code>null</code> if the element does not have a Javadoc comment or if no source is available. * * @param element the element to get the Javadoc of * @param useAttachedJavadoc if <code>true</code> Javadoc will be extracted from attached Javadoc * if there's no source * @return the Javadoc comment content in HTML or <code>null</code> if the element * does not have a Javadoc comment or if no source is available * @throws CoreException is thrown when the element's Javadoc cannot be accessed *//*from ww w .ja v a2 s . c om*/ public static String getHTMLContent(IJavaElement element, boolean useAttachedJavadoc) throws CoreException { if (element instanceof IPackageFragment) { return getHTMLContent((IPackageFragment) element); } if (element instanceof IPackageDeclaration) { return getHTMLContent((IPackageDeclaration) element); } if (!(element instanceof IMember || element instanceof ITypeParameter || (element instanceof ILocalVariable && (((ILocalVariable) element).isParameter())))) { return null; } String sourceJavadoc = getHTMLContentFromSource(element); if (sourceJavadoc == null || sourceJavadoc.length() == 0 || sourceJavadoc.trim().equals("{@inheritDoc}")) { //$NON-NLS-1$ if (useAttachedJavadoc) { if (element.getOpenable().getBuffer() == null) { // only if no source available return element.getAttachedJavadoc(null); } IMember member = null; if (element instanceof ILocalVariable) { member = ((ILocalVariable) element).getDeclaringMember(); } else if (element instanceof ITypeParameter) { member = ((ITypeParameter) element).getDeclaringMember(); } else if (element instanceof IMember) { member = (IMember) element; } if (canInheritJavadoc(member)) { IMethod method = (IMethod) member; String attachedDocInHierarchy = findAttachedDocInHierarchy(method); // Prepend "Overrides:" / "Specified by:" reference headers to make clear // that description has been copied from super method. if (attachedDocInHierarchy == null) return sourceJavadoc; StringBuffer superMethodReferences = createSuperMethodReferences(method); if (superMethodReferences == null) return attachedDocInHierarchy; superMethodReferences.append(attachedDocInHierarchy); return superMethodReferences.toString(); } } } return sourceJavadoc; }
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
public List<JavaElement> ProcessQuickInfoRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception { if (ActiveTypeRoots.containsKey(typeRootId)) { ITypeRoot cu = ActiveTypeRoots.get(typeRootId); cu.getBuffer().setContents(fileParseContents.toCharArray()); IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); List<JavaElement> ret = new ArrayList<JavaElement>(); long flags = JavaElementLabelComposer.ALL_FULLY_QUALIFIED | JavaElementLabelComposer.ALL_DEFAULT | JavaElementLabelComposer.M_PRE_RETURNTYPE | JavaElementLabelComposer.F_PRE_TYPE_SIGNATURE; for (IJavaElement element : elements) { StringBuffer buffer = new StringBuffer(); JavaElementLabelComposer composer = new JavaElementLabelComposer(buffer); composer.appendElementLabel(element, flags); System.out.println(element.getPath().toString()); JavaElement.Builder b = JavaElement.newBuilder().setDefinition(buffer.toString()); String javaDoc = null; try { javaDoc = element.getAttachedJavadoc(null); } catch (JavaModelException jme) { jme.printStackTrace();// w w w . j a va 2s . c o m } if (javaDoc != null) b.setJavaDoc(javaDoc); ret.add(b.build()); } return ret; } return null; }
From source file:org.eclipse.flux.jdt.services.JavaDocService.java
License:Open Source License
public JSONObject getJavadoc(String username, String requestorResourcePath, int offset, int length) { try {/*w w w . ja v a 2 s . c om*/ ICompilationUnit liveEditUnit = liveEditUnits.getLiveEditUnit(username, requestorResourcePath); if (liveEditUnit != null) { IJavaElement[] elements = liveEditUnit.codeSelect(offset, length); if (elements != null && elements.length > 0) { JSONObject result = new JSONObject(); IJavaElement element = elements[0]; String javadoc = null; if (element instanceof IMember && !((IMember) element).isBinary()) { javadoc = getJavadocFromSourceElement((IMember) element); } else { javadoc = element.getAttachedJavadoc(null); } result.put("javadoc", javadoc); return result; } } } catch (JavaModelException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return null; }