Interface ASTNode

    • Method Detail

      • getParent

        ASTNode getParent()
        Gets the parent node in the AST tree.
        Returns:
        the parent node, or null if this is a root node
      • setParent

        void setParent​(ASTNode parent)
        Sets the parent node in the AST tree.
        Parameters:
        parent - the parent node
      • getLocation

        SourceLocation getLocation()
        Gets the source location of this node.
        Returns:
        the source location
      • accept

        <T> T accept​(SourceVisitor<T> visitor)
        Accepts a visitor for this node.
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor
      • releaseFormerChild

        static void releaseFormerChild​(ASTNode formerChild,
                                       ASTNode parent)
        Clears the parent of a node that parent no longer holds.
        Parameters:
        formerChild - the node the parent used to hold, may be null
        parent - the node that replaced it
      • getChildren

        default List<ASTNode> getChildren()
        Lists the direct children a node holds, in source order.
        Returns:
        the direct children, empty for a leaf
      • walk

        default void walk​(Consumer<ASTNode> visitor)
        Walks the entire subtree rooted at this node in pre-order (parent first), calling the visitor on each node.
        Parameters:
        visitor - the consumer to call on each node
      • findFirst

        default <T extends ASTNodeOptional<T> findFirst​(Class<T> type)
        Finds the first descendant of the specified type.
        Type Parameters:
        T - the type of node to find
        Parameters:
        type - the class of the node to find
        Returns:
        an Optional containing the first matching node, or empty if not found
      • findFirst

        default <T extends ASTNodeOptional<T> findFirst​(Class<T> type,
                                                          Predicate<T> predicate)
        Finds the first descendant of the specified type matching the predicate.
        Type Parameters:
        T - the type of node to find
        Parameters:
        type - the class of the node to find
        predicate - the condition the node must satisfy
        Returns:
        an Optional containing the first matching node, or empty if not found
      • findAll

        default <T extends ASTNodeList<T> findAll​(Class<T> type)
        Finds all descendants of the specified type.
        Type Parameters:
        T - the type of nodes to find
        Parameters:
        type - the class of the nodes to find
        Returns:
        a list of all matching nodes
      • findAll

        default <T extends ASTNodeList<T> findAll​(Class<T> type,
                                                    Predicate<T> predicate)
        Finds all descendants of the specified type matching the predicate.
        Type Parameters:
        T - the type of nodes to find
        Parameters:
        type - the class of the nodes to find
        predicate - the condition the nodes must satisfy
        Returns:
        a list of all matching nodes
      • stream

        default Stream<ASTNode> stream()
        Returns a stream of all nodes in this subtree (including this node).
        Returns:
        a stream of all descendant nodes
      • stream

        default <T extends ASTNodeStream<T> stream​(Class<T> type)
        Returns a stream of all nodes of the specified type in this subtree.
        Type Parameters:
        T - the type of nodes to stream
        Parameters:
        type - the class of nodes to include
        Returns:
        a stream of matching nodes
      • findAncestor

        default <T extends ASTNodeOptional<T> findAncestor​(Class<T> type)
        Finds the first ancestor of the specified type.
        Type Parameters:
        T - the type of ancestor to find
        Parameters:
        type - the class of the ancestor to find
        Returns:
        an Optional containing the first matching ancestor, or empty if not found
      • isDescendantOf

        default boolean isDescendantOf​(ASTNode ancestor)
        Checks if this node is a descendant of the specified ancestor.
        Parameters:
        ancestor - the potential ancestor node
        Returns:
        true if this node is a descendant of the ancestor
      • getRoot

        default ASTNode getRoot()
        Gets the root of the AST tree containing this node.
        Returns:
        the root node (the topmost parent)
      • deepClone

        default ASTNode deepClone()
        Creates a deep clone of this node and its entire subtree.
        Returns:
        a deep copy of this node
      • replaceWith

        default boolean replaceWith​(ASTNode replacement)
        Replaces this node in its parent with a new node.
        Parameters:
        replacement - the node to replace this with
        Returns:
        true if replacement was successful
      • remove

        default boolean remove()
        Removes this node from its parent.
        Returns:
        true if removal was successful