public final class ReflectionUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
ReflectionUtils.RandomSupplier<T> |
Modifier and Type | Method and Description |
---|---|
static Object |
createDefaultInstance(String type) |
static Method |
findAccessor(Object target,
String propertyName)
Returns the accessor method for the specified member property.
|
static Method |
findMethod(Object target,
String name,
Class<?> parameterType)
Finds a method of the given name that will accept a parameter of the
given type.
|
static List<Object> |
getAllByPath(Object target,
List<String> path)
Evaluates the given path expression and returns the list of all matching
objects.
|
static Object |
getByPath(Object target,
List<String> path)
Evaluates the given path expression on the given object and returns the
object found.
|
static <T> Object |
getField(T instance,
Field field) |
static Class<?> |
getParameterTypes(Object target,
List<String> path) |
static <T> Class<T> |
loadClass(Class<?> base,
String name) |
static <T> Class<T> |
loadClass(ClassLoader classloader,
String name) |
static <T> T |
newInstance(Class<T> clazz,
Object... params) |
static <T> T |
newInstanceWithAllFieldsSet(Class<T> clz) |
static <T> T |
newInstanceWithAllFieldsSet(Class<T> clz,
List<ReflectionUtils.RandomSupplier<?>> suppliers) |
static <T> T |
newInstanceWithAllFieldsSet(Class<T> clz,
ReflectionUtils.RandomSupplier<?>... suppliers) |
static void |
setByPath(Object target,
Object value,
List<String> path)
Sets the value of the attribute at the given path in the target object,
creating any intermediate values (using the default constructor for the
type) if need be.
|
static void |
setField(Object instance,
Field field,
Object arg) |
public static <T> Class<T> loadClass(ClassLoader classloader, String name)
public static Object getByPath(Object target, List<String> path)
target
- the object to reflect onpath
- the path to evaluatepublic static List<Object> getAllByPath(Object target, List<String> path)
target
- the object to evaluate the expression againstpath
- the path expression to evaluatepublic static void setByPath(Object target, Object value, List<String> path)
target
- the object to modifyvalue
- the value to addpath
- the path into the target object at which to add the valuepublic static Method findAccessor(Object target, String propertyName)
target
- the object to reflect onpropertyName
- the name of the property to search forIllegalStateException
- if no matching method is foundpublic static Method findMethod(Object target, String name, Class<?> parameterType)
target
- the object to reflect onname
- the name of the method to search forparameterType
- the type of the parameter to be passedIllegalStateException
- if no matching method is foundpublic static <T> T newInstanceWithAllFieldsSet(Class<T> clz)
public static <T> T newInstanceWithAllFieldsSet(Class<T> clz, ReflectionUtils.RandomSupplier<?>... suppliers)
public static <T> T newInstanceWithAllFieldsSet(Class<T> clz, List<ReflectionUtils.RandomSupplier<?>> suppliers)
Copyright © 2024. All rights reserved.