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 Details

    • 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
    • asStream

      default NodeStream<N> asStream()
      Description copied from interface: Node
      Returns a node stream containing only this node. NodeStream.of(Node) is a null-safe version of this method.
      Specified by:
      asStream in interface Node
      Returns:
      A node stream containing only this node
      See Also:
    • children

      default NodeStream<N> children()
      Description copied from interface: Node
      Returns a node stream containing all the children of this node. This method does not provide much type safety, you'll probably want to use Node.children(Class).
      Specified by:
      children in interface Node
      See Also:
    • descendants

      default NodeStream.DescendantNodeStream<N> descendants()
      Description copied from interface: Node
      Returns a node stream containing all the descendants of this node. See NodeStream.DescendantNodeStream for details.
      Specified by:
      descendants in interface Node
      Returns:
      A node stream of the descendants of this node
      See Also:
    • descendantsOrSelf

      default NodeStream.DescendantNodeStream<N> descendantsOrSelf()
      Description copied from interface: Node
      Returns a node stream containing this node, then all its descendants. See NodeStream.DescendantNodeStream for details.
      Specified by:
      descendantsOrSelf in interface Node
      Returns:
      A node stream of the whole subtree topped by this node
      See Also:
    • 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:
    • 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:
    • 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