extract annotation from target class

@param targetClass target class
@param annotationClass annotation class
@param <T> The annotation type.
@return annotation
332784
@Nullable
    public static <T extends Annotation> T extract(Class<?> targetClass, Class<T> annotationClass) {
        T annotation = null;
        if (targetClass.isAnnotationPresent(annotationClass)) {
            annotation = targetClass.getAnnotation(annotationClass);
            if (annotation == null && logger.isDebugEnabled()) {
                logger.debug("TargetClass has no annotation '{}'", annotationClass.getSimpleName());
                annotation = targetClass.getDeclaredAnnotation(annotationClass);
                if (annotation == null && logger.isDebugEnabled()) {
                    logger.debug("TargetClass has no declared annotation '{}'", annotationClass.getSimpleName());
                }
            }
        }
        return annotation;
    }
69867
public static <A extends Annotation> A getAnnotation(final Class<?> clazz, Class<A> annoClazz) {
        if (clazz == null || annoClazz == null) {
            return null;
        }

        return clazz.getAnnotation(annoClazz);
    }
867240
public <A extends Annotation> A annotation(Class<A> annotationClass) {
        return field.getAnnotation(annotationClass);
    }
1103236
@SuppressWarnings("unchecked")
    public <A extends Annotation> Optional<A> getAnnotation(final Class<A> annoClass) {
        return Optional.ofNullable((A)annotationMap.get(annoClass));
    }
980447
public static Optional<Class<?>> getClassWithAnnotation(final Class<?> source,
        final Class<? extends Annotation> annotationClass) {

        Class<?> nextSource = source;
        while (nextSource != Object.class) {
            if (nextSource.isAnnotationPresent(annotationClass)) {
                return Optional.of(nextSource);
            } else {
                nextSource = nextSource.getSuperclass();
            }
        }

        return Optional.empty();
    }
882023
public static <T extends Transformer<?>> TransformerBeanDescriptor<T> ofTransformer(Class<T> transformerClass) {
        return new AnnotationBasedTransformerBeanDescriptor<T>(transformerClass);
    }
261689
public Annotator getAnnotator(Class<? extends Annotator> clazz) {

        if (!Annotator.class.isAssignableFrom(clazz)) {
            throw new IllegalArgumentException("The class name given as a custom annotator (" + clazz.getName() + ") does not refer to a class that implements " + Annotator.class.getName());
        }

        try {
            try {
                Constructor<? extends Annotator> constructor = clazz.getConstructor(GenerationConfig.class);
                return constructor.newInstance(generationConfig);
            } catch (NoSuchMethodException e) {
                return clazz.newInstance();
            }
        } catch (InvocationTargetException | InstantiationException e) {
            throw new IllegalArgumentException("Failed to create a custom annotator from the given class. An exception was thrown on trying to create a new instance.", e.getCause());
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Failed to create a custom annotator from the given class. It appears that we do not have access to this class - is both the class and its no-arg constructor marked public?", e);
        }

    }
209040
public static <T> List<T> getWithAnnotatedClass(Class annotationClass, String packages) {
        return new ArrayList<T>() {{
            addAll(ClassGraphUtil.getWithAnnotatedClass(annotationClass, packages));
        }};
    }
507461
public static Predicate<RequestHandler> withClassAnnotation(final Class<? extends Annotation> annotation) {
    return input -> declaringClass(input).map(annotationPresent(annotation)).orElse(false);
  }
467971
@SuppressWarnings("unchecked")
	public <A extends Annotation> A getAnnotation(Class<A> type) {
		for (Annotation annotation : this.annotations) {
			if (type.isInstance(annotation)) {
				return (A) annotation;
			}
		}
		return null;
	}
689472
@SuppressWarnings("unchecked")
    public <A extends Annotation> A getAnnotation(final Field field, final Class<A> annClass) throws AnnotationReadException {
        
        final Class<?> clazz = field.getDeclaringClass();
        
        if(xmlInfo != null && xmlInfo.containsClassInfo(clazz.getName())) {
            final ClassInfo classInfo = xmlInfo.getClassInfo(clazz.getName());
            
            if(classInfo.containsFieldInfo(field.getName())) {
                FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
                if(fieldInfo != null && fieldInfo.containsAnnotationInfo(annClass.getName())){
                    AnnotationInfo annInfo = fieldInfo.getAnnotationInfo(annClass.getName());
                    try {
                        return (A)annotationBuilder.buildAnnotation(Class.forName(annInfo.getClassName()), annInfo);
                    } catch (ClassNotFoundException e) {
                        throw new AnnotationReadException(String.format("not found class '%s'", annInfo.getClassName()), e);
                    }
                }
            }
        }
        return field.getAnnotation(annClass);
    }
1212610
@SuppressWarnings("unchecked")
    public <T extends Annotation> T getParameterAnnotation(Class<T> annotationType) {
        Annotation[] anns = getParameterAnnotations();
        for (Annotation ann : anns) {
            if (annotationType.isInstance(ann)) {
                return (T) ann;
            }
        }
        return null;
    }
282929
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
        T result = null;
        if (field != null) {
            result = field.getAnnotation(annotationClass);
        }
        if (result == null && setter != null) {
            result = setter.getAnnotation(annotationClass);
        }
        if (result == null && getter != null) {
            result = getter.getAnnotation(annotationClass);
        }
        return result;
    }
290188
public static final <T extends Annotation> T getAnnotation(Object bean, String property, Class<T> annotationClass)
    {
        return (T) doFor(
            bean, 
            property, 
            null,
            (Object a, int i)->{Object o=Array.get(a, i);return o!=null?o.getClass().getAnnotation(annotationClass):null;},
            (List l, int i)->{return l.get(i).getClass().getAnnotation(annotationClass);},
            (Object b, Class c, String p)->{return getField(c, p).getAnnotation(annotationClass);}, 
            (Object b, Method m)->{return m.getAnnotation(annotationClass);});
    }
17092
public static String extractAsClassName(Element item, Class<? extends Annotation> annotationClass, AnnotationAttributeType attributeName) {
		final Elements elementUtils=BindDataSourceSubProcessor.elementUtils;
		final One<String> result = new One<String>();

		extractString(elementUtils, item, annotationClass, attributeName, new OnAttributeFoundListener() {

			@Override
			public void onFound(String value) {
				result.value0 = AnnotationUtility.extractAsArrayOfClassName(value).get(0);
			}
		});

		return result.value0;
	}
198062
public static <T> ClassConfiguration<T> empty(Class<T> targetClass) {
        return new ClassConfiguration<T>(targetClass, new HashMap<>()) {};
    }
69536
@SuppressWarnings("unchecked")
	public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
		return (this.method != null ? this.method.getAnnotation(annotationType) :
				(T) this.constructor.getAnnotation(annotationType));
	}