Example usage for org.eclipse.jdt.core IMember getAttachedJavadoc

List of usage examples for org.eclipse.jdt.core IMember getAttachedJavadoc

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IMember getAttachedJavadoc.

Prototype

String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException;

Source Link

Document

Returns the Javadoc as HTML source if this element has attached Javadoc, null otherwise.

This should be used only for binary elements.

Usage

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  .j  a  va  2  s  .  co 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: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   ww  w.  jav a  2 s.  c om*/
            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 o  m
 *         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: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  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, urlPrefix);
                if (superMethodReferences == null)
                    return attachedDocInHierarchy;
                superMethodReferences.append(attachedDocInHierarchy);
                return superMethodReferences.toString();
            }
        }
    }
    return sourceJavadoc;
}

From source file:org.python.pydev.editor.codecompletion.JavaElementToken.java

License:Open Source License

private Reader getContentReader(IMember member, IProgressMonitor monitor) throws JavaModelException {
    Reader contentReader = JavadocContentAccess.getContentReader(member, true);
    if (contentReader != null) {
        return contentReader;
    }//from   w w w .ja  v  a  2  s .co  m

    if (member.getOpenable().getBuffer() == null) { // only if no source available
        String s = member.getAttachedJavadoc(monitor);
        if (s != null) {
            return new StringReader(s);
        }
    }
    return null;
}