Class MarkdownComment

  • All Implemented Interfaces:
    NodeWithRange<Node>, NodeWithTokenRange<Node>, Observable, Visitable, HasParentNode<Node>, Cloneable

    public class MarkdownComment
    extends JavadocComment
    https://openjdk.org/jeps/467 added support for markdown JavaDoc comments /// That are prefixed with /// /// Support `markdown` markup and references /// And supports substrings not allowed in regular block comments, e.g. *_no_space_here_/

    While these comments could be seen as a series of single line comments, they are functionally block comments. The MarkdownComment class adds support for this, although special handling is required for the content of these comments, since the header is no longer only applied to the start of the comment, but rather to the start of each line.

    • Constructor Detail

      • MarkdownComment

        public MarkdownComment()
      • MarkdownComment

        public MarkdownComment​(String content)
      • MarkdownComment

        public MarkdownComment​(TokenRange tokenRange,
                               String content)
        This constructor is used by the parser and is considered private.
    • Method Detail

      • getMarkdownContent

        public String getMarkdownContent()
        Returns the Markdown content of this comment as defined in JEP 467:
        Because horizontal whitespace at the beginning and end of each line of Markdown text may be significant, the content of a Markdown documentation comment is determined as follows: -- Any leading whitespace and the three initial / characters are removed from each line. -- The lines are shifted left, by removing leading whitespace characters, until the non-blank line with the least leading whitespace has no remaining leading whitespace. -- Additional leading whitespace and any trailing whitespace in each line is preserved, because it may be significant. For example, whitespace at the beginning of a line may indicate an indented code block or the continuation of a list item, and whitespace at the end of a line may indicate a hard line break.
      • getHeader

        public String getHeader()
        For other comment types, the header is the character sequence that starts the comment, i.e. /* for block comments and // for line comments and the footer is the character sequence that ends the comment, i.e. * / for block comments, but empty for line comments. These comments can then be reconstructed with c.getHeader() + c.getContent() + c.getFooter(). For Markdown comments, this model doesn't fit as well, since the header is now a character sequence that appears at the start of each line. For ease of use, the leading /// is now included in the comment content, returned by the getContent() method, while the getMarkdownContent() method returns the comment content with the leading /// stripped from each line.
        Specified by:
        getHeader in class Comment
        Returns:
        the empty string
      • getFooter

        public String getFooter()
        Markdown comments are not terminated by a specific character sequence, so just use the empty string as a footer.
        Specified by:
        getFooter in class Comment
        Returns:
        the empty string
      • accept

        public <R,​A> R accept​(GenericVisitor<R,​A> v,
                                    A arg)
        Description copied from interface: Visitable
        Accept method for visitor support.
        Type Parameters:
        R - the type of the return value of the visitor
        A - the type the user argument passed to the visitor
        Parameters:
        v - the visitor implementation
        arg - the argument passed to the visitor (of type A)
        Returns:
        the result of the visit (of type R)
      • accept

        public <A> void accept​(VoidVisitor<A> v,
                               A arg)
        Description copied from interface: Visitable
        Accept method for visitor support.
        Type Parameters:
        A - the type the argument passed for the visitor
        Parameters:
        v - the visitor implementation
        arg - any value relevant for the visitor (of type A)