Interface GenericNode<N extends GenericNode<N>>

  • Type Parameters:
    N - Self type (eg JavaNode)
    All Superinterfaces:
    Node, Reportable
    All Known Subinterfaces:
    AntlrNode<N>, JjtreeNode<N>
    All Known Implementing Classes:
    AbstractJjtreeNode, AbstractNode, BaseAntlrErrorNode, BaseAntlrInnerNode, BaseAntlrNode, BaseAntlrTerminalNode, PlainTextLanguage.PlainTextFile

    public interface GenericNode<N extends GenericNode<N>>
    extends Node
    Interface that binds the return type of some node methods to a type parameter. This enforces that eg all children of such a node are from the same hierarchy (eg Java nodes only have Java nodes as parent, or as children).

    Although subinterfaces like JavaNode profit from the added type information, the Node interface and its usages in language-independent code would suffer from adding a type parameter directly to Node.

    Type safety of the unchecked casts here is the responsibility of the implementation, it should check that methods like setParent or addChild add an instance of <N>.

    • Method Detail

      • getChild

        N getChild​(int index)
        Description copied from interface: Node
        Returns the child of this node at the given index.
        Specified by:
        getChild in interface Node
      • getParent

        N getParent()
        Description copied from interface: Node
        Returns the parent of this node, or null if this is the root of the tree.
        Specified by:
        getParent in interface Node
        Returns:
        The parent of this node
      • getFirstChild

        default @Nullable N getFirstChild()
        Description copied from interface: Node
        Returns the first child of this node, or null if it doesn't exist.
        Specified by:
        getFirstChild in interface Node
      • getLastChild

        default @Nullable N getLastChild()
        Description copied from interface: Node
        Returns the first last of this node, or null if it doesn't exist.
        Specified by:
        getLastChild in interface Node
      • getNthParent

        default N getNthParent​(int n)
        Description copied from interface: Node
        Returns the n-th parent or null if there are less than n ancestors.
        
            getNthParent(1) == jjtGetParent
         
        Specified by:
        getNthParent in interface Node
        Parameters:
        n - how many ancestors to iterate over.
        Returns:
        the n-th parent or null.
      • ancestorsOrSelf

        default NodeStream<N> ancestorsOrSelf()
        Description copied from interface: Node
        Returns a node stream containing this node and its ancestors. The nodes of the returned stream are yielded in a depth-first fashion.
        Specified by:
        ancestorsOrSelf in interface Node
        Returns:
        A stream of ancestors
        See Also:
        NodeStream.ancestorsOrSelf()
      • ancestors

        default NodeStream<N> ancestors()
        Description copied from interface: Node
        Returns a node stream containing all the strict ancestors of this node, in innermost to outermost order. The returned stream doesn't contain this node, and is empty if this node has no parent.
        Specified by:
        ancestors in interface Node
        Returns:
        A node stream of the ancestors of this node
        See Also:
        NodeStream.ancestors()
      • getPreviousSibling

        default @Nullable N getPreviousSibling()
        Description copied from interface: Node
        Returns the previous sibling of this node, or null if it does not exist.
        Specified by:
        getPreviousSibling in interface Node
      • getNextSibling

        default @Nullable N getNextSibling()
        Description copied from interface: Node
        Returns the next sibling of this node, or null if it does not exist.
        Specified by:
        getNextSibling in interface Node