Java Reflection Annotation Find findAnnotationDeclaringClass(Class annotationType, Class clazz)

Here you can find the source of findAnnotationDeclaringClass(Class annotationType, Class clazz)

Description

find Annotation Declaring Class

License

Open Source License

Declaration

public static Class findAnnotationDeclaringClass(Class annotationType, Class clazz) 

Method Source Code


//package com.java2s;
import java.lang.annotation.Annotation;

import java.util.Arrays;

import java.util.Iterator;

public class Main {

    public static Class findAnnotationDeclaringClass(Class annotationType, Class clazz) {
        if (clazz == null || clazz.equals(Object.class))
            return null;
        else/*www .jav  a2s.  c  om*/
            return isAnnotationDeclaredLocally(annotationType, clazz) ? clazz
                    : findAnnotationDeclaringClass(annotationType, clazz.getSuperclass());
    }

    public static boolean isAnnotationDeclaredLocally(Class annotationType, Class clazz) {
        boolean declaredLocally = false;
        Iterator iterator = Arrays.asList(clazz.getDeclaredAnnotations()).iterator();
        do {
            if (!iterator.hasNext())
                break;
            Annotation annotation = (Annotation) iterator.next();
            if (!annotation.annotationType().equals(annotationType))
                continue;
            declaredLocally = true;
            break;
        } while (true);
        return declaredLocally;
    }
}

Related

  1. findAnnotation(final Set annotations, final Class annotationType)
  2. findAnnotation(Method method, Class annotationType)
  3. findAnnotation(Method method, Class type)
  4. findAnnotation(Set annotations, Class annotationClass)
  5. findAnnotationClass( Class c, Class base)
  6. findAnnotationDeclaringClass(Class annotationType, Class classToFind)
  7. findAnnotationDeclaringClass(Class annotationType, Class clazz)
  8. findAnnotationFromClass(Class target, Class annotation)
  9. findAnnotationFromMethodOrClass(final Method method, final Class annotationClass)