Java Reflection Annotation getAnnotationDeep(Annotation from, Class toFind)

Here you can find the source of getAnnotationDeep(Annotation from, Class toFind)

Description

This method is looking for the annotation class toFind from the annoFrom annotation instance.

License

Open Source License

Parameter

Parameter Description
from the annotation to search from.
toFind the annotation to find.

Return

the found annotation or null if nothing found.

Declaration

public static Annotation getAnnotationDeep(Annotation from, Class<? extends Annotation> toFind) 

Method Source Code

//package com.java2s;
/**/*from w  w  w .jav  a2  s  .co  m*/
 * 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;

public class Main {
    public static final String JAVA_LANG = "java.lang";

    /**
     * This method is looking for the annotation class toFind from the annoFrom
     * annotation instance. It will reach recursively until the annotation is
     * found.
     *
     * @param from   the annotation to search from.
     * @param toFind the annotation to find.
     * @return the found annotation or null if nothing found.
     */
    public static Annotation getAnnotationDeep(Annotation from, Class<? extends Annotation> toFind) {

        if (from.annotationType().equals(toFind)) {
            return from;
        } else {
            for (Annotation anno : from.annotationType().getAnnotations()) {
                if (!anno.annotationType().getPackage().getName().startsWith(JAVA_LANG)) {
                    return getAnnotationDeep(anno, toFind);
                }
            }
        }

        return null;
    }
}

Related

  1. getAnnotationClass(Annotation a)
  2. getAnnotationClass(Annotation annotation)
  3. getAnnotationClass(Class clazz, Class annotation)
  4. getAnnotationClass(Class entityClass, Class annotationClass)
  5. getAnnotationClass(String name)
  6. getAnnotationDefault(Class annotationClass, String element)
  7. getAnnotationDefaultMap(Class annotationClass)
  8. getAnnotationElementValue(AnnotatedElement annotatedElement, String annotationClassName, String annotationElementName, Class annotationElementType)
  9. getAnnotationField(Annotation annotation, String field)