Package org.jboss.weld.util.reflection
Class Reflections
- java.lang.Object
-
- org.jboss.weld.util.reflection.Reflections
-
public class Reflections extends Object
Utility class for static reflection-type operations- Author:
- Pete Muir, Ales Justin, Marko Luksa
-
-
Field Summary
Fields Modifier and Type Field Description static Annotation[]EMPTY_ANNOTATIONSstatic Class<?>[]EMPTY_CLASSESstatic Type[]EMPTY_TYPES
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Map<Class<?>,Type>buildTypeMap(Set<Type> types)static <T> Tcast(Object obj)static booleancontainsWildcards(Type[] types)static Type[]getActualTypeArguments(Class<?> clazz)Gets the actual type arguments of a classstatic Type[]getActualTypeArguments(Type type)Gets the actual type arguments of a Typestatic Set<Class<?>>getInterfaceClosure(Class<?> clazz)static intgetNesting(Class<?> clazz)static MethodgetNonPrivateNonStaticFinalMethod(Class<?> type)static StringgetPropertyName(Method method)Gets the property name from a getter method.static <T> Class<T>getRawType(Type type)static <T> TinvokeAndUnwrap(Object instance, Method method, Object... parameters)Invokes the method on a given instance passing in given parameters.static booleanisAbstract(Class<?> clazz)static booleanisAbstract(Method method)Checks if a method is abstractstatic booleanisArrayType(Class<?> rawType)Checks if raw type is array typestatic booleanisBindings(Annotation binding)Deprecated.static booleanisCacheable(Annotation[] annotations)static booleanisCacheable(Collection<Annotation> annotations)static booleanisClassLoadable(String className, org.jboss.weld.resources.spi.ResourceLoader resourceLoader)static booleanisFinal(Class<?> clazz)Checks if class is finalstatic booleanisFinal(Member member)Checks if member is finalstatic booleanisPackagePrivate(int mod)static booleanisParameterizedType(Class<?> type)Checks if type is parameterized typestatic booleanisParameterizedTypeWithWildcard(Class<?> type)static booleanisPrimitive(Type type)static booleanisPrivate(Member member)Checks if member is privatestatic booleanisSerializable(Class<?> clazz)static booleanisStatic(Class<?> type)Checks if type is staticstatic booleanisStatic(Member member)Checks if member is staticstatic booleanisStaticNestedClass(Class<?> javaClass)static booleanisTopLevelOrStaticNestedClass(Class<?> javaClass)static booleanisTransient(Member member)static booleanisTypeOrAnyMethodFinal(Class<?> type)Checks if type or member is finalstatic booleanisUnboundedTypeVariable(Type type)static booleanisUnboundedWildcard(Type type)static <T> Class<T>loadClass(String className, org.jboss.weld.resources.spi.ResourceLoader resourceLoader)Tries to load a class using the specified ResourceLoader.static ExceptionunwrapInvocationTargetException(InvocationTargetException e)Unwraps the givenInvocationTargetException.
-
-
-
Field Detail
-
EMPTY_TYPES
public static final Type[] EMPTY_TYPES
-
EMPTY_ANNOTATIONS
public static final Annotation[] EMPTY_ANNOTATIONS
-
EMPTY_CLASSES
public static final Class<?>[] EMPTY_CLASSES
-
-
Method Detail
-
isCacheable
public static boolean isCacheable(Collection<Annotation> annotations)
-
isCacheable
public static boolean isCacheable(Annotation[] annotations)
-
cast
public static <T> T cast(Object obj)
-
getPropertyName
public static String getPropertyName(Method method)
Gets the property name from a getter method. We extend JavaBean conventions, allowing the getter method to have parameters- 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(Class<?> clazz)
Checks if class is final- Parameters:
clazz- The class to check- Returns:
- True if final, false otherwise
-
getNesting
public static int getNesting(Class<?> clazz)
-
isFinal
public static boolean isFinal(Member member)
Checks if member is final- Parameters:
member- The member to check- Returns:
- True if final, false otherwise
-
isPrivate
public static boolean isPrivate(Member member)
Checks if member is private- Parameters:
member- The member to check- Returns:
- True if final, false otherwise
-
isTypeOrAnyMethodFinal
public static boolean isTypeOrAnyMethodFinal(Class<?> type)
Checks if type or member is final- Parameters:
type- Type or member- Returns:
- True if final, false otherwise
-
getNonPrivateNonStaticFinalMethod
public static Method getNonPrivateNonStaticFinalMethod(Class<?> type)
-
isPackagePrivate
public static boolean isPackagePrivate(int mod)
-
isStatic
public static boolean isStatic(Class<?> type)
Checks if type is static- Parameters:
type- Type to check- Returns:
- True if static, false otherwise
-
isStatic
public static boolean isStatic(Member member)
Checks if member is static- Parameters:
member- Member to check- Returns:
- True if static, false otherwise
-
isTransient
public static boolean isTransient(Member member)
-
isAbstract
public static boolean isAbstract(Method method)
Checks if a method is abstract- Parameters:
method- the method- Returns:
- true if abstract
-
isAbstract
public static boolean isAbstract(Class<?> clazz)
-
getActualTypeArguments
public static Type[] getActualTypeArguments(Class<?> clazz)
Gets the actual type arguments of a class- Parameters:
clazz- The class to examine- Returns:
- The type arguments
-
getActualTypeArguments
public static Type[] getActualTypeArguments(Type type)
Gets the actual type arguments of a Type- Parameters:
type- The type to examine- Returns:
- The type arguments
-
isArrayType
public static boolean isArrayType(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(Class<?> type)
Checks if type is parameterized type- Parameters:
type- The type to check- Returns:
- True if parameterized, false otherwise
-
isParameterizedTypeWithWildcard
public static boolean isParameterizedTypeWithWildcard(Class<?> type)
-
containsWildcards
public static boolean containsWildcards(Type[] types)
-
isBindings
@Deprecated public static boolean isBindings(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
-
isSerializable
public static boolean isSerializable(Class<?> clazz)
-
isPrimitive
public static boolean isPrimitive(Type type)
-
isClassLoadable
public static boolean isClassLoadable(String className, org.jboss.weld.resources.spi.ResourceLoader resourceLoader)
-
loadClass
public static <T> Class<T> loadClass(String className, org.jboss.weld.resources.spi.ResourceLoader resourceLoader)
Tries to load a class using the specified ResourceLoader. Returns null if the class is not found.- Parameters:
className-resourceLoader-- Returns:
- the loaded class or null if the given class cannot be loaded
-
isUnboundedWildcard
public static boolean isUnboundedWildcard(Type type)
-
isUnboundedTypeVariable
public static boolean isUnboundedTypeVariable(Type type)
-
isStaticNestedClass
public static boolean isStaticNestedClass(Class<?> javaClass)
- Parameters:
javaClass-- Returns:
trueif the given class is a static nested class,falseotherwise
-
isTopLevelOrStaticNestedClass
public static boolean isTopLevelOrStaticNestedClass(Class<?> javaClass)
- Parameters:
javaClass-- Returns:
trueif the given class is a top-level or static nested class,falseotherwise
-
invokeAndUnwrap
public static <T> T invokeAndUnwrap(Object instance, Method method, Object... parameters) throws Throwable
Invokes the method on a given instance passing in given parameters. If the invocation yieldsInvocationTargetException, the exception is unwrapped. It is a responsibility of the caller to make sure that the method is accessible to the caller.- Throws:
Throwable
-
unwrapInvocationTargetException
public static Exception unwrapInvocationTargetException(InvocationTargetException e) throws Exception
Unwraps the givenInvocationTargetException.ErrorandExceptionare unwrapped right away,Throwableis wrapped withinWeldException. This method never returns - it always throws the unwrapped cause instead. The return type matches the throws part of the signature just to simplify usage.- Parameters:
the- given exception- Returns:
- Throws:
Exception- unwrapped cause ofInvocationTargetException
-
-