Class 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
    • Constructor Detail

      • CmtNode

        public CmtNode​(CmtNode root,
                       int padding,
                       int lineNum)
    • Method Detail

      • setKey

        public void setKey​(java.lang.String key)
        Overrides:
        setKey in class YamlLine<CmtNode>
        Parameters:
        key - property name
      • getSourceKey

        public java.lang.String getSourceKey()
        Original yaml file could contain quoted key, but YamlLine.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 (see getIdentityValue()).
        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: YamlLine
        Returned values assumed to be used in node comparisons.
        Specified by:
        getIdentityValue in class YamlLine<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:
        toString in class java.lang.Object