Top Description Fields Constructors Methods
com.github.javaparser.ast.comments

public abstract Class Comment

extends Node
Class Inheritance
Known Direct Subclasses
com.github.javaparser.ast.comments.JavadocComment, com.github.javaparser.ast.comments.LineComment, com.github.javaparser.ast.comments.BlockComment
Imports
com.github.javaparser.ast.AllFieldsConstructor, .Node, .Generated, com.github.javaparser.ast.observer.ObservableProperty, java.util.Optional, com.github.javaparser.ast.visitor.CloneVisitor, com.github.javaparser.metamodel.CommentMetaModel, .InternalProperty, .JavaParserMetaModel, com.github.javaparser.TokenRange, java.util.function.Consumer

Abstract class for all AST nodes that represent comments.
Author
Julio Vilmar Gesser
See Also
BlockComment, LineComment, JavadocComment

Field Summary

Modifier and TypeField and Description
private Node
private String
Inherited from com.github.javaparser.ast.Node:
ABSOLUTE_BEGIN_LINEABSOLUTE_END_LINENODE_BY_BEGIN_POSITIONprettyPrinterNoCommentsConfigurationSYMBOL_RESOLVER_KEY

Constructor Summary

AccessConstructor and Description
public
Comment(String content)

public
Comment(TokenRange tokenRange, String content)

This constructor is used by the parser and is considered private.

Method Summary

Modifier and TypeMethod and Description
public BlockComment
public JavadocComment
public LineComment
public Comment
clone()

Overrides com.github.javaparser.ast.Node.clone.

Creates and returns a copy of this object.
public Node
findRootNode()

Overrides com.github.javaparser.ast.Node.findRootNode.

Finds the root node of this AST by finding the topmost parent.
public Optional<Node>
public String

Returns:

text of the comment
getContent
()

Return the text of the comment.

public CommentMetaModel
public void
public void
public void
public boolean
public boolean
public boolean
public boolean
public boolean
remove()

Overrides com.github.javaparser.ast.Node.remove.

Try to remove this node from the parent
public boolean
public boolean
replace(Node node, Node replacementNode)

Overrides com.github.javaparser.ast.Node.replace.

public Node
setComment(final Comment
to be set
comment
)

Overrides com.github.javaparser.ast.Node.setComment.

Use this to store additional information to this node.
public Comment

Returns:

this, the Comment
setCommentedNode
(Node
the commentedNode, can be null
commentedNode
)

Sets the commentedNode

public Comment
setContent(final String
the text of the comment to set
content
)

Sets the text of the comment.

public Optional<BlockComment>
public Optional<JavadocComment>
public Optional<LineComment>
Inherited from com.github.javaparser.ast.Node:
addOrphanCommentcontainsDatacustomInitializationequalsfindAllfindAllfindCompilationUnitfindFirstfindFirstfindFirstgetAllContainedCommentsgetChildNodesgetChildNodesByTypegetCommentgetDatagetDataKeysgetNodesByTypegetOrphanCommentsgetParentNodegetParentNodeForChildrengetParsedgetRangegetSymbolResolvergetTokenRangegetToStringPrettyPrinterConfigurationhashCodeisAncestorOfisRegisterednotifyPropertyChangeregisterregisterregisterForSubtreeremoveCommentremoveDataremoveForcedremoveOrphanCommentreplacesetAsParentNodeOfsetAsParentNodeOfsetBlockCommentsetDatasetLineCommentsetParentNodesetParsedsetRangesetTokenRangesetToStringPrettyPrinterConfigurationstreamstreamtoStringtoStringtryAddImportToParentCompilationUnitunregisterwalkwalkwalk

Field Detail

commentedNodeback to summary
private Node commentedNode
Annotations
@InternalProperty
contentback to summary
private String content

Constructor Detail

Commentback to summary
public Comment(String content)
Annotations
@AllFieldsConstructor
Commentback to summary
public Comment(TokenRange tokenRange, String content)

This constructor is used by the parser and is considered private.

Annotations
@Generated:com.github.javaparser.generator.core.node.MainConstructorGenerator

Method Detail

asBlockCommentback to summary
public BlockComment asBlockComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
asJavadocCommentback to summary
public JavadocComment asJavadocComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
asLineCommentback to summary
public LineComment asLineComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
cloneback to summary
public Comment clone()

Overrides com.github.javaparser.ast.Node.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Comment

a clone of this instance.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.CloneGenerator
findRootNodeback to summary
public Node findRootNode()

Overrides com.github.javaparser.ast.Node.findRootNode.

Doc from com.github.javaparser.ast.Node.findRootNode.

Finds the root node of this AST by finding the topmost parent.

Annotations
@Override
getCommentedNodeback to summary
public Optional<Node> getCommentedNode()
getContentback to summary
public String getContent()

Return the text of the comment.

Returns:String

text of the comment

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
getMetaModelback to summary
public CommentMetaModel getMetaModel()

Overrides com.github.javaparser.ast.Node.getMetaModel.

Returns:CommentMetaModel

Doc from com.github.javaparser.ast.Node.getMetaModel.

get JavaParser specific node introspection information.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.GetMetaModelGenerator
ifBlockCommentback to summary
public void ifBlockComment(Consumer<BlockComment> action)
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
ifJavadocCommentback to summary
public void ifJavadocComment(Consumer<JavadocComment> action)
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
ifLineCommentback to summary
public void ifLineComment(Consumer<LineComment> action)
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
isBlockCommentback to summary
public boolean isBlockComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
isJavadocCommentback to summary
public boolean isJavadocComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
isLineCommentback to summary
public boolean isLineComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
isOrphanback to summary
public boolean isOrphan()
removeback to summary
public boolean remove()

Overrides com.github.javaparser.ast.Node.remove.

Doc from com.github.javaparser.ast.Node.remove.

Try to remove this node from the parent

Returns:boolean

true if removed, false if it is a required property of the parent, or if the parent isn't set.

Annotations
@Override
removeback to summary
public boolean remove(Node node)

Overrides com.github.javaparser.ast.Node.remove.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.RemoveMethodGenerator
replaceback to summary
public boolean replace(Node node, Node replacementNode)

Overrides com.github.javaparser.ast.Node.replace.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.ReplaceMethodGenerator
setCommentback to summary
public Node setComment(final Comment comment)

Overrides com.github.javaparser.ast.Node.setComment.

Doc from com.github.javaparser.ast.Node.setComment.

Use this to store additional information to this node.

Parameters
comment:Comment

to be set

Annotations
@Override
setCommentedNodeback to summary
public Comment setCommentedNode(Node commentedNode)

Sets the commentedNode

Parameters
commentedNode:Node

the commentedNode, can be null

Returns:Comment

this, the Comment

setContentback to summary
public Comment setContent(final String content)

Sets the text of the comment.

Parameters
content:String

the text of the comment to set

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
toBlockCommentback to summary
public Optional<BlockComment> toBlockComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
toJavadocCommentback to summary
public Optional<JavadocComment> toJavadocComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
toLineCommentback to summary
public Optional<LineComment> toLineComment()
Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator