Class Comment

java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.comments.Comment
All Implemented Interfaces:
NodeWithRange<Node>, NodeWithTokenRange<Node>, Observable, Visitable, HasParentNode<Node>, Cloneable
Direct Known Subclasses:
BlockComment, JavadocComment, LineComment

public abstract class Comment extends Node
Abstract class for all AST nodes that represent comments.
Author:
Julio Vilmar Gesser
See Also:
BlockComment, LineComment, JavadocComment
  • Constructor Details

    • Comment

      public Comment(String content)
    • Comment

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

    • getContent

      public String getContent()
      Return the text of the comment.
      Returns:
      text of the comment
    • setContent

      public Comment setContent(String content)
      Sets the text of the comment.
      Parameters:
      content - the text of the comment to set
    • isLineComment

      public boolean isLineComment()
    • asLineComment

      public LineComment asLineComment()
    • getCommentedNode

      public Optional<Node> getCommentedNode()
    • setCommentedNode

      public Comment setCommentedNode(Node commentedNode)
      Sets the commentedNode
      Parameters:
      commentedNode - the commentedNode, can be null
      Returns:
      this, the Comment
    • isOrphan

      public boolean isOrphan()
    • setComment

      public Node setComment(Comment comment)
      Description copied from class: Node
      Use this to store additional information to this node.
      Overrides:
      setComment in class Node
      Parameters:
      comment - to be set
    • remove

      public boolean remove()
      Description copied from class: Node
      Try to remove this node from the parent
      Overrides:
      remove in class Node
      Returns:
      true if removed, false if it is a required property of the parent, or if the parent isn't set.
    • findRootNode

      public Node findRootNode()
      Description copied from class: Node
      Finds the root node of this AST by finding the topmost parent.
      Overrides:
      findRootNode in class Node
    • clone

      public Comment clone()
      Overrides:
      clone in class Node
    • getMetaModel

      public CommentMetaModel getMetaModel()
      Overrides:
      getMetaModel in class Node
      Returns:
      get JavaParser specific node introspection information.
    • isBlockComment

      public boolean isBlockComment()
    • asBlockComment

      public BlockComment asBlockComment()
    • isJavadocComment

      public boolean isJavadocComment()
    • asJavadocComment

      public JavadocComment asJavadocComment()
    • ifBlockComment

      public void ifBlockComment(Consumer<BlockComment> action)
    • ifJavadocComment

      public void ifJavadocComment(Consumer<JavadocComment> action)
    • ifLineComment

      public void ifLineComment(Consumer<LineComment> action)
    • toBlockComment

      public Optional<BlockComment> toBlockComment()
    • toJavadocComment

      public Optional<JavadocComment> toJavadocComment()
    • toLineComment

      public Optional<LineComment> toLineComment()