public class Reflection extends Object
Modifier and Type | Field and Description |
---|---|
static student.testingsupport.reflection.Field<Object> |
field
A starting point for field filters where the name is unspecified.
|
static Object[] |
NULL
This constant represents an argument list containing one argument
whose value is null.
|
static student.testingsupport.reflection.Type<?> |
type
A starting point for type filters where the name is unspecified.
|
Modifier and Type | Method and Description |
---|---|
static <ConcreteFilterType extends student.testingsupport.reflection.Filter<ConcreteFilterType,?>> |
atLeastOne(ConcreteFilterType filter)
Change the quantification behavior of a filter so that boolean
predicates are evaluated over all matches for the filter and the
result is "or"ed together.
|
static <T> T |
create(Class<T> returnType,
Object... params)
Dynamically look up and invoke a class constructor for the target
class, with appropriate hints if any failures happen along the way.
|
static <T> T |
create(student.testingsupport.reflection.Constructor<T> constructor,
Object... params)
Just like
Constructor.newInstance(Object...) ,
but converts any thrown exceptions into RuntimeExceptions. |
static <T> T |
create(Constructor<T> constructor,
Object... params)
Just like
Constructor.newInstance(Object...) ,
but converts any thrown exceptions into RuntimeExceptions. |
static Object |
create(String className,
Object... params)
Dynamically look up and invoke a class constructor for the target
class, with appropriate hints if any failures happen along the way.
|
static <T> T |
create(student.testingsupport.reflection.Type<T> returnType,
Object... params)
Dynamically look up and invoke a class constructor for the target
class, with appropriate hints if any failures happen along the way.
|
static <T> T |
createEx(Class<T> returnType,
Object... params)
Just like
create(Class, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static <T> T |
createEx(student.testingsupport.reflection.Constructor<T> constructor,
Object... params)
Just like
create(java.lang.reflect.Constructor, Object...) ,
but unwraps any InvocationTargetExceptions and throws the true cause. |
static <T> T |
createEx(Constructor<T> constructor,
Object... params)
Just like
create(java.lang.reflect.Constructor, Object...) ,
but unwraps any InvocationTargetExceptions and throws the true cause. |
static Object |
createEx(String className,
Object... params)
Just like
create(String, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static <T> T |
createEx(student.testingsupport.reflection.Type<T> returnType,
Object... params)
Just like
create(Type, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static <ConcreteFilterType extends student.testingsupport.reflection.Filter<ConcreteFilterType,?>> |
every(ConcreteFilterType filter)
Change the quantification behavior of a filter so that boolean
predicates are evaluated over all matches for the filter and the
result is "and"ed together.
|
static student.testingsupport.reflection.Field<Object> |
field(Field field)
Get the field corresponding to a
Field . |
static student.testingsupport.reflection.Field<Object> |
field(String name)
Get the field corresponding to a name.
|
<T> T |
get(Object receiver,
Class<T> type,
String field)
Get the value of a field.
|
<T> T |
get(Object receiver,
student.testingsupport.reflection.Field<T> field)
Get the value of a field.
|
Object |
get(Object receiver,
String field)
Get the value of a field, without checking the type of the field.
|
<T> T |
get(Object receiver,
student.testingsupport.reflection.Type<T> type,
String field)
Get the value of a field.
|
static <T> T |
invoke(Object receiver,
Class<T> returnType,
String methodName,
Object... params)
Dynamically look up and invoke a method on a target object, with
appropriate hints if any failures happen along the way.
|
static <T> T |
invoke(Object receiver,
student.testingsupport.reflection.Method<T> method,
Object... params)
Just like
Method.invoke(Object, Object...) ,
but converts any thrown exceptions into RuntimeExceptions. |
static Object |
invoke(Object receiver,
Method method,
Object... params)
Just like
Method.invoke(Object, Object...) ,
but converts any thrown exceptions into RuntimeExceptions. |
static void |
invoke(Object receiver,
String methodName,
Object... params)
Dynamically look up and invoke a method on a target object, with
appropriate hints if any failures happen along the way.
|
static <T> T |
invoke(Object receiver,
student.testingsupport.reflection.Type<T> returnType,
String methodName,
Object... params)
Dynamically look up and invoke a method on a target object, with
appropriate hints if any failures happen along the way.
|
static <T> T |
invokeEx(Object receiver,
Class<T> returnType,
String methodName,
Object... params)
Just like
invoke(Object, Class, String, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static <T> T |
invokeEx(Object receiver,
student.testingsupport.reflection.Method<T> method,
Object... params)
Just like
invoke(Object, Method, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static Object |
invokeEx(Object receiver,
Method method,
Object... params)
Just like
invoke(Object, java.lang.reflect.Method, Object...) ,
but unwraps any InvocationTargetExceptions and throws the true cause. |
static void |
invokeEx(Object receiver,
String methodName,
Object... params)
Just like
invoke(Object, String, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static <T> T |
invokeEx(Object receiver,
student.testingsupport.reflection.Type<T> returnType,
String methodName,
Object... params)
Just like
invoke(Object, Class, String, Object...) , but unwraps
any InvocationTargetExceptions and throws the true cause. |
static <ConcreteFilterType extends student.testingsupport.reflection.Filter<ConcreteFilterType,?>> |
onlyOne(ConcreteFilterType filter)
Change the quantification behavior of a filter so that boolean
predicates are evaluated over all matches for the filter and the
result is "xor"ed together.
|
<T> void |
set(Object receiver,
student.testingsupport.reflection.Field<T> field,
T value)
Set the value of a field.
|
void |
set(Object receiver,
String field,
Object value)
Set the value of a field.
|
static <T> student.testingsupport.reflection.Type<T> |
type(Class<T> aClass)
Get the type corresponding to a
Class . |
static student.testingsupport.reflection.Type<?> |
type(String name)
Get the type corresponding to a name.
|
public static final Object[] NULL
null
directly in such a situation, you may get
a compiler warning, because the compiler cannot distinguish between
null
meaning no arguments at all (i.e., a null argument
list) or null
meaning an argument list of length one
whose first element is null
. This constant is always
interpreted as the second one (if you meant the first, you wouldn't
have provided any argument at all!).public static final student.testingsupport.reflection.Type<?> type
public static final student.testingsupport.reflection.Field<Object> field
public static student.testingsupport.reflection.Type<?> type(String name)
name
- The name of the type.public static <T> student.testingsupport.reflection.Type<T> type(Class<T> aClass)
Class
.T
- This parameter is deduced from aClass.aClass
- The class to represent.public static student.testingsupport.reflection.Field<Object> field(String name)
name
- The name of the field.public static student.testingsupport.reflection.Field<Object> field(Field field)
Field
.field
- The field to represent.public static <ConcreteFilterType extends student.testingsupport.reflection.Filter<ConcreteFilterType,?>> ConcreteFilterType atLeastOne(ConcreteFilterType filter)
ConcreteFilterType
- This type is deduced from the filter.filter
- The filter to alter.public static <ConcreteFilterType extends student.testingsupport.reflection.Filter<ConcreteFilterType,?>> ConcreteFilterType onlyOne(ConcreteFilterType filter)
ConcreteFilterType
- This type is deduced from the filter.filter
- The filter to alter.public static <ConcreteFilterType extends student.testingsupport.reflection.Filter<ConcreteFilterType,?>> ConcreteFilterType every(ConcreteFilterType filter)
ConcreteFilterType
- This type is deduced from the filter.filter
- The filter to alter.public static Object create(String className, Object... params)
className
- The type of object to create.params
- The parameters to pass to the constructor.public static <T> T create(student.testingsupport.reflection.Type<T> returnType, Object... params)
T
- The generic parameter T is deduced from the returnType.returnType
- The type of object to create.params
- The parameters to pass to the constructor.public static <T> T create(Class<T> returnType, Object... params)
T
- The generic parameter T is deduced from the returnType.returnType
- The type of object to create.params
- The parameters to pass to the constructor.public static <T> T create(student.testingsupport.reflection.Constructor<T> constructor, Object... params)
Constructor.newInstance(Object...)
,
but converts any thrown exceptions into RuntimeExceptions.T
- The generic parameter T is deduced from the constructor.constructor
- The constructor to invoke.params
- The parameters to pass to the constructor.public static <T> T create(Constructor<T> constructor, Object... params)
Constructor.newInstance(Object...)
,
but converts any thrown exceptions into RuntimeExceptions.T
- The generic parameter T is deduced from the constructor.constructor
- The constructor to invoke.params
- The parameters to pass to the constructor.public static Object createEx(String className, Object... params) throws Exception
create(String, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.className
- The type of object to create.params
- The parameters to pass to the constructor.Exception
- if the underlying method throws one.public static <T> T createEx(student.testingsupport.reflection.Type<T> returnType, Object... params) throws Exception
create(Type, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the returnType.returnType
- The type of object to create.params
- The parameters to pass to the constructor.Exception
- if the underlying method throws one.public static <T> T createEx(Class<T> returnType, Object... params) throws Exception
create(Class, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the returnType.returnType
- The type of object to create.params
- The parameters to pass to the constructor.Exception
- if the underlying method throws one.public static <T> T createEx(student.testingsupport.reflection.Constructor<T> constructor, Object... params) throws Exception
create(java.lang.reflect.Constructor, Object...)
,
but unwraps any InvocationTargetExceptions and throws the true cause.
This version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the constructor.constructor
- The constructor to invoke.params
- The parameters to pass to the constructor.Exception
- if the underlying method throws one.public static <T> T createEx(Constructor<T> constructor, Object... params) throws Exception
create(java.lang.reflect.Constructor, Object...)
,
but unwraps any InvocationTargetExceptions and throws the true cause.
This version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the constructor.constructor
- The constructor to invoke.params
- The parameters to pass to the constructor.Exception
- if the underlying method throws one.public static void invoke(Object receiver, String methodName, Object... params)
receiver
- The object to invoke the method on.methodName
- The name of the method to invoke.params
- The parameters to pass to the method.public static <T> T invoke(Object receiver, Class<T> returnType, String methodName, Object... params)
T
- The generic parameter T is deduced from the returnType.receiver
- The object to invoke the method on.returnType
- The expected type of the method's return value.
Use null (or void.class
) if the method that is
looked up is a void method.methodName
- The name of the method to invoke.params
- The parameters to pass to the method.public static <T> T invoke(Object receiver, student.testingsupport.reflection.Type<T> returnType, String methodName, Object... params)
T
- The generic parameter T is deduced from the returnType.receiver
- The object to invoke the method on.returnType
- The expected type of the method's return value.
Use null (or void.class
) if the method that is
looked up is a void method.methodName
- The name of the method to invoke.params
- The parameters to pass to the method.public static <T> T invoke(Object receiver, student.testingsupport.reflection.Method<T> method, Object... params)
Method.invoke(Object, Object...)
,
but converts any thrown exceptions into RuntimeExceptions.T
- The generic parameter T is deduced from the method.receiver
- The object to invoke the method on.method
- The method to invoke.params
- The parameters to pass to the method.public static Object invoke(Object receiver, Method method, Object... params)
Method.invoke(Object, Object...)
,
but converts any thrown exceptions into RuntimeExceptions.receiver
- The object to invoke the method on.method
- The method to invoke.params
- The parameters to pass to the method.public static void invokeEx(Object receiver, String methodName, Object... params) throws Exception
invoke(Object, String, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.receiver
- The object to invoke the method on.methodName
- The name of the method to invoke.params
- The parameters to pass to the method.Exception
- if the underlying method throws one.public static <T> T invokeEx(Object receiver, Class<T> returnType, String methodName, Object... params) throws Exception
invoke(Object, Class, String, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the returnType.receiver
- The object to invoke the method on.returnType
- The expected type of the method's return value.
Use null (or void.class
) if the method that is
looked up is a void method.methodName
- The name of the method to invoke.params
- The parameters to pass to the method.Exception
- if the underlying method throws one.public static <T> T invokeEx(Object receiver, student.testingsupport.reflection.Type<T> returnType, String methodName, Object... params) throws Exception
invoke(Object, Class, String, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the returnType.receiver
- The object to invoke the method on.returnType
- The expected type of the method's return value.
Use null (or void.class
) if the method that is
looked up is a void method.methodName
- The name of the method to invoke.params
- The parameters to pass to the method.Exception
- if the underlying method throws one.public static <T> T invokeEx(Object receiver, student.testingsupport.reflection.Method<T> method, Object... params) throws Exception
invoke(Object, Method, Object...)
, but unwraps
any InvocationTargetExceptions and throws the true cause. This
version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.T
- The generic parameter T is deduced from the method.receiver
- The object to invoke the method on.method
- The method to invoke.params
- The parameters to pass to the method.Exception
- if the underlying method throws one.public static Object invokeEx(Object receiver, Method method, Object... params) throws Exception
invoke(Object, java.lang.reflect.Method, Object...)
,
but unwraps any InvocationTargetExceptions and throws the true cause.
This version is provided when you want to write test cases where you
are intending to check for Exceptions as expected results.receiver
- The object to invoke the method on.method
- The method to invoke.params
- The parameters to pass to the method.Exception
- if the underlying method throws one.public <T> T get(Object receiver, student.testingsupport.reflection.Field<T> field)
T
- The generic parameter T is deduced from the field.receiver
- The object to retrieve the value from.field
- The field to read.public Object get(Object receiver, String field)
receiver
- The object to retrieve the value from.field
- The field to read.public <T> T get(Object receiver, student.testingsupport.reflection.Type<T> type, String field)
T
- The generic parameter T is deduced from the type.receiver
- The object to retrieve the value from.field
- The field to read.type
- The type of the field. The field's value must be assignable
to this type, or a ReflectionError will be thrown.public <T> T get(Object receiver, Class<T> type, String field)
T
- The generic parameter T is deduced from the type.receiver
- The object to retrieve the value from.field
- The field to read.type
- The type of the field. The field's value must be assignable
to this type, or a ReflectionError will be thrown.public <T> void set(Object receiver, student.testingsupport.reflection.Field<T> field, T value)
T
- The generic parameter T is deduced from the field.receiver
- The object to set the value in.field
- The field to store.value
- The value to store in the field.