Java Reflection Annotation getAnnotationAttributes(Annotation annotation)

Here you can find the source of getAnnotationAttributes(Annotation annotation)

Description

get Annotation Attributes

License

Open Source License

Declaration

public static Map getAnnotationAttributes(Annotation annotation) 

Method Source Code


//package com.java2s;
import java.lang.annotation.Annotation;

import java.lang.reflect.Method;

import java.util.HashMap;

import java.util.Map;

public class Main {

    public static Map getAnnotationAttributes(Annotation annotation) {
        Map attrs = new HashMap();
        Method methods[] = annotation.annotationType().getDeclaredMethods();
        for (int j = 0; j < methods.length; j++) {
            Method method = methods[j];
            if (method.getParameterTypes().length != 0 || method.getReturnType() == Void.TYPE)
                continue;
            try {
                attrs.put(method.getName(), method.invoke(annotation, new Object[0]));
            } catch (Exception ex) {
                throw new IllegalStateException("Could not obtain annotation attribute values", ex);
            }//w  ww .  ja va  2 s . c  o  m
        }

        return attrs;
    }
}

Related

  1. getAnnotation(Object obj, Class acl)
  2. getAnnotation(Object obj, Class annotation)
  3. getAnnotation(ProceedingJoinPoint pjp, Class annotationClass)
  4. getAnnotationAttribute(Annotation a, String attrName)
  5. getAnnotationAttribute(final Annotation anno, final String attrName, final Class attrType)
  6. getAnnotationAttributes(Annotation annotation)
  7. getAnnotationAttributes(final Annotation annotation)
  8. getAnnotationAttributeValue(final Annotation annotation, final String attributeName)
  9. getAnnotationByType(AnnotatedElement element, Class annotationType)