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> TcallConstructor(Constructor<?> constructor, Object... args)Call a constructor with the arguments.<T> TcallField(Object target, Field field)Call a field on a target.<T> TcallMethod(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.MethodfindMethod(Class<?> originalClazz, String methodName, Class<?>... argTypes)Scan the hierarchy of the input class for a method with the given name.FieldgetField(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> TgetFieldValue(Object target, String fieldName)Get a field from an object.Set<String>getModifiers(Field field)Get the modifier names of a field.booleansetAccessible(Class<?> clazz, Constructor<?> constructor)Set the constructor as accessible.booleansetAccessible(Class<?> clazz, Field field)Set the field as accessible.booleansetAccessible(Class<?> clazz, Method method)Set the method as accessible.
-
-
-
Method Detail
-
setAccessible
public boolean setAccessible(Class<?> clazz, Field field)
Description copied from interface:IReflectionSet the field as accessible.- Specified by:
setAccessiblein 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:IReflectionSet the method as accessible.- Specified by:
setAccessiblein 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:IReflectionSet the constructor as accessible.- Specified by:
setAccessiblein 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:IReflectionCall 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:
callMethodin 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:IReflectionScan 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:
findMethodin 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:IReflectionGet a filed from the target.- Specified by:
getFieldin 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:IReflectionGet a field from an object.- Specified by:
getFieldValuein 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:IReflectionGet an iterator that will iterator over all the available fields on the given class.- Specified by:
getFieldIteratorin 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:IReflectionCall a field on a target.- Specified by:
callFieldin 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:IReflectionGet the modifier names of a field.- Specified by:
getModifiersin 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:IReflectionFind a constructor on the given class.- Specified by:
findConstructorin 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:IReflectionCall a constructor with the arguments.- Specified by:
callConstructorin 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
-
-