Java Reflection Annotation getAnnotationFields(Class claz, Class annotationType)

Here you can find the source of getAnnotationFields(Class claz, Class annotationType)

Description

get fields list of a type, and all the fields returned contains the given annotation

License

Open Source License

Parameter

Parameter Description
claz a parameter
annotationType a parameter

Declaration

@SuppressWarnings({ "unchecked", "rawtypes" })
public static List<Field> getAnnotationFields(Class claz, Class annotationType) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/* w w w .ja va 2  s. c  om*/
     * get fields list of a type, and all the fields returned contains the given
     * annotation
     * 
     * @param claz
     * @param annotationType
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static List<Field> getAnnotationFields(Class claz, Class annotationType) {
        List<Field> result = new ArrayList<Field>();
        if (claz != null) {
            Field[] fields = claz.getDeclaredFields();
            for (Field field : fields) {
                if (field.getAnnotation(annotationType) != null) {
                    result.add(field);
                }
            }
            result.addAll(getAnnotationFields(claz.getSuperclass(), annotationType));
        }
        return result;
    }
}

Related

  1. getAnnotationDeep(Annotation from, Class toFind)
  2. getAnnotationDefault(Class annotationClass, String element)
  3. getAnnotationDefaultMap(Class annotationClass)
  4. getAnnotationElementValue(AnnotatedElement annotatedElement, String annotationClassName, String annotationElementName, Class annotationElementType)
  5. getAnnotationField(Annotation annotation, String field)
  6. getAnnotationFields(Class clazz, Class annotationClass)
  7. getAnnotationForMethodOrContainingClass(Method m, Class annotationType)
  8. getAnnotationForProperty(Class cls, String name, Class anno)
  9. getAnnotationFromAnnotation(Annotation annotation, Class annotationClass)