@@ -887,6 +887,40 @@ public DiffNode<L> shallowCopy() {
887887 );
888888 }
889889
890+ /**
891+ * Turns this node into a node with {@link DiffType} {@link DiffType#NON}.
892+ * To retain consistency of the variation diff, this node will also ensure that this
893+ * node will have a parent at all times.
894+ * To this end, the parent of this node will also be made unchanged if necessary, potentially
895+ * making some or all ancestors of this node unchanged recursively.
896+ * This method has no effect when this node is already unchanged.
897+ */
898+ public void makeUnchanged () {
899+ if (isNon ()) return ;
900+
901+ this .diffType = DiffType .NON ;
902+
903+ final DiffNode <L > bp = at (Time .BEFORE ).parent ;
904+ final DiffNode <L > ap = at (Time .AFTER ).parent ;
905+
906+ // If we have a parent before the change and after the change, making this node unchanged is fine.
907+ // Otherwise, if at least one parent is null, we have to set the other parent and make our parent unchanged as well.
908+ if (bp == null || ap == null ) {
909+ // There is only one parent, which we store in this field.
910+ final DiffNode <L > p = bp == null ? ap : bp ;
911+ Assert .assertTrue (p != null );
912+
913+ // If the parent is not unchanged, we have to make it unchanged so that it can be our
914+ // parent at all times.
915+ if (!p .isNon ()) {
916+ p .makeUnchanged ();
917+ }
918+
919+ // Now make p our parent at all times, not just at a single time.
920+ Time .forAll (t -> at (t ).parent = p );
921+ }
922+ }
923+
890924 /**
891925 * Transforms a {@code VariationNode} into a {@code DiffNode} by diffing {@code variationNode}
892926 * to itself. Recursively translates all children.
0 commit comments