public class Comments extends Object
blocks.
Please note that the methods provided here support all implemented positions by the engine
as defined by the YAML spec.
However, when dumping the document, depending on the
flow style currently
in use, comments at some positions will be lost. That is a limitation imposed by the engine and might be patched in
future releases. Always refer to the corresponding position documentation for detailed information regarding these
requirements and compatibility notes.
| Modifier and Type | Class and Description |
|---|---|
static class |
Comments.NodeType
Deprecated.
Use
NodeRole instead. |
static class |
Comments.Position
Comment position relative to the key/value node.
|
| 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)
Deprecated.
Replaced by
add(Block, NodeRole, Position, CommentLine) and subject for removal. |
static void |
add(Block<?> block,
Comments.NodeType node,
Comments.Position position,
List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
Deprecated.
Replaced by
add(Block, NodeRole, Position, List) and subject for removal. |
static void |
add(Block<?> block,
NodeRole 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,
NodeRole 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)
Deprecated.
Replaced by
get(Block, NodeRole, Position) and subject for removal. |
static List<org.snakeyaml.engine.v2.comments.CommentLine> |
get(Block<?> block,
NodeRole node,
Comments.Position position)
Returns comments at the given position.
|
static void |
remove(Block<?> block,
Comments.NodeType node,
Comments.Position position)
Deprecated.
Replaced by
remove(Block, NodeRole, Position) and subject for removal. |
static void |
remove(Block<?> block,
NodeRole 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)
Deprecated.
Replaced by
set(Block, NodeRole, Position, List) and subject for removal. |
static void |
set(Block<?> block,
NodeRole 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
Comments.Position.INLINE.@Nullable public static List<org.snakeyaml.engine.v2.comments.CommentLine> get(@NotNull Block<?> block, @NotNull NodeRole node, @NotNull Comments.Position position)
This method will return null or an empty List, indicating there are no comments at the
position.
The returned list can be modified with changes reflected in the document tree immediately. Please note that
not all comment types are allowed at all positions. Always refer to the Comments.Position documentation when
managing comments in order to avoid content loss and runtime exceptions.
block - the block used to retrieve commentsnode - node from which to retrieve commentsposition - position of the retrieved comments@Deprecated @Nullable public static List<org.snakeyaml.engine.v2.comments.CommentLine> get(@NotNull Block<?> block, @NotNull Comments.NodeType node, @NotNull Comments.Position position)
get(Block, NodeRole, Position) and subject for removal.
This method will return null or an empty List, indicating there are no comments at the
position.
The returned list can be modified with changes reflected in the document tree immediately. Please note that
not all comment types are allowed at all positions. Always refer to the Comments.Position documentation when
managing comments in order to avoid content loss and runtime exceptions.
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
NodeRole 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.
Setting a list returned by get(Block, NodeType, Position) is not necessary as the changes made to that
list are automatically reflected in the document structure.
Please note that not all comment types are allowed at all positions. Always refer to the Comments.Position
documentation when managing comments in order to avoid content loss and runtime exceptions.
block - the block for which to setnode - node to attach toposition - position at which to setcomments - the comments to setcreate(String, Position)@Deprecated public static void set(@NotNull Block<?> block, @NotNull Comments.NodeType node, @NotNull Comments.Position position, @Nullable List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
set(Block, NodeRole, Position, List) and subject for removal.
To remove comments, use remove(Block, NodeType, Position) instead. Alternatively, pass either
null or an empty List as the parameter.
Setting a list returned by get(Block, NodeType, Position) is not necessary as the changes made to that
list are automatically reflected in the document structure.
Please note that not all comment types are allowed at all positions. Always refer to the Comments.Position
documentation when managing comments in order to avoid content loss and runtime exceptions.
block - the block for which to setnode - node to attach toposition - position at which to setcomments - the comments to setcreate(String, Position)public static void remove(@NotNull
Block<?> block,
@NotNull
NodeRole node,
@NotNull
Comments.Position position)
block - the block for which to removenode - node to which the comments are attachedposition - position of the comments to remove@Deprecated public static void remove(@NotNull Block<?> block, @NotNull Comments.NodeType node, @NotNull Comments.Position position)
remove(Block, NodeRole, Position) and subject for removal.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
NodeRole node,
@NotNull
Comments.Position position,
@NotNull
List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
Please note that not all comment types are allowed at all positions. Always refer to the Comments.Position
documentation when managing comments in order to avoid content loss and runtime exceptions.
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 addcreate(String, Position)@Deprecated public static void add(@NotNull Block<?> block, @NotNull Comments.NodeType node, @NotNull Comments.Position position, @NotNull List<org.snakeyaml.engine.v2.comments.CommentLine> comments)
add(Block, NodeRole, Position, List) and subject for removal.
Please note that not all comment types are allowed at all positions. Always refer to the Comments.Position
documentation when managing comments in order to avoid content loss and runtime exceptions.
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 addcreate(String, Position)public static void add(@NotNull
Block<?> block,
@NotNull
NodeRole node,
@NotNull
Comments.Position position,
@NotNull
org.snakeyaml.engine.v2.comments.CommentLine comment)
Please note that not all comment types are allowed at all positions. Always refer to the Comments.Position
documentation when managing comments in order to avoid content loss and runtime exceptions.
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 addcreate(String, Position)@Deprecated public static void add(@NotNull Block<?> block, @NotNull Comments.NodeType node, @NotNull Comments.Position position, @NotNull org.snakeyaml.engine.v2.comments.CommentLine comment)
add(Block, NodeRole, Position, CommentLine) and subject for removal.
Please note that not all comment types are allowed at all positions. Always refer to the Comments.Position
documentation when managing comments in order to avoid content loss and runtime exceptions.
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 addcreate(String, Position)@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 © 2024. All rights reserved.