Fix config nodes appearing unpredictably during config update #8123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Newly added nodes during config updating appear in unpredictable ways due to bad design of the Node classes and some bugs in the config updating code.
Solution
Comments are now associated to a SectionNode, SimpleNode or InvalidNode
For config files, comments have been changed to be associated to a section node, simple node or invalid node. This reduces the complexity of updating the config and allows comments to be deleted or changed. They will only be added if the actual node is deleted. Void nodes are now no longer taken into account.
To allow saving of nodes with comments, a new
getAsStrings
method has been added, which serializes the node and its comments to a string format. This allows the node to be added to a config. Since the functionality ofsave(PrintWriter)
does not support this, and to allow developers to use a writer of their own choosing, this method has been deprecated.Fix some problems with adding at a specified index
Due to the previously mentioned complexity of the Node classes, adding a node at an index during the updating process would have an unreliable result. To fix this, a new
addRelative
method has been added, which now adds a Node correctly. Since this requires ignoring void nodes, its behaviour differs fromadd
.Move node parsing to SectionNode.NodeParser
In an attempt to clean up SectionNode, the node parsing logic has been moved to a static nested class. Furthermore, documentation has been added. This is a good setup to allow someone to improve this quite messy code down the line.
Comments now appear before the key of a node
In an attempt to standardize our config format with existing formats, and to reduce the complexity of finding/associating comments, config comments now appear before the key of the node.
Testing Completed
Supporting Information
Completes: #7533
Related: none