Class OffsetTreeCursor

  • All Implemented Interfaces:
    AutoCloseable

    public class OffsetTreeCursor
    extends TreeCursor
    Specialization of TreeCursor that applies a positional offset to visited nodes. Retrieving nodes by either getCurrentNode() or getCurrentTreeCursorNode() applies the offset to a copy of the original node, meaning that the tree is not mutated during traversal.

    So what exactly is the purpose of this cursor? Imagine a scenario in which we need to print out the node positions of a source code file that begins with n blank lines. Rather than modifying the original file, we can just use this cursor with a positional offset of new Position(-n, 0). Likewise, when printing node positions of an indented function, the n spaces of indentation can be negated with a positional offset of new Position(0, -n). Row and column offsets can be combined with various positive and negative arrangements.

    Since:
    1.2.0
    Author:
    Ozren Dabić