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>
,java.lang.Cloneable
- Direct Known Subclasses:
BlockComment
,JavadocComment
,LineComment
public abstract class Comment extends Node
Abstract class for all AST nodes that represent comments.- See Also:
BlockComment
,LineComment
,JavadocComment
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.javaparser.ast.Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
-
-
Field Summary
Fields Modifier and Type Field Description private Node
commentedNode
private java.lang.String
content
-
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, NODE_BY_BEGIN_POSITION, prettyPrinterNoCommentsConfiguration, SYMBOL_RESOLVER_KEY
-
-
Constructor Summary
Constructors Constructor Description Comment(TokenRange tokenRange, java.lang.String content)
This constructor is used by the parser and is considered private.Comment(java.lang.String content)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BlockComment
asBlockComment()
JavadocComment
asJavadocComment()
LineComment
asLineComment()
Comment
clone()
Node
findRootNode()
Finds the root node of this AST by finding the topmost parent.java.util.Optional<Node>
getCommentedNode()
java.lang.String
getContent()
Return the text of the comment.CommentMetaModel
getMetaModel()
void
ifBlockComment(java.util.function.Consumer<BlockComment> action)
void
ifJavadocComment(java.util.function.Consumer<JavadocComment> action)
void
ifLineComment(java.util.function.Consumer<LineComment> action)
boolean
isBlockComment()
boolean
isJavadocComment()
boolean
isLineComment()
boolean
isOrphan()
boolean
remove()
Try to remove this node from the parentboolean
remove(Node node)
boolean
replace(Node node, Node replacementNode)
Node
setComment(Comment comment)
Use this to store additional information to this node.Comment
setCommentedNode(Node commentedNode)
Sets the commentedNodeComment
setContent(java.lang.String content)
Sets the text of the comment.java.util.Optional<BlockComment>
toBlockComment()
java.util.Optional<JavadocComment>
toJavadocComment()
java.util.Optional<LineComment>
toLineComment()
-
Methods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, customInitialization, equals, findAll, findAll, findCompilationUnit, findFirst, findFirst, findFirst, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getRange, getSymbolResolver, getTokenRange, getToStringPrettyPrinterConfiguration, hashCode, isAncestorOf, isRegistered, notifyPropertyChange, register, register, registerForSubtree, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, setToStringPrettyPrinterConfiguration, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walk
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, isDescendantOf
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd
-
-
-
-
Field Detail
-
content
private java.lang.String content
-
commentedNode
private Node commentedNode
-
-
Constructor Detail
-
Comment
public Comment(java.lang.String content)
-
Comment
public Comment(TokenRange tokenRange, java.lang.String content)
This constructor is used by the parser and is considered private.
-
-
Method Detail
-
getContent
public java.lang.String getContent()
Return the text of the comment.- Returns:
- text of the comment
-
setContent
public Comment setContent(java.lang.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 java.util.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 classNode
- Parameters:
comment
- to be set
-
remove
public boolean remove()
Description copied from class:Node
Try to remove this node from the parent
-
findRootNode
public Node findRootNode()
Description copied from class:Node
Finds the root node of this AST by finding the topmost parent.- Overrides:
findRootNode
in classNode
-
getMetaModel
public CommentMetaModel getMetaModel()
- Overrides:
getMetaModel
in classNode
- 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(java.util.function.Consumer<BlockComment> action)
-
ifJavadocComment
public void ifJavadocComment(java.util.function.Consumer<JavadocComment> action)
-
ifLineComment
public void ifLineComment(java.util.function.Consumer<LineComment> action)
-
toBlockComment
public java.util.Optional<BlockComment> toBlockComment()
-
toJavadocComment
public java.util.Optional<JavadocComment> toJavadocComment()
-
toLineComment
public java.util.Optional<LineComment> toLineComment()
-
-