get Method Parameter Annotations - Java java.lang.annotation

Java examples for java.lang.annotation:Method Annotation

Description

get Method Parameter Annotations

Demo Code


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

public class Main {
    public static Annotation[][] getParameterAnnotations(Method method) {

        Annotation[][] annotations = method.getParameterAnnotations();
        Class<?> cl = method.getDeclaringClass();

        while (annotations == null) {
            cl = cl.getSuperclass();/*from w ww  .ja va  2  s  . c o  m*/
            if (cl == null || cl == Object.class) {
                break;
            }

            try {
                Method equivalentMethod = cl.getDeclaredMethod(
                        method.getName(), method.getParameterTypes());
                annotations = equivalentMethod.getParameterAnnotations();
            } catch (NoSuchMethodException e) {
                // We're done...
            }
        }

        return annotations;
    }
}

Related Tutorials