public class Comments extends Object
blocks, providing additional methods on top of those already provided by Block.
Please note that the methods provided here add possibilities for all implemented positions.
However, using positions other than Comments.Position.BEFORE might lead to comment de-alignment and errors. Please
read more information at the enum constants.
| Modifier and Type | Class and Description |
|---|---|
static class |
Comments.NodeType
Represents to which node the comments are attached in a mapping.
|
static class |
Comments.Position
Comment position relative to the node (scalar; see
Comments.NodeType) to which the comment is attached. |
| Modifier and Type | Field and Description |
|---|---|
static org.snakeyaml.engine.v2.comments.CommentLine |
BLANK_LINE
Comment representing a blank line.
|
| Constructor and Description |
|---|
Comments() |
| Modifier and Type | Method and Description |
|---|---|
static void |
add(Block<?> block,
Comments.NodeType node,
Comments.Position position,
org.snakeyaml.engine.v2.comments.CommentLine comment)
Adds the given comment to already existing comments at the given position.
|
static void |
add(Block<?> block,
Comments.NodeType node,
Comments.Position position,
List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
Adds the given comments to already existing comments at the given position.
|
static org.snakeyaml.engine.v2.comments.CommentLine |
create(String comment,
Comments.Position position)
Creates a comment.
|
static List<org.snakeyaml.engine.v2.comments.CommentLine> |
get(Block<?> block,
Comments.NodeType node,
Comments.Position position)
Returns comments at the given position.
|
static void |
remove(Block<?> block,
Comments.NodeType node,
Comments.Position position)
Removes all comments at the given position.
|
static void |
set(Block<?> block,
Comments.NodeType node,
Comments.Position position,
List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
Sets the given comments at the given position.
|
public static final org.snakeyaml.engine.v2.comments.CommentLine BLANK_LINE
@Nullable public static List<org.snakeyaml.engine.v2.comments.CommentLine> get(@NotNull Block<?> block, @NotNull Comments.NodeType node, @NotNull Comments.Position position)
Please expect null or an empty List, representing there are no comments at the position.
block - the block used to retrieve commentsnode - node from which to retrieve commentsposition - position of the retrieved commentspublic static void set(@NotNull
Block<?> block,
@NotNull
Comments.NodeType node,
@NotNull
Comments.Position position,
@Nullable
List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
To remove comments, use remove(Block, NodeType, Position) instead. Alternatively, pass either
null or an empty List as the parameter.
block - the block for which to setnode - node to attach toposition - position at which to setcomments - the comments to setpublic static void remove(@NotNull
Block<?> block,
@NotNull
Comments.NodeType node,
@NotNull
Comments.Position position)
block - the block for which to removenode - node to which the comments are attachedposition - position of the comments to removepublic static void add(@NotNull
Block<?> block,
@NotNull
Comments.NodeType node,
@NotNull
Comments.Position position,
@NotNull
List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
block - the block to add tonode - node to which the comments should be addedposition - position at which the comments should be addedcomments - the comments to addpublic static void add(@NotNull
Block<?> block,
@NotNull
Comments.NodeType node,
@NotNull
Comments.Position position,
@NotNull
org.snakeyaml.engine.v2.comments.CommentLine comment)
block - the block to add tonode - node to which the comments should be addedposition - position at which the comments should be addedcomment - the comment to add@NotNull
public static org.snakeyaml.engine.v2.comments.CommentLine create(@NotNull
String comment,
@NotNull
Comments.Position position)
BLANK_LINE.comment - the actual commentposition - position at which the block will be placedCopyright © 2022. All rights reserved.