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

StringgetAnnotationFullname(Annotation annotation)
get Annotation Fullname
return getAnnotationFullname(annotation.annotationType());
TgetAnnotationInClass(final Class annotationClass, final Class clazz)
Checks if class is noted by annotationClass.
Class<?> baseClass = clazz;
while (baseClass != null && !baseClass.equals(Object.class)) {
    if (baseClass.isAnnotationPresent(annotationClass)) {
        return baseClass.getAnnotation(annotationClass);
    for (Class<?> iClass : baseClass.getInterfaces()) {
        final T tAnnotation = getAnnotationInClass(annotationClass, iClass);
        if (tAnnotation != null) {
...
AnnotationgetAnnotationInHeirarchy(Class annotationClass, Class aClass)
get Annotation In Heirarchy
if (aClass.equals(Object.class))
    return null;
if (aClass.getAnnotation(annotationClass) != null) {
    return aClass.getAnnotation(annotationClass);
if (aClass.getSuperclass() != null) {
    Annotation annotation = getAnnotationInHeirarchy(annotationClass, aClass.getSuperclass());
    if (annotation != null) {
...
AgetAnnotationInherited(Class type, Class annotationClass)
get Annotation Inherited
A ann = type.getAnnotation(annotationClass);
if (ann != null) {
    return ann;
Class<?> superClass = type.getSuperclass();
if (superClass != null) {
    ann = getAnnotationInherited(superClass, annotationClass);
    if (ann != null) {
...
SetgetAnnotationInstances(Class clazz, Class annotationClass)
get Annotation Instances
Set<T> annotationInstances = new HashSet<T>();
for (Class<?> clazzClass : clazz.getInterfaces()) {
    if (clazzClass.isAnnotationPresent(annotationClass)) {
        annotationInstances.add(clazzClass.getAnnotation(annotationClass));
if (clazz.isAnnotationPresent(annotationClass)) {
    annotationInstances.add(clazz.getAnnotation(annotationClass));
...
MapgetAnnotationMemberDefaults(Annotation annotation)
get Annotation Member Defaults
Field[] fields = annotation.getClass().getSuperclass().getDeclaredFields();
for (Field field : fields) {
    field.setAccessible(true);
    Object instance = field.get(annotation);
    if (isAnnotationInvocationHandler(instance.getClass())) {
        Field typeField = instance.getClass().getDeclaredField("type");
        typeField.setAccessible(true);
        Object typeInstance = typeField.get(instance);
...
ClassgetAnnotationMemberType(Annotation annotation, String memberName)
return the type of an annotation member, or null if the member is not found in the annotation
Class<? extends Annotation> annotationType = annotation.annotationType();
return getAnnotationMemberType(annotationType, memberName);
AnnotationgetAnnotationMetaAnnotated( AnnotatedElement annotatedElementClass, Class metaAnnotationToFind)
Finds a annotation meta-annotated on the given annotated element.
Annotation[] annotations = annotatedElementClass.getAnnotations();
for (Annotation annotation : annotations) {
    Annotation[] metaAnnotations = annotation.annotationType().getAnnotations();
    for (Annotation metaAnnotation : metaAnnotations) {
        if (metaAnnotation.annotationType().equals(metaAnnotationToFind)) {
            return annotation;
return null;
MapgetAnnotationMethods(Class annotationType)
get Annotation Methods
Map<String, Method> annotationMethods = reflexionCache.get(annotationType);
if (annotationMethods == null) { 
    annotationMethods = new HashMap<String, Method>();
    for (Method method : annotationType.getMethods()) {
        if (method.getParameterTypes().length == 0 && method.getReturnType().equals(Void.class) == false) {
            String methName = method.getName();
            if (methName.equals("equals") || methName.equals("toString") || methName.equals("hashCode")
                    || methName.equals("annotationType")) {
...
TgetAnnotationOfField(Field field, Class clazz)
get Annotation Of Field
for (Annotation annotation : field.getDeclaredAnnotations()) {
    if (annotation.annotationType() == clazz) {
        return clazz.cast(annotation);
return null;