Java Reflection Annotation getAnnotations(Class cls)

Here you can find the source of getAnnotations(Class cls)

Description

get Annotations

License

Apache License

Declaration

public static Set<Annotation> getAnnotations(Class cls) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static Set<Annotation> getAnnotations(Class cls) {
        Set<Annotation> ret = new HashSet<Annotation>();
        ret.addAll(Arrays.asList(cls.getAnnotations()));
        if (cls.getSuperclass() != null) {
            ret.addAll(getAnnotations(cls.getSuperclass()));
        }//from   ww  w.  ja  v  a  2 s . c  om
        for (Class intrface : cls.getInterfaces()) {
            ret.addAll(getAnnotations(intrface));
        }
        return ret;
    }
}

Related

  1. getAnnotationPropertyValue(Annotation a, String annotationPropertyName)
  2. getAnnotationRecursive(Class cls, Class annotationClass)
  3. getAnnotations(AnnotatedElement ae, Class annotationType)
  4. getAnnotations(AnnotatedElement annotated)
  5. getAnnotations(Annotation[][] annotations)
  6. getAnnotations(Class annotationClass, Annotation[] annotations)
  7. getAnnotations(Class c, Class annotationClass)
  8. getAnnotations(Class annotation, Collection annotations)
  9. getAnnotations(Class ann, Object o, Method m, int param)