public interface Reflector
There are a set of methods that can find specific reflection objects ( fields
, constructors
or methods
). These methods
returns components that allows filtering by using common methods and, if no object is
found, a null
value is always returned in a case of a
single object selection (for a set of them, an empty
collection is returned).
Modifier and Type | Method and Description |
---|---|
java.lang.reflect.Method |
bridgedMethodFor(java.lang.reflect.Method bridgeMethod)
Reflects the bridged method of a given
bridge method. |
ConstructorSelector |
constructor()
Reflects a constructor with the specified parameters in a target.
|
ConstructorsSelector |
constructors()
Reflects all the constructors.
|
Reflector |
declared()
Indicates to reflect a declared element (besides its access modifiers).
|
FieldSelector |
field(java.lang.String name)
Reflects a field with the specified name in a target.
|
FieldsSelector |
fields()
Reflects all fields in a target.
|
Result<java.lang.Class,java.lang.Object> |
genericType()
Reflects the generic type parameter declared in a target.
|
Result<java.lang.Class,java.lang.Object> |
genericType(java.lang.String parameterName)
Reflects the generic type parameter declared in a target.
|
Result<java.util.List<java.lang.Class>,java.lang.Object> |
interfaces()
Reflects all interfaces that a target implements.
|
MethodSelector |
method(java.lang.String name)
Reflects a method with the specified name and parameters in a target.
|
MethodsSelector |
methods()
Reflects all methods in a target.
|
Reflector |
visible()
Indicates to reflect only visible elements (declared as "public" in all hierarchy).
|
Reflector visible()
Reflector declared()
FieldsSelector fields()
Use this method for selecting a set of fields.
FieldSelector field(java.lang.String name)
Use this method for selecting a single field.
name
- the field name.MethodsSelector methods()
Use this method for selecting a set of methods.
MethodSelector method(java.lang.String name)
Use this method for selecting a single method.
The method parameters in question must be informed in the returned object.
name
- the method name.ConstructorSelector constructor()
Use this method for selecting a single constructor.
The constructor parameters in question must be informed in the returned object.
ConstructorsSelector constructors()
Use this method for selecting a set of constructors.
Result<java.util.List<java.lang.Class>,java.lang.Object> interfaces()
This method returns the interfaces found in every class of the target hierarchy.
For a set of the interfaces implemented only by the target in question, use the
Class.getInterfaces()
method.
Result<java.lang.Class,java.lang.Object> genericType(java.lang.String parameterName)
Example:
Based on the following classes.
public class MyClass<E> { //... fields and methods } public class MyExtendedClass<MyType> { //... fields and methods }The code bellow will print
MyType
:
Class<?> genericType = Reflection.reflect()
.genericType("E").in(MyExtendedClass.class);
System.out.print(genericType.getSimpleName());
parameterName
- the generic parameter name.Result<java.lang.Class,java.lang.Object> genericType()
This method should be used only if the target has only one generic parameter.
genericType(String)
java.lang.reflect.Method bridgedMethodFor(java.lang.reflect.Method bridgeMethod)
bridge
method.
If the given method is not a bridge, then it should be returned.
bridgeMethod
- the bridge method.