net.sf.oval.internal.util
Class ReflectionUtils

java.lang.Object
  extended by net.sf.oval.internal.util.ReflectionUtils

public final class ReflectionUtils
extends Object

Author:
Sebastian Thomschke

Method Summary
static void assertPrivateAccessAllowed()
           
static Annotation[] getAnnotations(Class<?> clazz, boolean inspectInterfaces)
          Returns all annotations present on this class.
static Annotation[] getAnnotations(Method method, boolean inspectInterfaces)
          Returns all annotations present on this method.
static Field getField(Class<?> clazz, String fieldName)
           
static Field getFieldForSetter(Method setter)
           
static Field getFieldRecursive(Class<?> clazz, String fieldName)
           
static Object getFieldValue(Field field, Object target)
           
static Method getGetter(Class<?> clazz, String propertyName)
           
static Method getGetterRecursive(Class<?> clazz, String propertyName)
           
static List<Method> getInterfaceMethods(Method method)
           
static Set<Class<?>> getInterfacesRecursive(Class<?> clazz)
           
static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
           
static Method getMethodRecursive(Class<?> clazz, String methodName, Class<?>... parameterTypes)
           
static Annotation[][] getParameterAnnotations(Method method, boolean inspectInterfaces)
          Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this method.
static Method getSetter(Class<?> clazz, String propertyName)
           
static Method getSetterRecursive(Class<?> clazz, String propertyName)
           
static Method getSuperMethod(Method method)
           
static String guessFieldName(Method getter)
           
static boolean hasField(Class<?> clazz, String fieldName)
           
static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
           
static
<T> T
invokeMethod(Method method, Object obj, Object... args)
           
static boolean isAnnotationPresent(Method method, Class<? extends Annotation> annotationClass, boolean inspectInterfaces)
          Returns true if an annotation for the specified type is present on this method, else false.
static boolean isClassPresent(String className)
           
static boolean isFinal(Member member)
           
static boolean isGetter(Method method)
          determines if a method is a JavaBean style getter method
static boolean isNonStaticInnerClass(Class<?> clazz)
           
static boolean isPackage(Member member)
           
static boolean isPrivate(Member member)
           
static boolean isPrivateAccessAllowed()
           
static boolean isProtected(Member member)
           
static boolean isPublic(Member member)
           
static boolean isSetter(Method method)
          determines if a method is a JavaBean style setter method
static boolean isStatic(Member member)
           
static boolean isTransient(Member member)
           
static boolean isVoidMethod(Method method)
          determines if a method is a void method
static boolean setViaSetter(Object target, String propertyName, Object propertyValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

assertPrivateAccessAllowed

public static void assertPrivateAccessAllowed()
Throws:
SecurityException

getAnnotations

public static Annotation[] getAnnotations(Class<?> clazz,
                                          boolean inspectInterfaces)
Returns all annotations present on this class.

Parameters:
clazz - the class to inspect
inspectInterfaces - whether to also return annotations declared on interface declaration
Returns:
all annotations present on this class.

getAnnotations

public static Annotation[] getAnnotations(Method method,
                                          boolean inspectInterfaces)
Returns all annotations present on this method.

Parameters:
method - the method to inspect
inspectInterfaces - whether to also return annotations declared on interface method declaration
Returns:
all annotations present on this method.

getField

public static Field getField(Class<?> clazz,
                             String fieldName)
Returns:
the field or null if the field does not exist

getFieldForSetter

public static Field getFieldForSetter(Method setter)
Parameters:
setter -
Returns:
the corresponding field for a setter method. Returns null if the method is not a JavaBean style setter or the field could not be located.

getFieldRecursive

public static Field getFieldRecursive(Class<?> clazz,
                                      String fieldName)

getFieldValue

public static Object getFieldValue(Field field,
                                   Object target)
                            throws AccessingFieldValueFailedException
Throws:
AccessingFieldValueFailedException

getGetter

public static Method getGetter(Class<?> clazz,
                               String propertyName)

getGetterRecursive

public static Method getGetterRecursive(Class<?> clazz,
                                        String propertyName)

getInterfaceMethods

public static List<Method> getInterfaceMethods(Method method)

getInterfacesRecursive

public static Set<Class<?>> getInterfacesRecursive(Class<?> clazz)
Parameters:
clazz - the class to inspect
Returns:
a set with all implemented interfaces

getMethod

public static Method getMethod(Class<?> clazz,
                               String methodName,
                               Class<?>... parameterTypes)
Returns:
the method or null if the method does not exist

getMethodRecursive

public static Method getMethodRecursive(Class<?> clazz,
                                        String methodName,
                                        Class<?>... parameterTypes)
Returns:
the method or null if the method does not exist

getParameterAnnotations

public static Annotation[][] getParameterAnnotations(Method method,
                                                     boolean inspectInterfaces)
Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this method.

Parameters:
method - the method to inspect
inspectInterfaces - whether to also return annotations declared on interface method declaration
Returns:
an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this method.

getSetter

public static Method getSetter(Class<?> clazz,
                               String propertyName)

getSetterRecursive

public static Method getSetterRecursive(Class<?> clazz,
                                        String propertyName)

getSuperMethod

public static Method getSuperMethod(Method method)

guessFieldName

public static String guessFieldName(Method getter)

hasField

public static boolean hasField(Class<?> clazz,
                               String fieldName)

hasMethod

public static boolean hasMethod(Class<?> clazz,
                                String methodName,
                                Class<?>... parameterTypes)

invokeMethod

public static <T> T invokeMethod(Method method,
                                 Object obj,
                                 Object... args)
                      throws InvokingMethodFailedException,
                             ConstraintsViolatedException
Parameters:
method - the method to invoke
obj - the object on which to invoke the method
args - the method arguments
Returns:
the return value of the invoked method
Throws:
InvokingMethodFailedException
ConstraintsViolatedException

isAnnotationPresent

public static boolean isAnnotationPresent(Method method,
                                          Class<? extends Annotation> annotationClass,
                                          boolean inspectInterfaces)
Returns true if an annotation for the specified type is present on this method, else false.

Parameters:
method - the method to inspect
annotationClass - the Class object corresponding to the annotation type
inspectInterfaces - whether to also check annotations declared on interface method declaration
Returns:
true if an annotation for the specified annotation type is present on this method, else false

isClassPresent

public static boolean isClassPresent(String className)

isFinal

public static boolean isFinal(Member member)

isGetter

public static boolean isGetter(Method method)
determines if a method is a JavaBean style getter method


isNonStaticInnerClass

public static boolean isNonStaticInnerClass(Class<?> clazz)

isPackage

public static boolean isPackage(Member member)

isPrivate

public static boolean isPrivate(Member member)

isPrivateAccessAllowed

public static boolean isPrivateAccessAllowed()

isProtected

public static boolean isProtected(Member member)

isPublic

public static boolean isPublic(Member member)

isSetter

public static boolean isSetter(Method method)
determines if a method is a JavaBean style setter method


isStatic

public static boolean isStatic(Member member)

isTransient

public static boolean isTransient(Member member)

isVoidMethod

public static boolean isVoidMethod(Method method)
determines if a method is a void method


setViaSetter

public static boolean setViaSetter(Object target,
                                   String propertyName,
                                   Object propertyValue)


Copyright © 2005–2015 The OVal Development Team. All rights reserved.