org.apache.webbeans.util
Class ClassUtil

java.lang.Object
  extended by org.apache.webbeans.util.ClassUtil

public final class ClassUtil
extends Object

Utility classes with respect to the class operations.

Since:
1.0
Author:
Gurkan Erdogdu

Field Summary
static Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
           
 
Method Summary
static Object callInstanceMethod(Method method, Object instance, Object[] args)
          Call method on the instance with given arguments.
static boolean checkBeanAndRequiredTypeIsParametrized(Type beanTypeArg, Type requiredTypeArg)
          Check parametrized bean type and parametrized required types.
static boolean checkBeanTypeAndRequiredIsTypeVariable(Type beanTypeArg, Type requiredTypeArg)
           
static boolean checkEventTypeAssignability(Type eventType, Type observerType)
          Checks that event is applicable for the given observer type.
static boolean checkParametrizedType(ParameterizedType pType)
          Return true if it does not contain type variable for wildcard type false otherwise.
static boolean checkRequiredTypeIsClassAndBeanTypeIsVariable(Type beanTypeArg, Type requiredTypeArg)
          Checking bean type and required type.
static boolean checkRequiredTypeIsParameterizedAndBeanTypeIsVariable(Type beanTypeArg, Type requiredTypeArg)
           
static boolean checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(Type beanTypeArg, Type requiredTypeArg)
           
static boolean checkRequiredTypeIsWildCard(Type beanTypeArg, Type requiredTypeArg)
          Check bean type and required type.
static Type[] getActualTypeArguments(Type type)
          Returns declared type arguments if type is a ParameterizedType instance, else an empty array.
static Class<?> getClass(Type type)
          Gets the class of the given type arguments.
static Class<?> getClassFromName(String name)
           
static Class<?> getClazz(Type type)
          Return raw class type for given type.
static List<Method> getNonPrivateMethods(Class<?> topClass, boolean excludeFinalMethods)
          collect all non-private, non-static and non-abstract methods from the given class.
static Class<?> getPrimitiveWrapper(Class<?> clazz)
           
static Class<?> getRawTypeForInjectionPoint(InjectionPoint injectionPoint)
          Returns injection point raw type.
static boolean isAssignableForParametrized(ParameterizedType beanType, ParameterizedType requiredType)
          Returns true if given bean's api type is injectable to injection point required type.
static boolean isClassAssignable(Class<?> lhs, Class<?> rhs)
          Returns true if rhs is assignable type to the lhs, false otherwise.
static boolean isConcrete(Class<?> clazz)
          Returna true if the class is not abstract and interface.
static boolean isDefinitionContainsTypeVariables(Type type)
          Learn whether the specified class is defined with type parameters.
static boolean isInnerClazz(Class<?> clazz)
          Check the class is inner or not
static boolean isMethodHasCheckedException(Method method)
          Check method throws checked exception or not.
static boolean isObjectMethod(String methodName)
          Checks if the given method if from Object.class
static boolean isOverridden(List<Method> subclassMethods, Method superclassMethod)
          Check if the method is already defined in a subclass
static boolean isOverridden(Method subClassMethod, Method superClassMethod)
          Check whether superClassMethod is overridden by subClassMethod.
static boolean isParametrizedType(Type type)
          Returns true if type is an instance of ParameterizedType else otherwise.
static boolean isSame(Type type1, Type type2)
           
static boolean isTypeVariable(Type type)
          Returns true if type is an instance of TypeVariable else otherwise.
static boolean isUnboundedTypeVariable(Type type)
           
static boolean isWildCardType(Type type)
          Returns true if type is an instance of WildcardType else otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIMITIVE_TO_WRAPPERS_MAP

public static final Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
Method Detail

getClassFromName

public static Class<?> getClassFromName(String name)

isInnerClazz

public static boolean isInnerClazz(Class<?> clazz)
Check the class is inner or not

Parameters:
clazz - to check
Returns:
true or false

isSame

public static boolean isSame(Type type1,
                             Type type2)

getPrimitiveWrapper

public static Class<?> getPrimitiveWrapper(Class<?> clazz)

getClass

public static Class<?> getClass(Type type)
Gets the class of the given type arguments.

If the given type Type parameters is an instance of the ParameterizedType, it returns the raw type otherwise it return the casted Class of the type argument.

Parameters:
type - class or parametrized type
Returns:

isMethodHasCheckedException

public static boolean isMethodHasCheckedException(Method method)
Check method throws checked exception or not.

Parameters:
method - method instance

callInstanceMethod

public static Object callInstanceMethod(Method method,
                                        Object instance,
                                        Object[] args)
Call method on the instance with given arguments.

Parameters:
method - method instance
instance - object instance
args - arguments
Returns:
the method result

getNonPrivateMethods

public static List<Method> getNonPrivateMethods(Class<?> topClass,
                                                boolean excludeFinalMethods)
collect all non-private, non-static and non-abstract methods from the given class. This method removes any overloaded methods from the list automatically. We also do skip bridge methods as they exist for and are handled solely by the JVM itself. The returned Map contains the methods divided by the methodName as key in the map following all the methods with the same methodName in a List. There is some special rule for package-private methods. Any non-visible package-private method will get skipped and treated similarly to private methods. Note: we filter out the Object.finalize() method as users must not deal with it.

Parameters:
topClass - the class to start with. Then move up the hierarchy
excludeFinalMethods - whether final classes should get excluded from the result

