Class CompileUtil

java.lang.Object
net.officefloor.compile.impl.util.CompileUtil

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

    • isBlank

      public static boolean isBlank(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(String a, 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> Class<? extends T> obtainClass(String className, Class<T> expectedType, Map<String,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(Class<T> clazz, 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(Class<T> clazz, 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(String className, Class<T> expectedType, Map<String,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(Class<T> type, String sourceClassName, CompilerIssues issues, 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(Map<String,N> nodesMap, Function<N,String> sortKeyExtractor, Function<N,T> typeLoader, 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(Stream<N> nodes, Function<N,String> sortKeyExtractor, Function<N,T> typeLoader, 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(Map<String,N> nodesMap, Function<N,String> sortKeyExtractor, 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.