Package com.intergral.deep.reflect
Class ReflectionImpl
- java.lang.Object
-
- com.intergral.deep.reflect.ReflectionImpl
-
- All Implemented Interfaces:
IReflection
- Direct Known Subclasses:
Java9ReflectionImpl
public class ReflectionImpl extends Object implements IReflection
The version of reflection used before modules where added.
-
-
Constructor Summary
Constructors Constructor Description ReflectionImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
callConstructor(Constructor<?> constructor, Object... args)
Call a constructor with the arguments.<T> T
callField(Object target, Field field)
Call a field on a target.<T> T
callMethod(Object target, String methodName, Object... args)
Call a method on the target object.Constructor<?>
findConstructor(Class<?> clazz, Class<?>... args)
Find a constructor on the given class.Method
findMethod(Class<?> originalClazz, String methodName, Class<?>... argTypes)
Scan the hierarchy of the input class for a method with the given name.Field
getField(Object obj, String fieldName)
Get a filed from the target.Iterator<Field>
getFieldIterator(Class<?> clazz)
Get an iterator that will iterator over all the available fields on the given class.<T> T
getFieldValue(Object target, String fieldName)
Get a field from an object.Set<String>
getModifiers(Field field)
Get the modifier names of a field.boolean
setAccessible(Class<?> clazz, Constructor<?> constructor)
Set the constructor as accessible.boolean
setAccessible(Class<?> clazz, Field field)
Set the field as accessible.boolean
setAccessible(Class<?> clazz, Method method)
Set the method as accessible.
-
-
-
Method Detail
-
setAccessible
public boolean setAccessible(Class<?> clazz, Field field)
Description copied from interface:IReflection
Set the field as accessible.- Specified by:
setAccessible
in interfaceIReflection
- Parameters:
clazz
- the clazz the field is onfield
- the field to access- Returns:
- could we complete the operation
- See Also:
Field.setAccessible(boolean)
-
setAccessible
public boolean setAccessible(Class<?> clazz, Method method)
Description copied from interface:IReflection
Set the method as accessible.- Specified by:
setAccessible
in interfaceIReflection
- Parameters:
clazz
- the clazz the field is onmethod
- the method to access- Returns:
- could we complete the operation
- See Also:
Method.setAccessible(boolean)
-
setAccessible
public boolean setAccessible(Class<?> clazz, Constructor<?> constructor)
Description copied from interface:IReflection
Set the constructor as accessible.- Specified by:
setAccessible
in interfaceIReflection
- Parameters:
clazz
- the clazz the field is onconstructor
- the constructor to set- Returns:
- could we complete the operation
- See Also:
Constructor.setAccessible(boolean)
-
callMethod
public <T> T callMethod(Object target, String methodName, Object... args)
Description copied from interface:IReflection
Call a method on the target object.This will look for the method using
IReflection.findMethod(Class, String, Class[])
using the input arguments as the argument types of the method. The method will then be invoked on the target argument.- Specified by:
callMethod
in interfaceIReflection
- Type Parameters:
T
- the type of the response- Parameters:
target
- the target instance to call the method onmethodName
- the name of the method to callargs
- the arguments to the method- Returns:
- the response of the method
-
findMethod
public Method findMethod(Class<?> originalClazz, String methodName, Class<?>... argTypes)
Description copied from interface:IReflection
Scan the hierarchy of the input class for a method with the given name. This will scan declared methods and methods, as well as stepping up the super class.- Specified by:
findMethod
in interfaceIReflection
- Parameters:
originalClazz
- the class to start the scan onmethodName
- the name of the method to look forargTypes
- the argument types in the method signature- Returns:
- the discovered method or
null
-
getField
public Field getField(Object obj, String fieldName)
Description copied from interface:IReflection
Get a filed from the target.- Specified by:
getField
in interfaceIReflection
- Parameters:
obj
- the target instance to look on.fieldName
- the name of the field to get- Returns:
- the field, or
null
-
getFieldValue
public <T> T getFieldValue(Object target, String fieldName)
Description copied from interface:IReflection
Get a field from an object.- Specified by:
getFieldValue
in interfaceIReflection
- Type Parameters:
T
- the type to return as- Parameters:
target
- the object to look atfieldName
- the field name to look for- Returns:
- the field as T, else
null
-
getFieldIterator
public Iterator<Field> getFieldIterator(Class<?> clazz)
Description copied from interface:IReflection
Get an iterator that will iterator over all the available fields on the given class.- Specified by:
getFieldIterator
in interfaceIReflection
- Parameters:
clazz
- the class to scan- Returns:
- the iterator for the fields
-
callField
public <T> T callField(Object target, Field field)
Description copied from interface:IReflection
Call a field on a target.- Specified by:
callField
in interfaceIReflection
- Type Parameters:
T
- the type of the return- Parameters:
target
- the object to get the field fromfield
- the field to call- Returns:
- the value of the field
-
getModifiers
public Set<String> getModifiers(Field field)
Description copied from interface:IReflection
Get the modifier names of a field.- Specified by:
getModifiers
in interfaceIReflection
- Parameters:
field
- the field to look at- Returns:
- a set of strings that represent the modifiers.
-
findConstructor
public Constructor<?> findConstructor(Class<?> clazz, Class<?>... args)
Description copied from interface:IReflection
Find a constructor on the given class.- Specified by:
findConstructor
in interfaceIReflection
- Parameters:
clazz
- the class to look onargs
- the arguments for the constructor- Returns:
- the constructor or
null
-
callConstructor
public <T> T callConstructor(Constructor<?> constructor, Object... args)
Description copied from interface:IReflection
Call a constructor with the arguments.- Specified by:
callConstructor
in interfaceIReflection
- Type Parameters:
T
- the type of the return- Parameters:
constructor
- the constructor to callargs
- the arguments for the constructor- Returns:
- the new object, or
null
-
-