Java Utililty Methods Reflection Method Annotation

List of utility methods to do Reflection Method Annotation

Description

The list of methods to do Reflection Method Annotation are organized into topic(s).

Method

ListgetMethodAnnotations(Method m)
For a give Method m determine Annotation s in the following manner:
  • Check if the given Method has Annotation s.
    Method method = (Method) getFirstAnnotatedAccessibleObject(m.getDeclaringClass(), m);
    if (m != null) {
        return Arrays.asList(method.getDeclaredAnnotations());
    return new ArrayList<Annotation>();
    
ListgetMethodByAnnotation(Class cls, Class annotationClass)
get Method By Annotation
List<Method> result = new ArrayList<Method>();
Method[] methods = cls.getDeclaredMethods();
for (Method method : methods) {
    if (method.isAnnotationPresent(annotationClass)) {
        result.add(method);
Class<?> superClass = cls.getSuperclass();
...
ListgetMethodContainsAnnotations(Class target, Class annotation)
get Method Contains Annotations
List<Method> fieldsDaClasse = getMethods(target);
return (List<Method>) fieldsDaClasse.stream()
        .filter((Method method) -> method.isAnnotationPresent(annotation)).collect(Collectors.toList());
ArrayListgetMethodInClassWithAnnotation(Class cls, Class annotationClass, int... modifiers)
Gibt die Methode aus der gegebenen Klasse mit dem gegebenen Namen, den gegebenen Argumenten zurueck und den gegebenenen Modifiern zurueck.
ArrayList<Method> methods = new ArrayList<Method>();
for (Method m : cls.getDeclaredMethods()) {
    if (m.isAnnotationPresent(annotationClass) && hasAllModifiers(m, modifiers)) {
        methods.add(m);
return methods;
SetgetMethodLevelAnnotations(Class clazz, Class annotation)
get Method Level Annotations
Set<T> result = new HashSet<T>();
Set<Method> annotatedMethods = getMethodsAnnotatedWith(clazz, annotation);
for (Method annotatedMethod : annotatedMethods) {
    result.add(annotatedMethod.getAnnotation(annotation));
return result;
StringgetMethodName(final Class annoType, final Class klazType)
get Method Name
final Method[] methodArray = klazType.getDeclaredMethods();
for (final Method method : methodArray) {
    final Annotation anno = method.getAnnotation(annoType);
    if (anno != null) {
        return method.getName();
return null;
...
TgetMethodOrClassLevelAnnotation(Class annotationClass, Method method, Class clazz)
get Method Or Class Level Annotation
T annotation = method.getAnnotation(annotationClass);
if (annotation != null) {
    return annotation;
return getClassLevelAnnotation(annotationClass, clazz);
Method[]getMethods(Annotation anno)
get Methods
ArrayList<Method> methods = new ArrayList<Method>();
Class<? extends Annotation> cls = anno.annotationType();
for (Method method : cls.getDeclaredMethods()) {
    if (Modifier.isPublic(method.getModifiers()) && method.getDeclaringClass() == cls) {
        methods.add(method);
return methods.toArray(new Method[methods.size()]);
...
Method[]getMethods(Class clazz, Class annotation)
get Methods
List<Method> methods = new ArrayList();
for (Method m : clazz.getMethods()) {
    if (m.isAnnotationPresent(annotation)) {
        methods.add(m);
return methods.toArray(new Method[0]);
ListgetMethods(final Class clazz, final Class annotation)
Return all method(s) of a specified class that contain the specified annotation.
final List<Method> annotatedMethods = new LinkedList<Method>();
for (Method method : clazz.getMethods()) {
    if (method.isAnnotationPresent(annotation)) {
        annotatedMethods.add(method);
return annotatedMethods;