Class NodeUtil


  • public class NodeUtil
    extends java.lang.Object
    Common utility functions for Node implementations.
    Author:
    Daniel Sagenschneider
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Node[] getChildNodes​(java.util.Map<java.lang.String,​? extends Node>... children)
      Obtains the child Node instances.
      static <N extends Node>
      N
      getInitialisedNode​(java.lang.String nodeName, java.util.Map<java.lang.String,​N> nodes, NodeContext context, java.util.function.Supplier<N> create, java.util.function.Consumer<N> initialiser)
      Obtains the initialised Node.
      static <N extends Node>
      N
      getInitialisedNode​(N existingNode, NodeContext context, java.util.function.Supplier<N> create, java.util.function.Consumer<N> initialiser)
      Obtains an initialised Node.
      static java.lang.String getLocation​(java.lang.String sourceClassName, java.lang.Object sourceInstance, java.lang.String location)
      Obtains the location for the Node.
      static <N extends Node>
      N
      getNode​(java.lang.String nodeName, java.util.Map<java.lang.String,​N> nodes, java.util.function.Supplier<N> create)
      Obtains the particular Node.
      static <S> S initialise​(Node node, NodeContext context, S existingState, java.util.function.Supplier<S> createState)
      Initialises the Node.
      static boolean isNodeTreeInitialised​(Node root, CompilerIssues issues)
      Indicates if the Node tree is fully initialised.
      static void logTreeStructure​(Node node, java.io.Writer log)
      Logs the Node tree structure to the Writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getNode

        public static <N extends Node> N getNode​(java.lang.String nodeName,
                                                 java.util.Map<java.lang.String,​N> nodes,
                                                 java.util.function.Supplier<N> create)
        Obtains the particular Node.
        Type Parameters:
        N - Node type.
        Parameters:
        nodeName - Name of the Node.
        nodes - Existing Map of Node instances by their names.
        create - Supplier to create the Node.
        Returns:
        Node for the name.
      • getInitialisedNode

        public static <N extends Node> N getInitialisedNode​(java.lang.String nodeName,
                                                            java.util.Map<java.lang.String,​N> nodes,
                                                            NodeContext context,
                                                            java.util.function.Supplier<N> create,
                                                            java.util.function.Consumer<N> initialiser)

        Obtains the initialised Node.

        Should the Node be already initialised, an issue will be reported to the CompilerIssues.

        Type Parameters:
        N - Node type.
        Parameters:
        nodeName - Name of the Node.
        nodes - Map of Node instances by their name.
        context - NodeContext.
        create - Supplier to create the Node.
        initialiser - Consumer to initialise the Node.
        Returns:
        Initialised Node.
      • getInitialisedNode

        public static <N extends Node> N getInitialisedNode​(N existingNode,
                                                            NodeContext context,
                                                            java.util.function.Supplier<N> create,
                                                            java.util.function.Consumer<N> initialiser)
        Obtains an initialised Node.
        Type Parameters:
        N - Node type.
        Parameters:
        existingNode - Existing Node. May be null.
        context - NodeContext.
        create - Supplier to create the Node.
        initialiser - Consumer to initialise the Node.
        Returns:
        Initialised Node.
      • initialise

        public static <S> S initialise​(Node node,
                                       NodeContext context,
                                       S existingState,
                                       java.util.function.Supplier<S> createState)
        Initialises the Node.
        Type Parameters:
        S - Type of state.
        Parameters:
        node - Node to be initialised.
        context - NodeContext.
        existingState - Existing initialised state of the Node. May be null.
        createState - Supplier to create the initialised state.
        Returns:
        Initialised state for the Node.
      • isNodeTreeInitialised

        public static boolean isNodeTreeInitialised​(Node root,
                                                    CompilerIssues issues)
        Indicates if the Node tree is fully initialised.
        Parameters:
        root - Root Node of tree.
        issues - CompilerIssues.
        Returns:
        true if all Node instances within the tree are initialised. false if non-initialised Node instances within the tree, with issues reported to the CompilerIssues.
      • logTreeStructure

        public static void logTreeStructure​(Node node,
                                            java.io.Writer log)
                                     throws java.io.IOException
        Logs the Node tree structure to the Writer.
        Parameters:
        node - Root Node of tree.
        log - Writer.
        Throws:
        java.io.IOException - If fails to log.
      • getLocation

        public static java.lang.String getLocation​(java.lang.String sourceClassName,
                                                   java.lang.Object sourceInstance,
                                                   java.lang.String location)
        Obtains the location for the Node.
        Parameters:
        sourceClassName - Source Class name.
        sourceInstance - Instance of the source. May be null.
        location - Location of the source.
        Returns:
        Location for the Node.
      • getChildNodes

        @SafeVarargs
        public static Node[] getChildNodes​(java.util.Map<java.lang.String,​? extends Node>... children)
        Obtains the child Node instances.
        Parameters:
        children - Map instances containing the child Node instances.
        Returns:
        Child Node instances.