public class ClassUtils extends Object
| Constructor and Description |
|---|
ClassUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends AnnotatedType> |
addAnnotations(T type,
Annotation[] annotations) |
static AnnotatedType |
completeGenerics(AnnotatedType type,
AnnotatedType replacement) |
static boolean |
containsTypeAnnotation(AnnotatedType type,
Class<? extends Annotation> annotation) |
static AnnotatedType |
eraseBounds(AnnotatedType type,
AnnotatedType replacement)
Recursively replaces all bounded types found within the structure of the given
AnnotatedType with their first bound. |
static Optional<Field> |
findField(Class<?> type,
String fieldName) |
static Optional<Field> |
findFieldByGetter(Method getter) |
static Optional<Field> |
findFieldBySetter(Method setter) |
static Optional<Method> |
findGetter(Class<?> type,
String fieldName) |
static List<AnnotatedType> |
findImplementations(AnnotatedType superType,
String... packages)
Deprecated.
Use
ClassFinder directly as that enables caching of the search results |
static List<Class<?>> |
findImplementations(Class superType,
String... packages)
Deprecated.
Use
ClassFinder directly as that enables caching of the search results |
static Optional<Method> |
findMethod(Class<?> type,
String methodName,
Class<?>... parameterTypes) |
static Optional<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 <T extends Annotation> |
getAnnotation(Method method,
Class<T> annotation) |
static List<Method> |
getAnnotationFields(Class<? extends Annotation> annotation) |
static AnnotatedType |
getCommonSuperType(List<AnnotatedType> types)
Finds the most specific common super type of all the given types, merging the original annotations at each level.
|
static AnnotatedType |
getCommonSuperType(List<AnnotatedType> types,
AnnotatedType fallback)
Finds the most specific common super type of all the given types, merging the original annotations at each level.
|
static List<Class<?>> |
getCommonSuperTypes(List<Class<?>> classes) |
static Field |
getEnumConstantField(Enum<?> constant) |
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 List<AnnotatedElement> |
getPropertyMembers(Field field) |
static <T> Class<T> |
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 boolean |
hasAnnotation(AnnotatedElement element,
Class<? extends Annotation> annotation) |
static <T> T |
instance(AnnotatedType type) |
static <T> T |
instance(Class<T> clazz) |
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 |
isMissingTypeParameters(Type type) |
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 boolean |
isSubPackage(Package pkg,
String prefix) |
static <T extends AnnotatedType> |
normalize(T type) |
static <T extends AnnotatedType> |
removeAnnotations(T type,
Set<Class<? extends Annotation>> toRemove) |
static String |
toString(AnnotatedElement element) |
static String |
toString(AnnotatedType type) |
static <T extends AnnotatedType> |
transformType(T type,
UnaryOperator<T> transformer) |
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[] 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 boolean isMissingTypeParameters(Type type)
public static <T extends AnnotatedType> T normalize(T type)
public static <T> T instance(AnnotatedType type)
public static <T> T instance(Class<T> clazz)
public 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 List<AnnotatedElement> getPropertyMembers(Field field)
public static Optional<Method> findSetter(Class<?> type, String fieldName, Class<?> fieldType)
public static Optional<Method> findMethod(Class<?> type, String methodName, Class<?>... parameterTypes)
public static <T extends Annotation> T getAnnotation(Method method, Class<T> annotation)
@Deprecated public static List<AnnotatedType> findImplementations(AnnotatedType superType, String... packages)
ClassFinder directly as that enables caching of the search resultsAnnotatedType. Only the matching classes are loaded.superType - The type the implementations/subtypes of which are to be searched forpackages - The packages to limit the search toAnnotatedTypes discovered that implementation/extend superType@Deprecated public static List<Class<?>> findImplementations(Class superType, String... packages)
ClassFinder directly as that enables caching of the search resultssuperType - The type the implementations/subtypes of which are to be searched forpackages - The packages to limit the search tosuperTypepublic static boolean isAbstract(AnnotatedType type)
public static boolean isAbstract(Class<?> type)
public static String toString(AnnotatedType type)
public static String toString(AnnotatedElement element)
public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotation)
public static List<Method> getAnnotationFields(Class<? extends Annotation> annotation)
public static boolean containsTypeAnnotation(AnnotatedType type, Class<? extends Annotation> annotation)
public static Annotation[] getAllAnnotations(Stream<AnnotatedType> types)
public static <T extends AnnotatedType> T addAnnotations(T type, Annotation[] annotations)
public static <T extends AnnotatedType> T removeAnnotations(T type, Set<Class<? extends Annotation>> toRemove)
public static AnnotatedType eraseBounds(AnnotatedType type, AnnotatedType replacement)
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 completeGenerics(AnnotatedType type, AnnotatedType replacement)
public static <T extends AnnotatedType> T transformType(T type, UnaryOperator<T> transformer)
public static AnnotatedType getCommonSuperType(List<AnnotatedType> types)
TypeMappingException is thrown.types - Types whose most specific super types is to be foundpublic static AnnotatedType getCommonSuperType(List<AnnotatedType> types, AnnotatedType fallback)
If no common ancestors are found (except Object) returns fallback or throws a
TypeMappingException if fallback is null.
types - Types whose most specific super types is to be foundfallback - The type to return as the result when no common ancestors except Object are found (at any level)public 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–2018. All rights reserved.