List of usage examples for org.eclipse.jdt.core IMember getOpenable
IOpenable getOpenable();
From source file:at.bestsolution.fxide.jdt.editor.JDTJavaDocSupport.java
License:Open Source License
private static HtmlString getMemberJavaDoc(IMember member) throws JavaModelException { IBuffer buf = member.getOpenable().getBuffer(); if (buf != null) { ISourceRange javadocRange = member.getJavadocRange(); if (javadocRange != null) { String rawJavadoc = buf.getText(javadocRange.getOffset(), javadocRange.getLength()); return JDTJavaDocSupport.toHtml(member, rawJavadoc); }// www . j a v a2 s .c om } return null; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess.java
License:Open Source License
/** * Gets a reader for an IMember's Javadoc comment content from the source attachment. * The content does contain only the text from the comment without the Javadoc leading star characters. * Returns <code>null</code> if the member does not contain a Javadoc comment or if no source is available. * @param member The member to get the Javadoc of. * @return Returns a reader for the Javadoc comment content or <code>null</code> if the member * does not contain a Javadoc comment or if no source is available * @throws JavaModelException is thrown when the elements javadoc can not be accessed * @since 3.4/*from w w w .ja v a 2s. c o m*/ */ private static Reader internalGetContentReader(IMember member) throws JavaModelException { IBuffer buf = member.getOpenable().getBuffer(); if (buf == null) { return null; // no source attachment found } ISourceRange javadocRange = member.getJavadocRange(); if (javadocRange != null) { JavaDocCommentReader reader = new JavaDocCommentReader(buf, javadocRange.getOffset(), javadocRange.getOffset() + javadocRange.getLength() - 1); if (!containsOnlyInheritDoc(reader, javadocRange.getLength())) { reader.reset(); return reader; } } return null; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess.java
License:Open Source License
/** * Gets a reader for an IMember's Javadoc comment content from the source attachment. * and renders the tags in HTML./*from w w w . ja v a2 s . c o m*/ * Returns <code>null</code> if the member does not contain a Javadoc comment or if no source is available. * * @param member the member to get the Javadoc of. * @param allowInherited for methods with no (Javadoc) comment, the comment of the overridden * class is returned if <code>allowInherited</code> is <code>true</code> * @param useAttachedJavadoc if <code>true</code> Javadoc will be extracted from attached Javadoc * if there's no source * @return a reader for the Javadoc comment content in HTML or <code>null</code> if the member * does not contain a Javadoc comment or if no source is available * @throws JavaModelException is thrown when the elements Javadoc can not be accessed * @since 3.2 */ public static Reader getHTMLContentReader(IMember member, boolean allowInherited, boolean useAttachedJavadoc) throws JavaModelException { Reader contentReader = internalGetContentReader(member); if (contentReader != null) return new JavaDoc2HTMLTextReader(contentReader); if (useAttachedJavadoc && member.getOpenable().getBuffer() == null) { // only if no source available String s = member.getAttachedJavadoc(null); if (s != null) return new StringReader(s); } if (allowInherited && (member.getElementType() == IJavaElement.METHOD)) return findDocInHierarchy((IMethod) member, true, useAttachedJavadoc); return null; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private static String getHTMLContentFromSource(IJavaElement element) throws JavaModelException { IMember member; 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;/*from ww w . ja v a2 s . c o m*/ } else { return null; } IBuffer buf = member.getOpenable().getBuffer(); if (buf == null) { return null; // no source attachment found } ISourceRange javadocRange = member.getJavadocRange(); if (javadocRange == null) { if (canInheritJavadoc(member)) { // Try to use the inheritDoc algorithm. String inheritedJavadoc = javadoc2HTML(member, element, "/***/"); //$NON-NLS-1$ if (inheritedJavadoc != null && inheritedJavadoc.length() > 0) { return inheritedJavadoc; } } return getJavaFxPropertyDoc(member); } String rawJavadoc = buf.getText(javadocRange.getOffset(), javadocRange.getLength()); return javadoc2HTML(member, element, rawJavadoc); }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
private Object findMethodWithAttachedDocInHierarchy(final MethodBinding method) throws JavaModelException { ReferenceBinding type = method.declaringClass; final SelectionRequestor requestor1 = (SelectionRequestor) this.requestor; return new InheritDocVisitor() { public Object visit(ReferenceBinding currType) throws JavaModelException { MethodBinding overridden = findOverriddenMethodInType(currType, method); if (overridden == null) return InheritDocVisitor.CONTINUE; TypeBinding args[] = overridden.parameters; String names[] = new String[args.length]; for (int i = 0; i < args.length; i++) { names[i] = Signature.createTypeSignature(args[i].sourceName(), false); }/*from w ww .jav a2 s . co m*/ IMember member = (IMember) requestor1.findMethodFromBinding(overridden, names, overridden.declaringClass); if (member == null) return InheritDocVisitor.CONTINUE; if (member.getAttachedJavadoc(null) != null) { // for binary methods with attached javadoc and no source attached return overridden; } IOpenable openable = member.getOpenable(); if (openable == null) return InheritDocVisitor.CONTINUE; IBuffer buf = openable.getBuffer(); if (buf == null) { // no source attachment found. This method maybe the one. Stop. return InheritDocVisitor.STOP_BRANCH; } ISourceRange javadocRange = member.getJavadocRange(); if (javadocRange == null) return InheritDocVisitor.CONTINUE; // this method doesn't have javadoc, continue to look. String rawJavadoc = buf.getText(javadocRange.getOffset(), javadocRange.getLength()); if (rawJavadoc != null) { return overridden; } return InheritDocVisitor.CONTINUE; } }.visitInheritDoc(type); }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Gets an IMember's Javadoc comment content from the source or Javadoc attachment * and renders the tags and links in HTML. * Returns <code>null</code> if the member does not contain a Javadoc comment or if no source is available. * * @param member/*from w w w . j a v a 2 s.c om*/ * the member 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 member * does not have a Javadoc comment or if no source is available * @throws org.eclipse.jdt.core.JavaModelException * is thrown when the element's Javadoc cannot be accessed */ public static String getHTMLContent(IMember member, boolean useAttachedJavadoc, String urlPrefix) throws JavaModelException { String sourceJavadoc = getHTMLContentFromSource(member, urlPrefix); if (sourceJavadoc == null || sourceJavadoc.length() == 0 || sourceJavadoc.trim().equals("{@inheritDoc}")) { //$NON-NLS-1$ if (useAttachedJavadoc) { if (member.getOpenable().getBuffer() == null) { // only if no source available return member.getAttachedJavadoc(null); } 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.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java
License:Open Source License
private static String getHTMLContentFromSource(IMember member, String urlPrefix) throws JavaModelException { IBuffer buf = member.getOpenable().getBuffer(); if (buf == null) { return null; // no source attachment found }//from w ww . jav a 2 s .c o m ISourceRange javadocRange = member.getJavadocRange(); if (javadocRange == null) { if (canInheritJavadoc(member)) { // Try to use the inheritDoc algorithm. String inheritedJavadoc = javadoc2HTML(member, "/***/", urlPrefix); //$NON-NLS-1$ if (inheritedJavadoc != null && inheritedJavadoc.length() > 0) { return inheritedJavadoc; } } return null;// getJavaFxPropertyDoc(member); } String rawJavadoc = buf.getText(javadocRange.getOffset(), javadocRange.getLength()); return javadoc2HTML(member, rawJavadoc, urlPrefix); }
From source file:com.curlap.orb.plugin.common.CurlSpecUtil.java
License:Open Source License
public static String getCurlDocString(IMember iMember) throws JavaModelException { ISourceRange range = iMember.getJavadocRange(); if (range == null) return null; IBuffer buf = iMember.getOpenable().getBuffer(); JavaDocCommentReader reader = new JavaDocCommentReader(buf, range.getOffset(), range.getOffset() + range.getLength() - 1); StringBuffer javadocBuf = new StringBuffer(); char[] buffer = new char[1024]; int count;// w ww . j av a 2s.co m try { while ((count = reader.read(buffer)) != -1) javadocBuf.append(buffer, 0, count); } catch (IOException e) { return null; } return javadocBuf.toString(); }
From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java
License:Open Source License
/** * Returns the Javadoc of the given Java member. * /*from w w w . j a v a 2 s. c o m*/ * @param iMember * The member * @param monitor * The progress monitor * @return The Javadoc of the given Java member. */ private String getJavadoc(IMember iMember, IProgressMonitor monitor) { String documentation = ""; //$NON-NLS-1$ try { if (iMember.getJavadocRange() != null) { documentation = iMember.getOpenable().getBuffer().getText(iMember.getJavadocRange().getOffset(), iMember.getJavadocRange().getLength()); } } catch (JavaModelException e) { e.printStackTrace(); } return documentation; }
From source file:org.eclipse.che.jdt.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Gets an IMember's Javadoc comment content from the source or Javadoc attachment * and renders the tags and links in HTML. * Returns <code>null</code> if the member does not contain a Javadoc comment or if no source is available. * * @param member//from w w w . j av a 2 s . com * the member 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 member * does not have a Javadoc comment or if no source is available * @throws org.eclipse.jdt.core.JavaModelException * is thrown when the element's Javadoc cannot be accessed */ public static String getHTMLContent(IMember member, boolean useAttachedJavadoc, String urlPrefix) throws JavaModelException { String sourceJavadoc = getHTMLContentFromSource(member, urlPrefix); if (sourceJavadoc == null || sourceJavadoc.length() == 0 || sourceJavadoc.trim().equals("{@inheritDoc}")) { //$NON-NLS-1$ if (useAttachedJavadoc) { if (member.getOpenable().getBuffer() == null) { // only if no source available return member.getAttachedJavadoc(null); } 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, urlPrefix); if (superMethodReferences == null) return attachedDocInHierarchy; superMethodReferences.append(attachedDocInHierarchy); return superMethodReferences.toString(); } } } return sourceJavadoc; }