org.jboss.weld.util
Class Reflections

java.lang.Object
  extended by org.jboss.weld.util.Reflections

public class Reflections
extends java.lang.Object

Utility class for static reflection-type operations

Author:
Pete Muir

Nested Class Summary
static class Reflections.HierarchyDiscovery
           
 
Field Summary
static java.lang.annotation.Annotation[] EMPTY_ANNOTATIONS
           
static java.lang.reflect.Type[] EMPTY_TYPES
           
 
Constructor Summary
Reflections()
           
 
Method Summary
static boolean containsWildcards(java.lang.reflect.Type[] types)
           
static java.util.Set<java.lang.reflect.Type> createTypeClosure(java.lang.Class<?> rawType, java.lang.reflect.Type[] actualTypeArguments)
           
static
<T> java.lang.reflect.Constructor<T>
ensureAccessible(java.lang.reflect.Constructor<T> constructor)
           
static java.lang.reflect.Field ensureAccessible(java.lang.reflect.Field field)
           
static java.lang.reflect.Method ensureAccessible(java.lang.reflect.Method method)
           
static java.lang.Class<?>[] extractValues(java.lang.annotation.Annotation annotation)
           
static java.lang.reflect.Type[] getActualTypeArguments(java.lang.Class<?> clazz)
          Gets the actual type arguments of a class
static java.lang.Object getAndWrap(java.lang.reflect.Field field, java.lang.Object target)
          Gets value of a field and wraps exceptions
static java.lang.Object getAndWrap(java.lang.String fieldName, java.lang.Object target)
           
static
<T> java.lang.reflect.Constructor<T>
getDeclaredConstructor(java.lang.Class<T> clazz, java.lang.Class<?>... parameterTypes)
          Gets a constructor with matching parameter types
static java.lang.String getPropertyName(java.lang.reflect.Method method)
          Gets the property name from a getter method
static java.lang.Object invokeAndWrap(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object... parameters)
          Invokes a method and wraps exceptions
static java.lang.Object invokeAndWrap(java.lang.String methodName, java.lang.Object instance, java.lang.Object... parameters)
           
static boolean isAbstract(java.lang.Class<?> clazz)
          Checks if clazz is abstract
static boolean isArrayType(java.lang.Class<?> rawType)
          Checks if raw type is array type
static boolean isAssignableFrom(java.lang.Class<?> rawType1, java.lang.reflect.Type[] actualTypeArguments1, java.lang.Class<?> rawType2, java.lang.reflect.Type[] actualTypeArguments2)
          Check the assignability of one type to another, taking into account the actual type arguements
static boolean isAssignableFrom(java.lang.Class<?> rawType1, java.lang.reflect.Type[] actualTypeArguments1, java.lang.reflect.Type type2)
           
static boolean isAssignableFrom(java.util.Set<java.lang.reflect.Type> types1, java.util.Set<java.lang.reflect.Type> types2)
          Check the assiginability of a set of flattened types.
static boolean isAssignableFrom(java.util.Set<java.lang.reflect.Type> types1, java.lang.reflect.Type type2)
          Check the assiginability of a set of flattened types.
static boolean isAssignableFrom(java.lang.reflect.Type[] types1, java.lang.reflect.Type type2)
           
static boolean isAssignableFrom(java.lang.reflect.Type[] actualTypeArguments1, java.lang.reflect.Type[] actualTypeArguments2)
           
static boolean isAssignableFrom(java.lang.reflect.Type type1, java.util.Set<? extends java.lang.reflect.Type> types2)
           
static boolean isAssignableFrom(java.lang.reflect.Type type1, java.lang.reflect.Type type2)
           
static boolean isAssignableFrom(java.lang.reflect.Type type1, java.lang.reflect.Type[] types2)
           
static boolean isBindings(java.lang.annotation.Annotation binding)
          Deprecated. 
static boolean isFinal(java.lang.Class<?> clazz)
          Checks if class is final
static boolean isFinal(java.lang.reflect.Member member)
          Checks if member is final
static boolean isNonStaticInnerClass(java.lang.Class<?> clazz)
          Checks if class is a non-static inner one
static boolean isPackagePrivate(int mod)
           
static boolean isParamerterizedTypeWithWildcard(java.lang.Class<?> type)
           
static boolean isParameterizedType(java.lang.Class<?> type)
          Checks if type is parameterized type
static boolean isPrimitive(java.lang.Class<?> type)
          Checks if type is primitive
static boolean isSerializable(java.lang.Class<?> clazz)
           
static boolean isStatic(java.lang.Class<?> type)
          Checks if type is static
static boolean isStatic(java.lang.reflect.Member member)
          Checks if member is static
static boolean isTransient(java.lang.reflect.Member member)
           
static boolean isTypeBounded(java.lang.reflect.Type type, java.lang.reflect.Type[] lowerBounds, java.lang.reflect.Type[] upperBounds)
           
static boolean isTypeOrAnyMethodFinal(java.lang.Class<?> type)
          Checks if type or member is final
