Class Comment

  • Direct Known Subclasses:
    BlockComment, Javadoc, LineComment

    public abstract class Comment
    extends ASTNode
    Abstract base class for all AST nodes that represent comments. There are exactly three kinds of comment: line comments (LineComment), block comments (BlockComment), and doc comments (Javadoc).
     Comment:
         LineComment
         BlockComment
         Javadoc
     
    Since:
    3.0
    • Method Detail

      • isBlockComment

        public final boolean isBlockComment()
        Returns whether this comment is a block comment (BlockComment).
        Returns:
        true if this is a block comment, and false otherwise
      • isLineComment

        public final boolean isLineComment()
        Returns whether this comment is a line comment (LineComment).
        Returns:
        true if this is a line comment, and false otherwise
      • isDocComment

        public final boolean isDocComment()
        Returns whether this comment is a doc comment (Javadoc).
        Returns:
        true if this is a doc comment, and false otherwise
      • getAlternateRoot

        public final ASTNode getAlternateRoot()
        Returns the root AST node that this comment occurs within, or null if none (or not recorded).

        Typically, the comment nodes created while parsing a compilation unit are not considered descendents of the normal AST root, namely an CompilationUnit. Instead, these comment nodes exist outside the normal AST and each is a root in its own right. This optional property provides a well-known way to navigate from the comment to the compilation unit in such cases. Note that the alternate root property is not one of the comment node's children. It is simply a reference to a node.

        Returns:
        the alternate root node, or null if none
        See Also:
        setAlternateRoot(ASTNode)
      • setAlternateRoot

        public final void setAlternateRoot​(ASTNode root)
        Returns the root AST node that this comment occurs within, or null if none (or not recorded).
        Parameters:
        root - the alternate root node, or null if none
        See Also:
        getAlternateRoot()