Java Utililty Methods Reflection Annotation

List of utility methods to do Reflection Annotation

Description

The list of methods to do Reflection Annotation are organized into topic(s).

Method

AgetAnnotation(Class cls, Class annotationClass)
get Annotation
A annotation = cls.getAnnotation(annotationClass);
if (annotation == null) {
    Class<?> superClass = cls.getSuperclass();
    if (superClass != null && !(superClass.equals(Object.class))) {
        annotation = getAnnotation(superClass, annotationClass);
if (annotation == null) {
...
TgetAnnotation(Class cls, Class annotation)
get Annotation
return cls.getAnnotation(annotation);
TgetAnnotation(Class componentClass, Class annotationClass)
Search for the given annotationClass in the given componentClass and return it if search was successful.
T annotation = componentClass.getAnnotation(annotationClass);
if (annotation != null) {
    return annotation;
for (Class<?> ifc : componentClass.getInterfaces()) {
    annotation = getAnnotation(ifc, annotationClass);
    if (annotation != null) {
        return annotation;
...
TgetAnnotation(Class configInterface, Method method, Class annotationType, boolean searchMethodType)
Search for an annotation on a configuration interface method.
T annotation = method.getAnnotation(annotationType);
if (annotation == null) {
    Method getMethod = getGetMethod(configInterface, method);
    if (getMethod != null) {
        annotation = getMethod.getAnnotation(annotationType);
    if ((annotation == null) && searchMethodType) {
        String methodName = method.getName();
...
TgetAnnotation(Class klazz, Class annotationClass)
get Annotation
return klazz.getAnnotation(annotationClass);
TgetAnnotation(Class objectClass, Class annotationClass)
get Annotation
if (objectClass == null || Object.class == objectClass) {
    return null;
T annotation = objectClass.getAnnotation(annotationClass);
if (annotation != null) {
    return annotation;
return getAnnotation(objectClass.getSuperclass(), annotationClass);
...
AgetAnnotation(Class onClass, Class desiredAnnotationClass)
Obtains the specified Annotation instance on the provided Class , interfaces implemented by the Class and/or the super-class(es)/super-interface(s) of the Class .
if (onClass == null || desiredAnnotationClass == null) {
    return null;
} else if (onClass.getClass().equals(Object.class)) {
    return null;
} else {
    A annotation = onClass.getAnnotation(desiredAnnotationClass);
    if (annotation == null) {
        for (Class<?> onInterface : onClass.getInterfaces()) {
...
TgetAnnotation(Class target, Class annoCls)
get Annotation
if (Object.class.equals(target)) {
    return null;
try {
    T annotation = target.getAnnotation(annoCls);
    if (annotation != null)
        return annotation;
    else
...
TgetAnnotation(Class target, Class annotationClass)
Returns the annotation of the annotationClass of the clazz or any of it super classes.
Class<?> clazz = target;
T annotation = clazz.getAnnotation(annotationClass);
if (annotation != null) {
    return annotation;
while ((clazz = clazz.getSuperclass()) != null) {
    annotation = clazz.getAnnotation(annotationClass);
    if (annotation != null) {
...
TgetAnnotation(Class theClass, Class theAnnotation)
Return the given annotation from the class.
T aAnnotation = null;
if (theClass.isAnnotationPresent(theAnnotation)) {
    aAnnotation = theClass.getAnnotation(theAnnotation);
} else {
    if (shouldInspectClass(theClass.getSuperclass()))
        aAnnotation = getAnnotation(theClass.getSuperclass(), theAnnotation);
    if (aAnnotation == null) {
        for (Class<?> aInt : theClass.getInterfaces()) {
...