Class CompileUtil
- java.lang.Object
-
- net.officefloor.compile.impl.util.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 inputString
is eithernull
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>
TnewInstance(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, Node node, CompilerIssues issues)
Instantiates a new instance of the inputClass
by its default constructor.static <T,E>
TnewInstance(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, SourceIssues issues)
Instantiates a new instance of the inputClass
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 aClass
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 theClass
.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 subNode
instances.
-
-
-
Method Detail
-
isBlank
public static boolean isBlank(java.lang.String value)
Indicates whether the inputString
is eithernull
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 theClass
.- Type Parameters:
T
- Expected type.- Parameters:
className
- Fully qualified name of theClass
to obtain.expectedType
- Expected type of theClass
to return.aliases
- Map of alias name toClass
. May benull
.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 inputClass
by its default constructor. If fails to instantiate, then reports issue viaCompilerIssues
.- 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 inputClass
by its default constructor. If fails to instantiate, then reports issue viaSourceIssues
.- 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 aClass
from its fully qualified name.- Type Parameters:
T
- Expected type.- Parameters:
className
- Fully qualified name of theClass
.expectedType
- Expected type thatClass
instance must be assignable.aliases
- Map of alias name toClass
. May benull
.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
- SourceClass
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 theNode
instances within the listing.- Parameters:
nodesMap
-Map
ofNode
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 theNode
.arrayGenerator
-Function
to generate the array of types.- Returns:
- Array of types or
null
with issues reported to theCompilerIssues
.
-
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 theNode
instances within the listing.- Parameters:
nodes
-Stream
ofNode
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 theNode
.arrayGenerator
-Function
to generate the array of types.- Returns:
- Array of types or
null
with issues reported to theCompilerIssues
.
-
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 subNode
instances.- Type Parameters:
N
-Node
type.- Parameters:
nodesMap
-Map
ofNode
instances by their names to source.sortKeyExtractor
-Function
to extract the sort key (to enable deterministic order of sourcing the subNode
instances).sourcer
-Predicate
to source the subNode
.- Returns:
true
if all subNode
instances sourced. Otherwise,false
with issue reported to theCompilerIssues
.
-
-