static java.lang.reflect.Method lookupMethod(java.lang.reflect.Method method, java.lang.Object instance)
          Looks up a method in the type hierarchy of an instance
static java.lang.reflect.Method lookupMethod(java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object instance)
          Looks up a method in the type hierarchy of an instance
static boolean matches(java.lang.Class<?> rawType1, java.lang.reflect.Type[] actualTypeArguments1, java.lang.Class<?> rawType2, java.lang.reflect.Type[] actualTypeArguments2)
           
static boolean matches(java.lang.Class<?> rawType1, java.lang.reflect.Type[] actualTypeArguments1, java.lang.reflect.Type type2)
           
static boolean matches(java.util.Set<java.lang.reflect.Type> types1, java.util.Set<java.lang.reflect.Type> types2)
          Check whether whether any of the types1 matches a type in types2
static boolean matches(java.lang.reflect.Type type1, java.util.Set<? extends java.lang.reflect.Type> types2)
           
static boolean matches(java.lang.reflect.Type type1, java.lang.reflect.Type type2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_TYPES

public static final java.lang.reflect.Type[] EMPTY_TYPES

EMPTY_ANNOTATIONS

public static final java.lang.annotation.Annotation[] EMPTY_ANNOTATIONS
Constructor Detail

Reflections

public Reflections()
Method Detail

getPropertyName

public static java.lang.String getPropertyName(java.lang.reflect.Method method)
Gets the property name from a getter method

Parameters:
method - The getter method
Returns:
The name of the property. Returns null if method wasn't JavaBean getter-styled

isFinal

public static boolean isFinal(java.lang.Class<?> clazz)
Checks if class is final

Parameters:
clazz - The class to check
Returns:
True if final, false otherwise

isFinal

public static boolean isFinal(java.lang.reflect.Member member)
Checks if member is final

Parameters:
member - The member to check
Returns:
True if final, false otherwise

isTypeOrAnyMethodFinal

public static boolean isTypeOrAnyMethodFinal(java.lang.Class<?> type)
Checks if type or member is final

Parameters:
type - Type or member
Returns:
True if final, false otherwise

isPrimitive

public static boolean isPrimitive(java.lang.Class<?> type)
Checks if type is primitive

Parameters:
type - Type to check
Returns:
True if primitive, false otherwise

isPackagePrivate

public static boolean isPackagePrivate(int mod)

isStatic

public static boolean isStatic(java.lang.Class<?> type)
Checks if type is static

Parameters:
type - Type to check
Returns:
True if static, false otherwise

isStatic

public static boolean isStatic(java.lang.reflect.Member member)
Checks if member is static

Parameters:
member - Member to check
Returns:
True if static, false otherwise

isTransient

public static boolean isTransient(java.lang.reflect.Member member)

isAbstract

public static boolean isAbstract(java.lang.Class<?> clazz)
Checks if clazz is abstract

Parameters:
clazz - Class to check
Returns:
True if abstract, false otherwise

isNonStaticInnerClass

public static boolean isNonStaticInnerClass(java.lang.Class<?> clazz)
Checks if class is a non-static inner one

Parameters:
clazz - Class to Check
Returns:
True if static, false otherwise

getDeclaredConstructor

public static <T> java.lang.reflect.Constructor<T> getDeclaredConstructor(java.lang.Class<T> clazz,
                                                                          java.lang.Class<?>... parameterTypes)
Gets a constructor with matching parameter types

Type Parameters:
T - The type
Parameters:
clazz - The class
parameterTypes - The parameter types
Returns:
The matching constructor. Null is returned if none is found

getActualTypeArguments

public static java.lang.reflect.Type[] getActualTypeArguments(java.lang.Class<?> clazz)
Gets the actual type arguments of a class

Parameters:
clazz - The class to examine
Returns:
The type arguments

isArrayType

public static boolean isArrayType(java.lang.Class<?> rawType)
Checks if raw type is array type

Parameters:
rawType - The raw type to check
Returns:
True if array, false otherwise

isParameterizedType

public static boolean isParameterizedType(java.lang.Class<?> type)
Checks if type is parameterized type

Parameters:
type - The type to check
Returns:
True if parameterized, false otherwise

isParamerterizedTypeWithWildcard

public static boolean isParamerterizedTypeWithWildcard(java.lang.Class<?> type)

containsWildcards

public static boolean containsWildcards(java.lang.reflect.Type[] types)

createTypeClosure

public static java.util.Set<java.lang.reflect.Type> createTypeClosure(java.lang.Class<?> rawType,
                                                                      java.lang.reflect.Type[] actualTypeArguments)

invokeAndWrap

public static java.lang.Object invokeAndWrap(java.lang.reflect.Method method,
                                             java.lang.Object instance,
                                             java.lang.Object... parameters)
Invokes a method and wraps exceptions

Parameters:
method - The method to invoke
instance - The instance to invoke on
parameters - The parameters
Returns:
The return value

invokeAndWrap

public static java.lang.Object invokeAndWrap(java.lang.String methodName,
                                             java.lang.Object instance,
                                             java.lang.Object... parameters)

getAndWrap

public static java.lang.Object getAndWrap(java.lang.reflect.Field field,
                                          java.lang.Object target)
Gets value of a field and wraps exceptions

Parameters:
field - The field to set on
target - The instance to set on
Returns:
The value to set

getAndWrap

public static java.lang.Object getAndWrap(java.lang.String fieldName,
                                          java.lang.Object target)

lookupMethod

public static java.lang.reflect.Method lookupMethod(java.lang.reflect.Method method,
                                                    java.lang.Object instance)
Looks up a method in the type hierarchy of an instance

Parameters:
method - The method to look for
instance - The instance to start from
Returns:
The method found
Throws:
java.lang.IllegalArgumentException - if the method is not found

lookupMethod

public static java.lang.reflect.Method lookupMethod(java.lang.String methodName,
                                                    java.lang.Class<?>[] parameterTypes,
                                                    java.lang.Object instance)
                                             throws java.lang.NoSuchMethodException
Looks up a method in the type hierarchy of an instance

Parameters:
method - The method to look for
instance - The instance to start from
Returns:
the method
Throws:
java.lang.NoSuchMethodException - if the method is not found

isBindings

@Deprecated
public static boolean isBindings(java.lang.annotation.Annotation binding)
Deprecated. 

Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.

Parameters:
binding - The binding type to check
Returns:
true only if the annotation is really a binding type

isAssignableFrom

public static boolean isAssignableFrom(java.lang.Class<?> rawType1,
                                       java.lang.reflect.Type[] actualTypeArguments1,
                                       java.lang.Class<?> rawType2,
                                       java.lang.reflect.Type[] actualTypeArguments2)
Check the assignability of one type to another, taking into account the actual type arguements

Parameters:
rawType1 - the raw type of the class to check
actualTypeArguments1 - the actual type arguements to check, or an empty array if not a parameterized type
rawType2 - the raw type of the class to check
actualTypeArguments2 - the actual type arguements to check, or an empty array if not a parameterized type
Returns:

matches

public static boolean matches(java.lang.Class<?> rawType1,
                              java.lang.reflect.Type[] actualTypeArguments1,
                              java.lang.Class<?> rawType2,
                              java.lang.reflect.Type[] actualTypeArguments2)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.reflect.Type[] actualTypeArguments1,
                                       java.lang.reflect.Type[] actualTypeArguments2)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.reflect.Type type1,
                                       java.util.Set<? extends java.lang.reflect.Type> types2)