isOverridden

public static boolean isOverridden(List<Method> subclassMethods,
                                   Method superclassMethod)
Check if the method is already defined in a subclass

Parameters:
subclassMethods -
superclassMethod -

isObjectMethod

public static boolean isObjectMethod(String methodName)
Checks if the given method if from Object.class

Parameters:
methodName -
Returns:
true if the given method is from Object.class (either directly or overloaded)

isParametrizedType

public static boolean isParametrizedType(Type type)
Returns true if type is an instance of ParameterizedType else otherwise.

Parameters:
type - type of the artifact
Returns:
true if type is an instance of ParameterizedType

isWildCardType

public static boolean isWildCardType(Type type)
Returns true if type is an instance of WildcardType else otherwise.

Parameters:
type - type of the artifact
Returns:
true if type is an instance of WildcardType

isUnboundedTypeVariable

public static boolean isUnboundedTypeVariable(Type type)

isTypeVariable

public static boolean isTypeVariable(Type type)
Returns true if type is an instance of TypeVariable else otherwise.

Parameters:
type - type of the artifact
Returns:
true if type is an instance of TypeVariable

isConcrete

public static boolean isConcrete(Class<?> clazz)
Returna true if the class is not abstract and interface.

Parameters:
clazz - class type
Returns:
true if the class is not abstract and interface

checkEventTypeAssignability

public static boolean checkEventTypeAssignability(Type eventType,
                                                  Type observerType)
Checks that event is applicable for the given observer type.

Parameters:
eventType - event type
observerType - observer type
Returns:
true if event is applicable

isClassAssignable

public static boolean isClassAssignable(Class<?> lhs,
                                        Class<?> rhs)
Returns true if rhs is assignable type to the lhs, false otherwise.

Parameters:
lhs - left hand side class
rhs - right hand side class
Returns:
true if rhs is assignable to lhs

isAssignableForParametrized

public static boolean isAssignableForParametrized(ParameterizedType beanType,
                                                  ParameterizedType requiredType)
Returns true if given bean's api type is injectable to injection point required type.

Parameters:
beanType - bean parametrized api type
requiredType - injection point parametrized api type
Returns:
if injection is possible false otherwise

checkBeanAndRequiredTypeIsParametrized

public static boolean checkBeanAndRequiredTypeIsParametrized(Type beanTypeArg,
                                                             Type requiredTypeArg)
Check parametrized bean type and parametrized required types.

Parameters:
beanTypeArg - parametrized bean type
requiredTypeArg - parametrized required type
Returns:
true if types are assignables
Since:
1.1.1

checkRequiredTypeIsWildCard

public static boolean checkRequiredTypeIsWildCard(Type beanTypeArg,
                                                  Type requiredTypeArg)
Check bean type and required type.

Required type is a wildcard type.

Parameters:
beanTypeArg - bean type
requiredTypeArg - required type
Returns:
true if condition satisfies
Since:
1.1.1

checkRequiredTypeIsClassAndBeanTypeIsVariable

public static boolean checkRequiredTypeIsClassAndBeanTypeIsVariable(Type beanTypeArg,
                                                                    Type requiredTypeArg)
Checking bean type and required type.

Required type is class and bean type is a type variable.

Parameters:
beanTypeArg - bean type
requiredTypeArg - required type
Returns:
true if condition satisfy

checkRequiredTypeIsParameterizedAndBeanTypeIsVariable

public static boolean checkRequiredTypeIsParameterizedAndBeanTypeIsVariable(Type beanTypeArg,
                                                                            Type requiredTypeArg)

checkRequiredTypeIsTypeVariableAndBeanTypeIsClass

public static boolean checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(Type beanTypeArg,
                                                                        Type requiredTypeArg)

checkBeanTypeAndRequiredIsTypeVariable

public static boolean checkBeanTypeAndRequiredIsTypeVariable(Type beanTypeArg,
                                                             Type requiredTypeArg)

isDefinitionContainsTypeVariables

public static boolean isDefinitionContainsTypeVariables(Type type)
Learn whether the specified class is defined with type parameters.

Parameters:
type - to check
Returns:
true if there are type parameters
Since:
1.1.1

getActualTypeArguments

public static Type[] getActualTypeArguments(Type type)
Returns declared type arguments if type is a ParameterizedType instance, else an empty array. Get the actual type arguments of a type.

Parameters:
type -
Returns:
array of type arguments available
Since:
1.1.1

getClazz

public static Class<?> getClazz(Type type)
Return raw class type for given type.

Parameters:
type - base type instance
Returns:
class type for given type

checkParametrizedType

public static boolean checkParametrizedType(ParameterizedType pType)
Return true if it does not contain type variable for wildcard type false otherwise.

Parameters:
pType - parameterized type
Returns:
true if it does not contain type variable for wildcard type

getRawTypeForInjectionPoint

public static Class<?> getRawTypeForInjectionPoint(InjectionPoint injectionPoint)
Returns injection point raw type.

Parameters:
injectionPoint - injection point definition
Returns:
injection point raw type

isOverridden

public static boolean isOverridden(Method subClassMethod,
                                   Method superClassMethod)
Check whether superClassMethod is overridden by subClassMethod.

Parameters:
subClassMethod - potentially overriding
superClassMethod - potentially overridden
Returns:
true if overridden
Since:
1.1.1


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.