Interface Node

All Superinterfaces:
Comparable<Node>
All Known Implementing Classes:
BaseNode, ByteArrayNBT, CompoundNBT, Delimiter, IntArrayNBT, InvalidToken, KeyValuePair, ListNBT, Literal, Root, Token, Value, WHITESPACE

public interface Node extends Comparable<Node>
  • Method Details

    • open

      default void open()
      Life-cycle hook method called after the node has been made the current node
    • close

      default void close()
      Life-cycle hook method called after all the child nodes have been added.
    • getInputSource

      default String getInputSource()
      Returns:
      the input source (usually a filename) from which this Node came from
    • hasChildNodes

      default boolean hasChildNodes()
      Returns whether this node has any children.
      Returns:
      Returns true if this node has any children, false otherwise.
    • setParent

      void setParent(Node n)
      Parameters:
      n - The Node to set as the parent. Mostly used internally. The various addChild or appendChild sorts of methods should use this to set the node's parent.
    • getParent

      Node getParent()
      Returns:
      this node's parent Node
    • addChild

      void addChild(Node n)
      appends a child node to this Node
      Parameters:
      n - the Node to append
    • addChild

      void addChild(int i, Node n)
      inserts a child Node at a specific index, displacing the nodes after the index by 1.
      Parameters:
      i - the (zero-based) index at which to insert the node
      n - the Node to insert
    • getChild

      Node getChild(int i)
      Parameters:
      i - the index of the Node to return
      Returns:
      the Node at the specific offset
    • setChild

      void setChild(int i, Node n)
      Replace the node at index i
      Parameters:
      i - the index
      n - the node
    • removeChild

      Node removeChild(int i)
      Remove the node at index i. Any Nodes after i are shifted to the left.
      Parameters:
      i - the index at which to remove
      Returns:
      the removed Node
    • removeChild

      default boolean removeChild(Node n)
      Removes the Node from this node's children
      Parameters:
      n - the Node to remove
      Returns:
      whether the Node was present
    • replaceChild

      default boolean replaceChild(Node current, Node replacement)
      Replaces a child node with another one. It does nothing if the first parameter is not actually a child node.
      Parameters:
      current - the Node to be replaced
      replacement - the Node to substitute
      Returns:
      whether any replacement took place
    • prependChild

      default boolean prependChild(Node where, Node inserted)
      Insert a Node right before a given Node. It does nothing if the where Node is not actually a child node.
      Parameters:
      where - the Node that is the location where to prepend
      inserted - the Node to prepend
      Returns:
      whether a Node was prepended
    • appendChild

      default boolean appendChild(Node where, Node inserted)
      Insert a node right after a given Node. It does nothing if the where node is not actually a child node.
      Parameters:
      where - the Node after which to append
      inserted - the Node to be inserted
      Returns:
      whether a Node really was appended
    • indexOf

      default int indexOf(Node child)
      Parameters:
      child - the Node to get the index of
      Returns:
      the index of the child Node. Or -1 if it is not a child Node.
    • previousSibling

      default Node previousSibling()
    • nextSibling

      default Node nextSibling()
    • compareTo

      default int compareTo(Node n)
      Used to order Nodes by location.
      Specified by:
      compareTo in interface Comparable<Node>
      Parameters:
      n - the Node to compare to
      Returns:
      typical Comparator semantics
    • clearChildren

      void clearChildren()
      Remove all the child nodes
    • getChildCount

      int getChildCount()
      Returns:
      the number of child nodes
    • children

      default List<Node> children(boolean includeUnparsedTokens)
      Returns:
      a List containing this node's child nodes The default implementation returns a copy, so modifying the list that is returned has no effect on this object. Most implementations of this should similarly return a copy or possibly immutable wrapper around the list.
    • children

      default List<Node> children()
    • getAllTokens

      default List<Token> getAllTokens(boolean includeCommentTokens)
      Parameters:
      includeCommentTokens - Whether to include comment tokens
      Returns:
      a List containing all the tokens in a Node
    • getRealTokens

      default List<Token> getRealTokens()
      Returns:
      All the tokens in the node that are "real" (i.e. participate in parsing)
    • getTokenSource

      SNBTLexer getTokenSource()
      Returns:
      the #SNBTLexer from which this Node object originated. There is no guarantee that this doesn't return null. Most likely that would simply be because you constructed the Node yourself, i.e. it didn't really come about via the parsing/tokenizing machinery.
    • setTokenSource

      void setTokenSource(SNBTLexer tokenSource)
    • getSource

      default String getSource()
      Returns:
      the original source content this Node came from a reference to the #SNBTLexer that stores the source code and the start/end location info stored in the Node object itself. This method could throw a NullPointerException if #getTokenSource returns null. Also, the return value could be spurious if the content of the source file was changed meanwhile. But this is just the default implementation of an API and it does not address this problem!
    • getLength

      default int getLength()
    • getBeginLine

      default int getBeginLine()
      Returns:
      the (1-based) line location where this Node starts
    • getEndLine

      default int getEndLine()
      Returns:
      the (1-based) line location where this Node ends
    • getBeginColumn

      default int getBeginColumn()
      Returns:
      the (1-based) column where this Node starts
    • getEndColumn

      default int getEndColumn()
      Returns:
      the (1-based) column offset where this Node ends
    • getBeginOffset

      int getBeginOffset()
      Returns:
      the offset in the input source where the token begins, expressed in code units.
    • getEndOffset

      int getEndOffset()
      Returns:
      the offset in the input source where the token ends, expressed in code units. This is actually the offset where the very next token would begin.
    • setBeginOffset

      void setBeginOffset(int beginOffset)
      Set the offset where the token begins, expressed in code units.
    • setEndOffset

      void setEndOffset(int endOffet)
      Set the offset where the token ends, actually the location where the very next token should begin.
    • getLocation

      default String getLocation()
      Returns:
      a String that gives the starting location of this Node. This is a default implementation that could be overridden
    • isUnparsed

      default boolean isUnparsed()
      Returns:
      whether this Node was created by regular operations of the parsing machinery.
    • setUnparsed

      void setUnparsed(boolean b)
      Mark whether this Node is unparsed, i.e. not the result of normal parsing
      Parameters:
      b - whether to set the Node as unparsed or parsed.
    • firstChildOfType

      default <T extends Node> T firstChildOfType(Class<T> clazz)
    • firstChildOfType

      default <T extends Node> T firstChildOfType(Class<T> clazz, Predicate<T> pred)
    • firstDescendantOfType

      default Token firstDescendantOfType(SNBTConstants.TokenType type)
    • firstChildOfType

      default Token firstChildOfType(SNBTConstants.TokenType tokenType)
    • firstDescendantOfType

      default <T extends Node> T firstDescendantOfType(Class<T> clazz)
    • childrenOfType

      default <T extends Node> List<T> childrenOfType(Class<T> clazz)
    • descendantsOfType

      default <T extends Node> List<T> descendantsOfType(Class<T> clazz)
    • firstAncestorOfType

      default <T extends Node> T firstAncestorOfType(Class<T> clazz)
    • getTokenType

      default SNBTConstants.TokenType getTokenType()
    • getFirstToken

      default Token getFirstToken()
      Returns:
      the very first token that is part of this node. It may be an unparsed (i.e. special) token.
    • getLastToken

      default Token getLastToken()
    • copyLocationInfo

      default void copyLocationInfo(Node from)
      Copy the location info from another Node
      Parameters:
      from - the Node to copy the info from
    • copyLocationInfo

      default void copyLocationInfo(Node start, Node end)
      Copy the location info given a start and end Node
      Parameters:
      start - the start node
      end - the end node
    • replace

      default void replace(Node toBeReplaced)
    • getFirstChild

      default Node getFirstChild()
      Returns the first child of this node. If there is no such node, this returns null.
      Returns:
      the first child of this node. If there is no such node, this returns null.
    • getLastChild

      default Node getLastChild()
      Returns the last child of the given node. If there is no such node, this returns null.
      Returns:
      the last child of the given node. If there is no such node, this returns null.
    • getRoot

      default Node getRoot()
    • getTokens

      static List<Token> getTokens(Node node)
    • getRealTokens

      static List<Token> getRealTokens(Node n)
    • descendants

      default List<Node> descendants()
    • descendants

      default List<Node> descendants(Predicate<? super Node> predicate)
    • descendants

      default <T extends Node> List<T> descendants(Class<T> clazz)
    • descendants

      default <T extends Node> List<T> descendants(Class<T> clazz, Predicate<? super T> predicate)
    • dump

      default void dump(String prefix)
    • dump

      default void dump()
    • iterator

      default ListIterator<Node> iterator()