matches

public static boolean matches(java.lang.reflect.Type type1,
                              java.util.Set<? extends java.lang.reflect.Type> types2)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.reflect.Type type1,
                                       java.lang.reflect.Type[] types2)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.reflect.Type type1,
                                       java.lang.reflect.Type type2)

matches

public static boolean matches(java.lang.reflect.Type type1,
                              java.lang.reflect.Type type2)

isTypeBounded

public static boolean isTypeBounded(java.lang.reflect.Type type,
                                    java.lang.reflect.Type[] lowerBounds,
                                    java.lang.reflect.Type[] upperBounds)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.Class<?> rawType1,
                                       java.lang.reflect.Type[] actualTypeArguments1,
                                       java.lang.reflect.Type type2)

matches

public static boolean matches(java.lang.Class<?> rawType1,
                              java.lang.reflect.Type[] actualTypeArguments1,
                              java.lang.reflect.Type type2)

isAssignableFrom

public static boolean isAssignableFrom(java.util.Set<java.lang.reflect.Type> types1,
                                       java.util.Set<java.lang.reflect.Type> types2)
Check the assiginability of a set of flattened types. This algorithm will check whether any of the types1 matches a type in types2

Parameters:
types1 -
types2 -
Returns:

matches

public static boolean matches(java.util.Set<java.lang.reflect.Type> types1,
                              java.util.Set<java.lang.reflect.Type> types2)
Check whether whether any of the types1 matches a type in types2

Parameters:
types1 -
types2 -
Returns:

isAssignableFrom

public static boolean isAssignableFrom(java.util.Set<java.lang.reflect.Type> types1,
                                       java.lang.reflect.Type type2)
Check the assiginability of a set of flattened types. This algorithm will check whether any of the types1 matches a type in types2

Parameters:
types1 -
types2 -
Returns:

isAssignableFrom

public static boolean isAssignableFrom(java.lang.reflect.Type[] types1,
                                       java.lang.reflect.Type type2)

isSerializable

public static boolean isSerializable(java.lang.Class<?> clazz)

ensureAccessible

public static java.lang.reflect.Field ensureAccessible(java.lang.reflect.Field field)

ensureAccessible

public static java.lang.reflect.Method ensureAccessible(java.lang.reflect.Method method)

ensureAccessible

public static <T> java.lang.reflect.Constructor<T> ensureAccessible(java.lang.reflect.Constructor<T> constructor)

extractValues

public static java.lang.Class<?>[] extractValues(java.lang.annotation.Annotation annotation)


Copyright © 2008-2009 Seam Framework. All Rights Reserved.