All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fabric3.spi.introspection.java.AnnotationHelper Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package org.fabric3.spi.introspection.java;

import java.lang.annotation.Annotation;

/**
 *
 */
public class AnnotationHelper {

    /**
     * Returns the annotation if it is present on the type or it is present on one of the type annotations.
     *
     * @param annotationClass the annotation type
     * @param type            the type
     * @return the annotation or null if not present
     */
    public static  A findAnnotation(Class annotationClass, Class type) {
        for (Annotation annotation : type.getAnnotations()) {
            if (annotationClass.equals(annotation.annotationType())) {
                return annotationClass.cast(annotation);
            }
            for (Annotation metaAnnotation : annotation.annotationType().getDeclaredAnnotations()) {
                if (annotationClass.equals(metaAnnotation.annotationType())) {
                    return annotationClass.cast(metaAnnotation);
                }
            }
        }
        return null;
    }

    /**
     * Returns true if the annotation is present on the type or it is present on one of the type annotations.
     *
     * @param annotationClass the annotation type
     * @param type            the type
     * @return true if present
     */
    public static  boolean isPresent(Class annotationClass, Class type) {
        return findAnnotation(annotationClass, type) != null;
    }

    private AnnotationHelper() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy