Java Reflection Method Annotation getMethodValue(Class annotationClasss, Class targetClass, String... annotationFields)

Here you can find the source of getMethodValue(Class annotationClasss, Class targetClass, String... annotationFields)

Description

get Method Value

License

Open Source License

Declaration

public static Map<String, Map<String, Object>> getMethodValue(Class annotationClasss, Class targetClass,
        String... annotationFields) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.annotation.Annotation;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static Map<String, Map<String, Object>> getMethodValue(Class annotationClasss, Class targetClass,
            String... annotationFields) throws Exception {
        Map<String, Map<String, Object>> map = new HashMap<String, Map<String, Object>>(20);
        Method[] methods = targetClass.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(annotationClasss)) {
                Map<String, Object> methodMap = new HashMap<String, Object>(10);
                Annotation p = method.getAnnotation(annotationClasss);
                for (String annotationField : annotationFields) {
                    Method m = p.getClass().getDeclaredMethod(annotationField);
                    if (m == null) {
                        continue;
                    }/*from   ww  w .ja va  2s . co  m*/
                    Object value = m.invoke(p);
                    methodMap.put(annotationField, value);
                }
            }
        }
        return map;
    }
}

Related

  1. getMethodsWithAnnotation(Class annotation, Class clazz)
  2. getMethodsWithAnnotation(Class type, Class obj)
  3. getMethodsWithAnnotation(Class clazz, Class annotationType)
  4. getMethodsWithAnnotation(Class type, Class annotation, boolean checkSuper)
  5. getMethodsWithAnnotation(final Class clazz, final Class... annotationClasses)