Class CompileUtil


  • public class CompileUtil
    extends java.lang.Object
    Utility methods to aid in compiling.
    Author:
    Daniel Sagenschneider
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isBlank​(java.lang.String value)
      Indicates whether the input String is either null or empty.
      static <T> T loadType​(java.lang.Class<T> type, java.lang.String sourceClassName, CompilerIssues issues, java.util.function.Supplier<T> supplier)
      Convenience method to load a type.
      static <N,​T>
      T[]
      loadTypes​(java.util.Map<java.lang.String,​N> nodesMap, java.util.function.Function<N,​java.lang.String> sortKeyExtractor, java.util.function.Function<N,​T> typeLoader, java.util.function.IntFunction<T[]> arrayGenerator)
      Convenience method to load a listing of types.
      static <N,​T>
      T[]
      loadTypes​(java.util.stream.Stream<N> nodes, java.util.function.Function<N,​java.lang.String> sortKeyExtractor, java.util.function.Function<N,​T> typeLoader, java.util.function.IntFunction<T[]> arrayGenerator)
      Convenience method to load a listing of types.
      static <T,​E>
      T
      newInstance​(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, Node node, CompilerIssues issues)
      Instantiates a new instance of the input Class by its default constructor.
      static <T,​E>
      T
      newInstance​(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, SourceIssues issues)
      Instantiates a new instance of the input Class by its default constructor.
      static <T> T newInstance​(java.lang.String className, java.lang.Class<T> expectedType, java.util.Map<java.lang.String,​java.lang.Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues)
      Convenience method to instantiate and instance of a Class from its fully qualified name.
      static <T> java.lang.Class<? extends T> obtainClass​(java.lang.String className, java.lang.Class<T> expectedType, java.util.Map<java.lang.String,​java.lang.Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues)
      Obtains the Class.
      static int sortCompare​(java.lang.String a, java.lang.String b)
      Convenience method to compare two strings for sorting.
      static <N> boolean source​(java.util.Map<java.lang.String,​N> nodesMap, java.util.function.Function<N,​java.lang.String> sortKeyExtractor, java.util.function.Predicate<N> sourcer)
      Convenience method to source a listing of sub Node instances.
      • Methods inherited from class java.lang.Object

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

      • isBlank

        public static boolean isBlank​(java.lang.String value)
        Indicates whether the input String is either null or empty.
        Parameters:
        value - Value to check.
        Returns:
        true if blank.
      • sortCompare

        public static int sortCompare​(java.lang.String a,
                                      java.lang.String b)
        Convenience method to compare two strings for sorting.
        Parameters:
        a - First string.
        b - Second string.
        Returns:
        Compare result for sorting.
      • obtainClass

        public static <T> java.lang.Class<? extends T> obtainClass​(java.lang.String className,
                                                                   java.lang.Class<T> expectedType,
                                                                   java.util.Map<java.lang.String,​java.lang.Class<?>> aliases,
                                                                   SourceContext context,
                                                                   Node node,
                                                                   CompilerIssues issues)
        Obtains the Class.
        Type Parameters:
        T - Expected type.
        Parameters:
        className - Fully qualified name of the Class to obtain.
        expectedType - Expected type of the Class to return.
        aliases - Map of alias name to Class. May be null.
        context - SourceContext.
        node - Node.
        issues - CompilerIssues.
        Returns:
        Class.
      • newInstance

        public static <T,​E> T newInstance​(java.lang.Class<T> clazz,
                                                java.lang.Class<E> expectedType,
                                                Node node,
                                                CompilerIssues issues)
        Instantiates a new instance of the input Class by its default constructor. If fails to instantiate, then reports issue via CompilerIssues.
        Type Parameters:
        T - Type of instance.
        E - Expected type.
        Parameters:
        clazz - Class to instantiate.
        expectedType - Expected type that is to be instantiated.
        node - Node.
        issues - CompilerIssues.
        Returns:
        New instance or null if not able to instantiate.
      • newInstance

        public static <T,​E> T newInstance​(java.lang.Class<T> clazz,
                                                java.lang.Class<E> expectedType,
                                                SourceIssues issues)
        Instantiates a new instance of the input Class by its default constructor. If fails to instantiate, then reports issue via SourceIssues.
        Type Parameters:
        T - Type of instance.
        E - Expected type.
        Parameters:
        clazz - Class to instantiate.
        expectedType - Expected type that is to be instantiated.
        issues - SourceIssues.
        Returns:
        New instance or null if not able to instantiate.
      • newInstance

        public static <T> T newInstance​(java.lang.String className,
                                        java.lang.Class<T> expectedType,
                                        java.util.Map<java.lang.String,​java.lang.Class<?>> aliases,
                                        SourceContext context,
                                        Node node,
                                        CompilerIssues issues)
        Convenience method to instantiate and instance of a Class from its fully qualified name.
        Type Parameters:
        T - Expected type.
        Parameters:
        className - Fully qualified name of the Class.
        expectedType - Expected type that Class instance must be assignable.
        aliases - Map of alias name to Class. May be null.
        context - SourceContext.
        node - Node.
        issues - CompilerIssues.
        Returns:
        New instance or null if not able to instantiate.
      • loadType

        public static <T> T loadType​(java.lang.Class<T> type,
                                     java.lang.String sourceClassName,
                                     CompilerIssues issues,
                                     java.util.function.Supplier<T> supplier)
                              throws LoadTypeError
        Convenience method to load a type.
        Type Parameters:
        T - Type to be loaded.
        Parameters:
        type - Type to be loaded.
        sourceClassName - Source Class name for the type.
        issues - CompilerIssues.
        supplier - Supplier of the type.
        Returns:
        Type.
        Throws:
        LoadTypeError - If fails to load the type.
      • loadTypes

        public static <N,​T> T[] loadTypes​(java.util.Map<java.lang.String,​N> nodesMap,
                                                java.util.function.Function<N,​java.lang.String> sortKeyExtractor,
                                                java.util.function.Function<N,​T> typeLoader,
                                                java.util.function.IntFunction<T[]> arrayGenerator)
        Convenience method to load a listing of types.
        Type Parameters:
        N - Node type within the listing.
        T - Type returned from the Node instances within the listing.
        Parameters:
        nodesMap - Map of Node instances by their names to load types from.
        sortKeyExtractor - Function to extract the sort key (to enable deterministic order of loading the types).
        typeLoader - Function to load the type from the Node.
        arrayGenerator - Function to generate the array of types.
        Returns:
        Array of types or null with issues reported to the CompilerIssues.
      • loadTypes

        public static <N,​T> T[] loadTypes​(java.util.stream.Stream<N> nodes,
                                                java.util.function.Function<N,​java.lang.String> sortKeyExtractor,
                                                java.util.function.Function<N,​T> typeLoader,
                                                java.util.function.IntFunction<T[]> arrayGenerator)
        Convenience method to load a listing of types.
        Type Parameters:
        N - Node type within the listing.
        T - Type returned from the Node instances within the listing.
        Parameters:
        nodes - Stream of Node instances to load types from.
        sortKeyExtractor - Function to extract the sort key (to enable deterministic order of loading the types).
        typeLoader - Function to load the type from the Node.
        arrayGenerator - Function to generate the array of types.
        Returns:
        Array of types or null with issues reported to the CompilerIssues.
      • source

        public static <N> boolean source​(java.util.Map<java.lang.String,​N> nodesMap,
                                         java.util.function.Function<N,​java.lang.String> sortKeyExtractor,
                                         java.util.function.Predicate<N> sourcer)
        Convenience method to source a listing of sub Node instances.
        Type Parameters:
        N - Node type.
        Parameters:
        nodesMap - Map of Node instances by their names to source.
        sortKeyExtractor - Function to extract the sort key (to enable deterministic order of sourcing the sub Node instances).
        sourcer - Predicate to source the sub Node.
        Returns:
        true if all sub Node instances sourced. Otherwise, false with issue reported to the CompilerIssues.