public final class ClassUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static Map<Class<?>,Object> |
DEFAULT_VALUES_MAP |
static Type[] |
NO_TYPES |
static Map<Class<?>,Class<?>> |
PRIMITIVE_TO_WRAPPERS_MAP |
| Modifier and Type | Method and Description |
|---|---|
static Object |
callInstanceMethod(Method method,
Object instance,
Object[] args)
Call method on the instance with given arguments.
|
static boolean |
checkParametrizedType(ParameterizedType pType)
Return true if it does not contain type variable for wildcard type
false otherwise.
|
static boolean |
checkRequiredTypeIsWildCard(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
is
Modifier.ABSTRACT |
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 Object |
getDefaultValue(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 boolean |
isClassAssignableFrom(Class<?> lhs,
Class<?> rhs)
Returns true if rhs is assignable type
to the lhs, false otherwise.
|
static boolean |
isConcrete(Class<?> clazz)
Return true if the class is not abstract and interface.
|
static boolean |
isInnerClazz(Class<?> clazz)
Check the class is inner or not
|
static boolean |
isMethodDeclared(Class<?> clazz,
String name,
Class<?>... parameterTypes)
|
static boolean |
isMethodHasCheckedException(Method method)
Check method throws checked exception or not.
|
static boolean |
isMethodImplemented(Class<?> clazz,
Class<?> interfase,
String methodName,
Class<?>... parameterTypes)
|
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 |
isRawClassEquals(Type ipType,
Type apiType) |
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. |
public static final Type[] NO_TYPES
public static boolean isInnerClazz(Class<?> clazz)
clazz - to checkpublic static Class<?> getClass(Type type)
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.
type - class or parametrized typepublic static boolean isMethodHasCheckedException(Method method)
method - method instancepublic static Object callInstanceMethod(Method method, Object instance, Object[] args)
method - method instanceinstance - object instanceargs - argumentspublic static List<Method> getNonPrivateMethods(Class<?> topClass, boolean excludeFinalMethods)
Object.finalize() method as users must not deal with it.topClass - the class to start with. Then move up the hierarchyexcludeFinalMethods - whether final classes should get excluded from the resultpublic static List<Method> getAbstractMethods(Class<?> clazz)
Modifier.ABSTRACTpublic static boolean isMethodDeclared(Class<?> clazz, String name, Class<?>... parameterTypes)
clazz - to checkname - of the methodparameterTypes - of the methodfalsepublic static boolean isMethodImplemented(Class<?> clazz, Class<?> interfase, String methodName, Class<?>... parameterTypes)
Class implements the Method with the
given name und parameterTypes.
Returns false if the method is only a default method in the interface!clazz - to checkinterfase - the Interface which declares the methodmethodName - of the methodparameterTypes - of the methodfalsepublic static boolean isOverridden(List<Method> subclassMethods, Method superclassMethod)
subclassMethods - superclassMethod - public static boolean isObjectMethod(String methodName)
methodName - true if the given method is from Object.class (either directly or overloaded)public static boolean isParametrizedType(Type type)
ParameterizedType
else otherwise.type - type of the artifactParameterizedTypepublic static boolean isWildCardType(Type type)
WildcardType
else otherwise.type - type of the artifactWildcardTypepublic static boolean isUnboundedTypeVariable(Type type)
public static boolean isTypeVariable(Type type)
TypeVariable
else otherwise.type - type of the artifactTypeVariablepublic static boolean isConcrete(Class<?> clazz)
clazz - class typepublic static boolean isClassAssignableFrom(Class<?> lhs, Class<?> rhs)
lhs - left hand side classrhs - right hand side classpublic static boolean checkRequiredTypeIsWildCard(Type beanTypeArg, Type requiredTypeArg)
Required type is a wildcard type.
beanTypeArg - bean typerequiredTypeArg - required typepublic static Type[] getActualTypeArguments(Type type)
type is a
ParameterizedType instance, else an empty array.
Get the actual type arguments of a type.type - public static Class<?> getClazz(Type type)
type - base type instancepublic static boolean checkParametrizedType(ParameterizedType pType)
pType - parameterized typepublic static Class<?> getRawTypeForInjectionPoint(javax.enterprise.inject.spi.InjectionPoint injectionPoint)
injectionPoint - injection point definitionpublic static boolean isOverridden(Method subClassMethod, Method superClassMethod)
superClassMethod is overridden by subClassMethod.subClassMethod - potentially overridingsuperClassMethod - potentially overriddenCopyright © 2008–2020 The Apache Software Foundation. All rights reserved.