|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectconsciouscode.util.ReflectionUtils
public class ReflectionUtils
Utility methods for simplifying reflective operations.
Field Summary | |
---|---|
static Class<?>[] |
NO_PARAMETERS
|
Constructor Summary | |
---|---|
ReflectionUtils()
|
Method Summary | |
---|---|
static boolean |
constructorIsApplicable(Constructor<?> ctor,
Class<?>[] paramTypes)
|
static String |
describeParameters(Class<?>[] parameterTypes)
|
static void |
describeParameters(StringBuilder buffer,
Class<?>... parameterTypes)
|
static String |
describeType(Class<?> type)
Ensures a friendly representation of a Java type. |
static void |
describeType(StringBuilder buffer,
Class<?> type)
Renders a friendly representation of a Java type into a buffer. |
static String |
describeTypeOfValue(Object value)
Ensures a visible representation of a value. |
static void |
describeTypeOfValue(StringBuilder buffer,
Object value)
Renders a friendly representation of a value's type into a buffer. |
static void |
ensureNoCheckedExceptions(Method method)
Checks that a method throws no checked exception. |
static void |
ensurePublic(Method method)
Check that a method is public. |
static Method |
getMethod(Class<?> targetClass,
String methodName)
Gets the reflection of a specified no-argument method. |
static Method |
getMethod(Class<?> targetClass,
String methodName,
Class<?>[] parameterTypes)
Get the reflection of a specified method. |
static Object |
invokeSafeMethod(Object object,
Method method)
Invoke a no-argument method that is known to be safe. |
static Object |
invokeSafeMethod(Object object,
Method method,
Object[] arguments)
Invokes a method that is known to be safe. |
static boolean |
methodIsApplicable(Method method,
Class<?>[] paramTypes)
|
static boolean |
parametersAreApplicable(Class<?>[] declaredParamTypes,
Class<?>[] actualParamTypes)
Determines whether certain actual parameter types are applicable to certain declared parameter types. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Class<?>[] NO_PARAMETERS
Constructor Detail |
---|
public ReflectionUtils()
Method Detail |
---|
public static String describeType(Class<?> type)
Class.getName()
, but without its
clumsy internal notation for arrays: instead of (for example)
the string "[B"
this method returns the string "byte[]"
.
type
- the type to describe. If null, this method returns the
string "null"
.
public static void describeType(StringBuilder buffer, Class<?> type)
Class.getName()
, but without its
clumsy internal notation for arrays: instead of (for example)
the string "[B"
this method appends the string "byte[]"
.
buffer
- must not be null
.type
- the type to describe. If null, this method appends the
string "null"
.public static String describeTypeOfValue(Object value)
"null"
, otherwise passes the object's
class to describeType(Class)
.
value
- may be null.
describeType(Class)
public static void describeTypeOfValue(StringBuilder buffer, Object value)
"null"
, otherwise
appends the object's type as per describeType(Class)
.
buffer
- must not be null
.value
- may be null.describeType(Class)
public static Method getMethod(Class<?> targetClass, String methodName, Class<?>[] parameterTypes)
IllegalArgumentException
- if the requested method does not
exist.public static void describeParameters(StringBuilder buffer, Class<?>... parameterTypes)
public static String describeParameters(Class<?>[] parameterTypes)
public static Method getMethod(Class<?> targetClass, String methodName)
getMethod(Class, String, Class[])
IllegalArgumentException
- if the requested method does not
exist.public static void ensureNoCheckedExceptions(Method method)
IllegalArgumentException
- if method
throws an
exception that must be declared.public static void ensurePublic(Method method)
IllegalArgumentException
- if method
is not public.public static boolean constructorIsApplicable(Constructor<?> ctor, Class<?>[] paramTypes)
public static boolean methodIsApplicable(Method method, Class<?>[] paramTypes)
public static boolean parametersAreApplicable(Class<?>[] declaredParamTypes, Class<?>[] actualParamTypes)
It would be nice to use ClassUtils from Apache Commons Lang, but that doesn't seem to handle boxing/unboxing conversions.
public static Object invokeSafeMethod(Object object, Method method, Object[] arguments)
RuntimeException
or Error
) that are
raised by the method invocation.
RuntimeException
- if the method is not accessible, or if it
throws a checked exception.public static Object invokeSafeMethod(Object object, Method method)
invokeSafeMethod(Object, Method, Object[])
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |