Java Reflection Annotation getAnnotationMetaAnnotated( AnnotatedElement annotatedElementClass, Class metaAnnotationToFind)

Here you can find the source of getAnnotationMetaAnnotated( AnnotatedElement annotatedElementClass, Class metaAnnotationToFind)

Description

Finds a annotation meta-annotated on the given annotated element.

License

Open Source License

Parameter

Parameter Description
T the annotation type to retrieve
annotatedElementClass the annotated element
metaAnnotationToFind the meta annotation to find

Return

the annotation meta annotated if exist, null otherwise

Declaration

public static <T extends Annotation> Annotation getAnnotationMetaAnnotated(
        AnnotatedElement annotatedElementClass, Class<T> metaAnnotationToFind) 

Method Source Code

//package com.java2s;
/**/*from  w ww .j ava2 s. c  om*/
 * Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
 *
 * This file is part of SeedStack, An enterprise-oriented full development stack.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

public class Main {
    /**
     * Finds a annotation meta-annotated on the given annotated element.
     *
     * @param <T> the annotation type to retrieve
     * @param annotatedElementClass the annotated element
     * @param metaAnnotationToFind  the meta annotation to find
     * @return the annotation meta annotated if exist, null otherwise
     */
    public static <T extends Annotation> Annotation getAnnotationMetaAnnotated(
            AnnotatedElement annotatedElementClass, Class<T> metaAnnotationToFind) {
        Annotation[] annotations = annotatedElementClass.getAnnotations();
        for (Annotation annotation : annotations) {
            Annotation[] metaAnnotations = annotation.annotationType().getAnnotations();
            for (Annotation metaAnnotation : metaAnnotations) {
                if (metaAnnotation.annotationType().equals(metaAnnotationToFind)) {
                    return annotation;
                }
            }
        }
        return null;
    }
}

Related

  1. getAnnotationInHeirarchy(Class annotationClass, Class aClass)
  2. getAnnotationInherited(Class type, Class annotationClass)
  3. getAnnotationInstances(Class clazz, Class annotationClass)
  4. getAnnotationMemberDefaults(Annotation annotation)
  5. getAnnotationMemberType(Annotation annotation, String memberName)
  6. getAnnotationMethods(Class annotationType)
  7. getAnnotationOfField(Field field, Class clazz)
  8. getAnnotationOuterIndecies(Class annotationClass, Annotation[][] annotations)
  9. getAnnotationPropertyValue(Annotation a, String annotationPropertyName)