
net.bndy.lib.AnnotationHelper Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (C) 2017 http://bndy.net
* Created by Bendy (Bing Zhang)
******************************************************************************/
package net.bndy.lib;
import java.lang.annotation.Annotation;
/**
* Utils for Annotation
*/
public class AnnotationHelper {
/**
* Get annotation of public field.
*
* @param annotationClass the annotation class annotated by @Retention(RetentionPolicy.RUNTIME)
* @param source the source class
* @param fieldName the public field name
* @param the annotation type
* @param the source type
* @return the instance typed {@code T}
*/
public static T getFieldAnnotation(Class annotationClass, Class source, String fieldName) {
return ReflectionHelper.getField(fieldName, source).getAnnotation(annotationClass);
}
/**
* Get annotation of class.
*
* @param annotationClass the annotation class annotated by @Retention(RetentionPolicy.RUNTIME)
* @param source the source class
* @param the annotation type
* @param the source type
* @return the instance typed {@code T}
* @throws SecurityException SecurityException
*/
public static T getClassAnnotation(Class annotationClass, Class source) throws SecurityException {
return source.getAnnotation(annotationClass);
}
}