org.spockframework.util
Class ReflectionUtil

java.lang.Object
  extended by org.spockframework.util.ReflectionUtil

public abstract class ReflectionUtil
extends java.lang.Object


Constructor Summary
ReflectionUtil()
           
 
Method Summary
static java.io.File getClassFile(java.lang.Class<?> clazz)
          Returns the class file for the given class (which has been verified to exist in the returned location), or null if the class file could not be found (e.g.
static java.lang.reflect.Method getDeclaredMethodByName(java.lang.Class<?> clazz, java.lang.String name)
           
static java.lang.reflect.Method getDeclaredMethodBySignature(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)
           
static java.lang.Object getDefaultValue(java.lang.Class<?> type)
           
static java.lang.reflect.Method getMethodByName(java.lang.Class<?> clazz, java.lang.String name)
          Finds a public method with the given name declared in the given class/interface or one of its super classes/interfaces.
static java.lang.reflect.Method getMethodBySignature(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)
           
static java.lang.String getPropertyNameForGetterMethod(java.lang.reflect.Method method)
          Checks if the given method is a getter method according to Groovy rules.
static java.lang.String getSourceCode(java.lang.String packageName, java.lang.String filename)
          Returns the contents of the file in which the given class is declared, or null if the file cannot be found;
static java.lang.Class[] getTypes(java.lang.Object... objects)
           
static boolean hasAnyOfTypes(java.lang.Object value, java.lang.Class<?>... types)
           
static java.lang.Object invokeMethod(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object... args)
           
static boolean isAnnotationPresent(java.lang.reflect.AnnotatedElement element, java.lang.String className)
           
static boolean isClassAvailable(java.lang.String className)
           
static boolean isMethodAvailable(java.lang.String className, java.lang.String methodName)
           
static java.lang.Class<?> loadClassIfAvailable(java.lang.String className)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

loadClassIfAvailable

public static java.lang.Class<?> loadClassIfAvailable(java.lang.String className)

isClassAvailable

public static boolean isClassAvailable(java.lang.String className)

isMethodAvailable

public static boolean isMethodAvailable(java.lang.String className,
                                        java.lang.String methodName)

isAnnotationPresent

public static boolean isAnnotationPresent(java.lang.reflect.AnnotatedElement element,
                                          java.lang.String className)

getMethodByName

public static java.lang.reflect.Method getMethodByName(java.lang.Class<?> clazz,
                                                       java.lang.String name)
Finds a public method with the given name declared in the given class/interface or one of its super classes/interfaces. If multiple such methods exists, it is undefined which one is returned.


getDeclaredMethodByName

public static java.lang.reflect.Method getDeclaredMethodByName(java.lang.Class<?> clazz,
                                                               java.lang.String name)

getMethodBySignature

public static java.lang.reflect.Method getMethodBySignature(java.lang.Class<?> clazz,
                                                            java.lang.String name,
                                                            java.lang.Class<?>... parameterTypes)

getDeclaredMethodBySignature

public static java.lang.reflect.Method getDeclaredMethodBySignature(java.lang.Class<?> clazz,
                                                                    java.lang.String name,
                                                                    java.lang.Class<?>... parameterTypes)

getClassFile

public static java.io.File getClassFile(java.lang.Class<?> clazz)
Returns the class file for the given class (which has been verified to exist in the returned location), or null if the class file could not be found (e.g. because it is contained in a Jar).


getSourceCode

public static java.lang.String getSourceCode(java.lang.String packageName,
                                             java.lang.String filename)
                                      throws java.io.IOException
Returns the contents of the file in which the given class is declared, or null if the file cannot be found;

Throws:
java.io.IOException

getDefaultValue

public static java.lang.Object getDefaultValue(java.lang.Class<?> type)

getPropertyNameForGetterMethod

public static java.lang.String getPropertyNameForGetterMethod(java.lang.reflect.Method method)
Checks if the given method is a getter method according to Groovy rules. If yes, the corresponding property name is returned. Otherwise, null is returned. This method differs from Groovy 1.6.8 in that the latter doesn't support the "is" prefix for static boolean properties; however, that seems more like a bug. See http://jira.codehaus.org/browse/GROOVY-4206


hasAnyOfTypes

public static boolean hasAnyOfTypes(java.lang.Object value,
                                    java.lang.Class<?>... types)

getTypes

public static java.lang.Class[] getTypes(java.lang.Object... objects)

invokeMethod

public static java.lang.Object invokeMethod(java.lang.Object target,
                                            java.lang.reflect.Method method,
                                            java.lang.Object... args)


Copyright © 2013. All rights reserved