public final class ClassUtils extends Object
Class lookup (locateClass(String, boolean,
ClassLoader)), that allows a full scan (to try all
packages known) and an optional ExternalClassLoader instance that is able to actually compile a .java file on the fly and load its compile
.class file| Constructor and Description |
|---|
ClassUtils() |
| Modifier and Type | Method and Description |
|---|---|
static @Nullable Object |
assignToField(Object o,
String property,
Object value)
Assigns a value to a field
id on the given object o. |
static Set<String> |
collectMethodNames(Class<?> dataType,
Class<?> boundaryMarker,
EnumSet<MethodModifier> methodModifiers) |
static Set<Method> |
collectMethods(Class<?> dataType,
Class<?> boundaryMarker,
EnumSet<MethodModifier> methodModifiers)
Returns a list of names that represent the methods on an
Object |
static Set<Method> |
collectMethodsByName(Class<?> type,
Class<?> boundaryMarker,
EnumSet<MethodModifier> methodModifiers,
String methodName) |
static Map<String,Set<Method>> |
collectMethodsMappingToName(Class<?> type,
Class<?> boundaryMarker,
EnumSet<MethodModifier> methodModifiers) |
static @NotNull Collection<String> |
collectPropertyNames(Object subject)
Returns a list of names that represent the fields on an
Object. |
static @Nullable Class<?> |
locateClass(String className,
boolean fullscan,
@Nullable ClassLoader classLoader)
Searches the JVM and optionally all of its packages
|
static @Nullable Class<?> |
locateClass(String fullClassName,
@Nullable ClassLoader classLoader)
This function dynamically tries to locate a class.
|
static @Nullable Class<?> |
locateClass(String className,
@Nullable String inPackage,
@Nullable ClassLoader classLoader) |
static <T> T |
newInstanceSimple(Class<T> _class)
Simply calls
Class.newInstance() and hides the exception handling boilerplate code. |
static void |
resetCache() |
static @Nullable Field |
solveField(Class<?> _class,
String fieldName)
Returns a field from the given Class that goes by the name of
fieldName. |
static @Nullable Field |
solveField(Object object,
String fieldName)
Delegates to
solveField(Class, String) by using the class of given object object or if object itself if it ss a class. |
static <T> T |
solveFieldValue(Object object,
String fieldName)
Gets value from the field returned by
solveField(Object, String).; |
public static void resetCache()
@Nullable public static @Nullable Class<?> locateClass(String className, boolean fullscan, @Nullable @Nullable ClassLoader classLoader)
className - The name of the class to locate.fullscan - Whether a full scan through all available java packages is required.classLoader - Optional user-provided classloader.Class reference if found or null otherwise.@Nullable public static @Nullable Class<?> locateClass(String className, @Nullable @Nullable String inPackage, @Nullable @Nullable ClassLoader classLoader)
@Nullable public static @Nullable Class<?> locateClass(String fullClassName, @Nullable @Nullable ClassLoader classLoader)
Class.forName(String).fullClassName - The Class that needs to be found.classLoader - Optional user-provided classloader.Class object found from cache or VM.@NotNull public static <T> T newInstanceSimple(Class<T> _class)
Class.newInstance() and hides the exception handling boilerplate code.T - Type used to parameterize the return instance._class - The datatype for which we need to create a new instance of.@Nullable public static <T> T solveFieldValue(Object object, String fieldName)
solveField(Object, String).;@Nullable public static @Nullable Field solveField(Object object, String fieldName)
solveField(Class, String) by using the class of given object object or if object itself if it ss a class.@Nullable public static @Nullable Field solveField(Class<?> _class, String fieldName)
fieldName. Will search for fields on implemented interfaces and superclasses._class - The reference to the Class to fetch the field from.fieldName - The identifier or name of the member field/property.Field.@Nullable public static @Nullable Object assignToField(Object o, String property, Object value) throws IllegalAccessException, NoSuchFieldException
id on the given object o. If a simple assignment fails, a common conversion will be
attempted.o - The object to find the field on.property - The name of the field we're assigning the value to.value - The value to assign to the field, may be converted to the field's type through common conversion.IllegalAccessException - Thrown by Field.set(Object, Object)NoSuchFieldException - Thrown if the Field could not be found, even after trying to convert the value to the target type.ValueConversionHelper.convert(Object, Class)@NotNull public static @NotNull Collection<String> collectPropertyNames(Object subject)
Object.subject - The Object who's properties/fields need to be reflected.Object.public static Set<String> collectMethodNames(Class<?> dataType, Class<?> boundaryMarker, EnumSet<MethodModifier> methodModifiers)
collectMethods(Class, Class, EnumSet) mapped to the method names.public static Set<Method> collectMethodsByName(Class<?> type, Class<?> boundaryMarker, EnumSet<MethodModifier> methodModifiers, String methodName)
collectMethodsMappingToName(Class, Class, EnumSet) filtered on method name.public static Map<String,Set<Method>> collectMethodsMappingToName(Class<?> type, Class<?> boundaryMarker, EnumSet<MethodModifier> methodModifiers)
collectMethods(Class, Class, EnumSet) filtered on method name.public static Set<Method> collectMethods(Class<?> dataType, Class<?> boundaryMarker, EnumSet<MethodModifier> methodModifiers)
ObjectmethodModifiers - List of method modifiers that will match any method that has one of them.boundaryMarker - Optional type to limit (including) how far back up the inheritance chain we go for discovering methods.Methods.Copyright © 2018. All rights reserved.