public class ClassUtils extends Object
| Constructor and Description |
|---|
ClassUtils() |
| Modifier and Type | Method and Description |
|---|---|
static AnnotatedType |
addAnnotations(AnnotatedType type,
Annotation[] annotations) |
static void |
checkIfResolvable(AnnotatedType declaringType,
Member member)
Check whether the member has resolvable type.
|
static boolean |
containsTypeAnnotation(AnnotatedType type,
Class<? extends Annotation> annotation) |
static Method |
findGetter(Class<?> type,
String fieldName) |
static List<AnnotatedType> |
findImplementations(AnnotatedType superType,
String... packages)
Scans classpath for implementations/subtypes of the given
AnnotatedType. |
static List<Class> |
findImplementations(Class superType,
String... packages) |
static Method |
findSetter(Class<?> type,
String fieldName,
Class<?> fieldType) |
static Class<?> |
forName(String className) |
static Annotation[] |
getAllAnnotations(Stream<AnnotatedType> types) |
static Set<Field> |
getAnnotatedFields(Class<?> type,
Class<? extends Annotation> annotation)
Retrieves all public fields on the given class (same as
Class.getFields()) annotated by the given annotation |
static Set<Method> |
getAnnotatedMethods(Class<?> type,
Class<? extends Annotation> annotation)
Retrieves all public methods on the given class (same as
Class.getMethods()) annotated by the given annotation |
static AnnotatedType |
getCommonSuperType(List<AnnotatedType> types)
Finds the most specific super type of all given types.
|
static List<Class<?>> |
getCommonSuperTypes(List<Class> classes) |
static String |
getFieldNameFromGetter(Method getter) |
static String |
getFieldNameFromSetter(Method setter) |
static AnnotatedType |
getFieldType(Field field,
AnnotatedType declaringType)
Returns the exact annotated type of the field declared by the given type, with type variables resolved (if possible)
|
static <T> T |
getFieldValue(Object source,
String fieldName) |
static AnnotatedType[] |
getParameterTypes(Executable executable,
AnnotatedType declaringType)
Returns the exact annotated parameter types of the executable declared by the given type, with type variables resolved (if possible)
|
static Class<?> |
getRawType(Type type) |
static AnnotatedType |
getReturnType(Method method,
AnnotatedType declaringType)
Returns the exact annotated return type of the method declared by the given type, with type variables resolved (if possible)
|
static Set<Class<?>> |
getSuperTypes(Class<?> clazz) |
static AnnotatedType[] |
getTypeArguments(AnnotatedType type) |
static boolean |
isAbstract(AnnotatedType type) |
static boolean |
isAbstract(Class<?> type) |
static boolean |
isAssignable(Type superType,
Type subType) |
static boolean |
isGetter(Method getter)
Checks whether the given method is a JavaBean property getter
|
static boolean |
isProxy(Class<?> clazz)
Attempts to discover if the given class is a dynamically generated proxy class.
|
static boolean |
isSetter(Method setter)
Checks whether the given method is a JavaBean property setter
|
static AnnotatedType |
stripBounds(AnnotatedType type)
Recursively replaces all bounded types found within the structure of the given
AnnotatedType with their first bound. |
static String |
toString(AnnotatedType type) |
public static Set<Method> getAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation)
Class.getMethods()) annotated by the given annotationtype - The class to scanannotation - The annotation to look forpublic static Set<Field> getAnnotatedFields(Class<?> type, Class<? extends Annotation> annotation)
Class.getFields()) annotated by the given annotationtype - The class to scanannotation - The annotation to look forpublic static AnnotatedType getReturnType(Method method, AnnotatedType declaringType)
method - The method whose return type is to be resolveddeclaringType - The declaring annotated type against which to resolve the return typepublic static AnnotatedType getFieldType(Field field, AnnotatedType declaringType)
field - The field whose type is to be resolveddeclaringType - The declaring annotated type against which to resolve the field typepublic static AnnotatedType[] getTypeArguments(AnnotatedType type)
public static AnnotatedType[] getParameterTypes(Executable executable, AnnotatedType declaringType)
executable - The executable whose parameter types are to be resolveddeclaringType - The declaring annotated type against which to resolve the types of the parameters of the given executablepublic static void checkIfResolvable(AnnotatedType declaringType, Member member)
declaringType - The type declaring the member (against which the member's type will be resolved)member - The field of method to be checkedpublic static boolean isGetter(Method getter)
getter - The method to be checkedisSetter(Method)public static boolean isSetter(Method setter)
setter - The method to be checkedisGetter(Method)public static Method findGetter(Class<?> type, String fieldName) throws NoSuchMethodException
NoSuchMethodExceptionpublic static Method findSetter(Class<?> type, String fieldName, Class<?> fieldType) throws NoSuchMethodException
NoSuchMethodExceptionpublic static List<AnnotatedType> findImplementations(AnnotatedType superType, String... packages)
AnnotatedType. Only the matching classes are loaded.superType - The type whose implementations/subtypes are to be looked forAnnotatedTypes found on the classpath that are implementations/subtypes of superTypeRuntimeException - If a class file could not be parsed or a class could not be loadedpublic static List<Class> findImplementations(Class superType, String... packages)
public static boolean isAbstract(AnnotatedType type)
public static boolean isAbstract(Class<?> type)
public static String toString(AnnotatedType type)
public static boolean containsTypeAnnotation(AnnotatedType type, Class<? extends Annotation> annotation)
public static Annotation[] getAllAnnotations(Stream<AnnotatedType> types)
public static AnnotatedType addAnnotations(AnnotatedType type, Annotation[] annotations)
public static AnnotatedType stripBounds(AnnotatedType type)
AnnotatedType with their first bound.
I.e.
AnnotatedWildcardTypes are replaced with their first lower bound if it exists,
or their first upper bound otherwise. All annotations are preserved.AnnotatedTypeVariables are replaced with their first bound. All annotations are preserved.type - A potentially bounded typepublic static AnnotatedType getCommonSuperType(List<AnnotatedType> types)
types - Types whose most specific super types is to be foundpublic static List<Class<?>> getCommonSuperTypes(List<Class> classes)
classes - Types whose most specific super types is to be foundgetCommonSuperType(List)public static boolean isProxy(Class<?> clazz)
clazz - The class to testtrue if the given class is a known proxy, false otherwisepublic static Class<?> forName(String className) throws ClassNotFoundException
ClassNotFoundExceptionCopyright © 2016–2017. All rights reserved.