Class CmtNode
- java.lang.Object
-
- ru.vyarus.yaml.updater.parse.common.model.TreeNode<T>
-
- ru.vyarus.yaml.updater.parse.common.model.YamlLine<CmtNode>
-
- ru.vyarus.yaml.updater.parse.comments.model.CmtNode
-
- All Implemented Interfaces:
LineNumberAware
public class CmtNode extends YamlLine<CmtNode>
One or multiple lines in yaml file. Usually represent property (something: val), its value and comment. Everything before property that is not a property assumed to be its comment (important to recover comments as-is; actually it doesn't matter what property they belong actually, it's important to not change structure).If there are only comment lines at the end of yaml file then special node would be used: comment without property.
For lists, parsed structure is a bit weird for objects: dashed property goes first and later object properties are children of this value (so item object become split, but this simplifies parsing (node always one or more lines)).
Value part for properties is parsed as-is, preserving possible in-line comments. For multi-line values, exact lines would be stored (easier re-build file exactly as it was).
- Since:
- 22.04.2021
-
-
Field Summary
-
Fields inherited from class ru.vyarus.yaml.updater.parse.common.model.YamlLine
PATH_SEPARATOR
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetIdentityValue()Returned values assumed to be used in node comparisons.java.lang.StringgetParsedValue()NOTE: such value may not be set if comments parser used directly (e.g. in tests).java.lang.StringgetSourceKey()Original yaml file could contain quoted key, butYamlLine.getKey()would always return unquoted key to avoid comparison mistakes.java.util.List<java.lang.String>getTopComment()NOTE: If multiple comments above property, separated by blank lines - it all would be assumed as property comment (everything is remembered to re-create exactly the same file).java.util.List<java.lang.String>getValue()booleanhasComment()booleanhasValue()booleanisAddedNode()booleanisCommentOnly()voidsetAddedNode(boolean addedNode)Mark node as added during merge process.voidsetKey(java.lang.String key)voidsetParsedValue(java.lang.String parsedValue)Property value, parsed by snakeyaml parser.voidsetSourceKey(java.lang.String sourceKey)Method should be used only to change existing node property style (e.g. quoted to unquoted and vice-versa).voidsetValue(java.util.List<java.lang.String> value)Register property value.java.lang.StringtoString()-
Methods inherited from class ru.vyarus.yaml.updater.parse.common.model.YamlLine
find, getAllPropertiesIncludingScalarLists, getKey, getLineNum, getPadding, getTreeLeaves, getYamlPath, getYamlPathElement, isEmptyDash, isListItem, isListItemWithProperty, isObjectListItem, isProperty, setListItem, setListItemWithProperty, setPadding
-
Methods inherited from class ru.vyarus.yaml.updater.parse.common.model.TreeNode
add, addAll, getChildren, getRoot, getRootProperties, hasChildren, hasListValue, setRoot
-
-
-
-
Constructor Detail
-
CmtNode
public CmtNode(CmtNode root, int padding, int lineNum)
-
-
Method Detail
-
setKey
public void setKey(java.lang.String key)
-
getSourceKey
public java.lang.String getSourceKey()
Original yaml file could contain quoted key, butYamlLine.getKey()would always return unquoted key to avoid comparison mistakes. Use this method to get original key before writing it back to file (method ONLY for correct node writing).- Returns:
- original key representation (quoted, if it was originally quoted in the file)
-
setSourceKey
public void setSourceKey(java.lang.String sourceKey)
Method should be used only to change existing node property style (e.g. quoted to unquoted and vice-versa). Style change is important because target file style must be implied in all possible aspects.- Parameters:
sourceKey- new property representation in file
-
getValue
public java.util.List<java.lang.String> getValue()
- Returns:
- property value (multiple lines for multi-line values) or empty list
-
setValue
public void setValue(java.util.List<java.lang.String> value)
Register property value.- Parameters:
value- property value
-
getTopComment
public java.util.List<java.lang.String> getTopComment()
NOTE: If multiple comments above property, separated by blank lines - it all would be assumed as property comment (everything is remembered to re-create exactly the same file).- Returns:
- comment (multiple lines) above property or empty list if no comment
-
getParsedValue
public java.lang.String getParsedValue()
NOTE: such value may not be set if comments parser used directly (e.g. in tests).- Returns:
- value from snakeyaml parser or null
-
setParsedValue
public void setParsedValue(java.lang.String parsedValue)
Property value, parsed by snakeyaml parser. Used for list items matching (seegetIdentityValue()).- Parameters:
parsedValue- value from snakeyaml parser
-
hasComment
public boolean hasComment()
- Returns:
- true if property has comment above
-
isCommentOnly
public boolean isCommentOnly()
- Returns:
- true if node contains only comment without property (trailing file or subtree comment)
-
hasValue
public boolean hasValue()
- Returns:
- true if property has non empty value
-
getIdentityValue
public java.lang.String getIdentityValue()
Description copied from class:YamlLineReturned values assumed to be used in node comparisons.- Specified by:
getIdentityValuein classYamlLine<CmtNode>- Returns:
- maximally accurate node value (as much as possible for used parser)
-
setAddedNode
public void setAddedNode(boolean addedNode)
Mark node as added during merge process.- Parameters:
addedNode- true to mark node as added
-
isAddedNode
public boolean isAddedNode()
- Returns:
- true indicates added node during merge process (including lists update)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-