Class CompileUtil
java.lang.Object
net.officefloor.compile.impl.util.CompileUtil
Utility methods to aid in compiling.
- Author:
- Daniel Sagenschneider
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanIndicates whether the inputStringis eithernullor empty.static <T> TloadType(Class<T> type, String sourceClassName, CompilerIssues issues, Supplier<T> supplier) Convenience method to load a type.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.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.static <T,E> T newInstance(Class<T> clazz, Class<E> expectedType, Node node, CompilerIssues issues) Instantiates a new instance of the inputClassby its default constructor.static <T,E> T newInstance(Class<T> clazz, Class<E> expectedType, SourceIssues issues) Instantiates a new instance of the inputClassby its default constructor.static <T> TnewInstance(String className, Class<T> expectedType, Map<String, Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues) Convenience method to instantiate and instance of aClassfrom its fully qualified name.static <T> Class<? extends T>obtainClass(String className, Class<T> expectedType, Map<String, Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues) Obtains theClass.static intsortCompare(String a, String b) Convenience method to compare two strings for sorting.static <N> booleanConvenience method to source a listing of subNodeinstances.
-
Method Details
-
isBlank
Indicates whether the inputStringis eithernullor empty.- Parameters:
value- Value to check.- Returns:
trueif blank.
-
sortCompare
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 theClass.- Type Parameters:
T- Expected type.- Parameters:
className- Fully qualified name of theClassto obtain.expectedType- Expected type of theClassto return.aliases- Map of alias name toClass. May benull.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 inputClassby its default constructor. If fails to instantiate, then reports issue viaCompilerIssues.- Type Parameters:
T- Type of instance.E- Expected type.- Parameters:
clazz-Classto instantiate.expectedType- Expected type that is to be instantiated.node-Node.issues-CompilerIssues.- Returns:
- New instance or
nullif not able to instantiate.
-
newInstance
Instantiates a new instance of the inputClassby its default constructor. If fails to instantiate, then reports issue viaSourceIssues.- Type Parameters:
T- Type of instance.E- Expected type.- Parameters:
clazz-Classto instantiate.expectedType- Expected type that is to be instantiated.issues-SourceIssues.- Returns:
- New instance or
nullif 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 aClassfrom its fully qualified name.- Type Parameters:
T- Expected type.- Parameters:
className- Fully qualified name of theClass.expectedType- Expected type thatClassinstance must be assignable.aliases- Map of alias name toClass. May benull.context-SourceContext.node-Node.issues-CompilerIssues.- Returns:
- New instance or
nullif 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- SourceClassname for the type.issues-CompilerIssues.supplier-Supplierof 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-Nodetype within the listing.T- Type returned from theNodeinstances within the listing.- Parameters:
nodesMap-MapofNodeinstances by their names to load types from.sortKeyExtractor-Functionto extract the sort key (to enable deterministic order of loading the types).typeLoader-Functionto load the type from theNode.arrayGenerator-Functionto generate the array of types.- Returns:
- Array of types or
nullwith issues reported to theCompilerIssues.
-
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-Nodetype within the listing.T- Type returned from theNodeinstances within the listing.- Parameters:
nodes-StreamofNodeinstances to load types from.sortKeyExtractor-Functionto extract the sort key (to enable deterministic order of loading the types).typeLoader-Functionto load the type from theNode.arrayGenerator-Functionto generate the array of types.- Returns:
- Array of types or
nullwith issues reported to theCompilerIssues.
-
source
public static <N> boolean source(Map<String, N> nodesMap, Function<N, String> sortKeyExtractor, Predicate<N> sourcer) Convenience method to source a listing of subNodeinstances.- Type Parameters:
N-Nodetype.- Parameters:
nodesMap-MapofNodeinstances by their names to source.sortKeyExtractor-Functionto extract the sort key (to enable deterministic order of sourcing the subNodeinstances).sourcer-Predicateto source the subNode.- Returns:
trueif all subNodeinstances sourced. Otherwise,falsewith issue reported to theCompilerIssues.
-