Package org.apache.webbeans.util
Class ClassUtil
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description static Map<Class<?>,Object>DEFAULT_VALUES_MAPstatic Type[]NO_TYPESstatic Map<Class<?>,Class<?>>PRIMITIVE_TO_WRAPPERS_MAP
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectcallInstanceMethod(Method method, Object instance, Object[] args)Call method on the instance with given arguments.static booleancheckParametrizedType(ParameterizedType pType)Return true if it does not contain type variable for wildcard type false otherwise.static booleancheckRequiredTypeIsWildCard(Type beanTypeArg, Type requiredTypeArg)Check bean type and required type.static List<Method>getAbstractMethods(Class<?> clazz)collect all abstract methods for the given class if the given class isModifier.ABSTRACTstatic Type[]getActualTypeArguments(Type type)Returns declared type arguments iftypeis aParameterizedTypeinstance, else an empty array.static Class<?>getClass(Type type)Gets the class of the given type arguments.static Class<?>getClassFromName(String name)static Class<?>getClassFromName(String name, ClassLoader providedLoader, boolean init)static Class<?>getClazz(Type type)Return raw class type for given type.static ObjectgetDefaultValue(Class<?> 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(javax.enterprise.inject.spi.InjectionPoint injectionPoint)Returns injection point raw type.static booleanisClassAssignableFrom(Class<?> lhs, Class<?> rhs)Returns true if rhs is assignable type to the lhs, false otherwise.static booleanisConcrete(Class<?> clazz)Return true if the class is not abstract and interface.static booleanisInnerClazz(Class<?> clazz)Check the class is inner or notstatic booleanisMethodDeclared(Class<?> clazz, String name, Class<?>... parameterTypes)static booleanisMethodHasCheckedException(Method method)Check method throws checked exception or not.static booleanisMethodImplemented(Class<?> clazz, Class<?> interfase, String methodName, Class<?>... parameterTypes)static booleanisObjectMethod(String methodName)Checks if the given method if from Object.classstatic booleanisOverridden(Method subClassMethod, Method superClassMethod)Check whethersuperClassMethodis overridden bysubClassMethod.static booleanisOverridden(List<Method> subclassMethods, Method superclassMethod)Check if the method is already defined in a subclassstatic booleanisParametrizedType(Type type)Returns true if type is an instance ofParameterizedTypeelse otherwise.static booleanisRawClassEquals(Type ipType, Type apiType)static booleanisSame(Type type1, Type type2)static booleanisTypeVariable(Type type)Returns true if type is an instance ofTypeVariableelse otherwise.static booleanisUnboundedTypeVariable(Type type)static booleanisWildCardType(Type type)Returns true if type is an instance ofWildcardTypeelse otherwise.
-
-
-
Method Detail
-
getClassFromName
public static Class<?> getClassFromName(String name, ClassLoader providedLoader, boolean init)
-
isInnerClazz
public static boolean isInnerClazz(Class<?> clazz)
Check the class is inner or not- Parameters:
clazz- to check- Returns:
- true or false
-
getClass
public static Class<?> getClass(Type type)
Gets the class of the given type arguments.If the given type
Typeparameters is an instance of theParameterizedType, it returns the raw type otherwise it return the castedClassof 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 instanceinstance- object instanceargs- 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 theObject.finalize()method as users must not deal with it.- Parameters:
topClass- the class to start with. Then move up the hierarchyexcludeFinalMethods- whether final classes should get excluded from the result
-
getAbstractMethods
public static List<Method> getAbstractMethods(Class<?> clazz)
collect all abstract methods for the given class if the given class isModifier.ABSTRACT
-
isMethodDeclared
public static boolean isMethodDeclared(Class<?> clazz, String name, Class<?>... parameterTypes)
- Parameters:
clazz- to checkname- of the methodparameterTypes- of the method- Returns:
- true if the given class contains a method with the given name and parameterTypes,
otherwise
false
-
isMethodImplemented
public static boolean isMethodImplemented(Class<?> clazz, Class<?> interfase, String methodName, Class<?>... parameterTypes)
Checks, if the givenClassimplements theMethodwith the given name und parameterTypes. Returnsfalseif the method is only a default method in the interface!- Parameters:
clazz- to checkinterfase- the Interface which declares the methodmethodName- of the methodparameterTypes- of the method- Returns:
- true if the given class contains a method with the given name and parameterTypes,
otherwise
false
-
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:
trueif 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 ofParameterizedTypeelse 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 ofWildcardTypeelse 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 ofTypeVariableelse otherwise.- Parameters:
type- type of the artifact- Returns:
- true if type is an instance of
TypeVariable
-
isConcrete
public static boolean isConcrete(Class<?> clazz)
Return true if the class is not abstract and interface.- Parameters:
clazz- class type- Returns:
- true if the class is not abstract and interface
-
isClassAssignableFrom
public static boolean isClassAssignableFrom(Class<?> lhs, Class<?> rhs)
Returns true if rhs is assignable type to the lhs, false otherwise.- Parameters:
lhs- left hand side classrhs- right hand side class- Returns:
- true if rhs is assignable to lhs
-
checkRequiredTypeIsWildCard
public static boolean checkRequiredTypeIsWildCard(Type beanTypeArg, Type requiredTypeArg)
Check bean type and required type.Required type is a wildcard type.
- Parameters:
beanTypeArg- bean typerequiredTypeArg- required type- Returns:
- true if condition satisfies
- Since:
- 1.1.1
-
getActualTypeArguments
public static Type[] getActualTypeArguments(Type type)
Returns declared type arguments iftypeis aParameterizedTypeinstance, 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(javax.enterprise.inject.spi.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 whethersuperClassMethodis overridden bysubClassMethod.- Parameters:
subClassMethod- potentially overridingsuperClassMethod- potentially overridden- Returns:
- true if overridden
- Since:
- 1.1.1
-
-