Here you can find the source of getMethodAnnotations(String className, String methodName, Class>[] parameterTypes)
public static Annotation[] getMethodAnnotations(String className, String methodName, Class<?>[] parameterTypes)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.Method; public class Main { /**//w ww . j ava2 s . c o m * Returns all annotations on the given method */ // TODO: Squander should be fetching annotations through the central mechanism that also examines auxiliary files public static Annotation[] getMethodAnnotations(String className, String methodName, Class<?>[] parameterTypes) { try { Class<?> cls = Class.forName(className); if ("<init>".equals(methodName)) { Constructor<?> c = cls.getDeclaredConstructor(parameterTypes); c.setAccessible(true); return c.getAnnotations(); } else { try { // look for method declared exactly in this class final Method m = cls.getDeclaredMethod(methodName, parameterTypes); m.setAccessible(true); return m.getAnnotations(); } catch (final NoSuchMethodException e) { // look for a public method declared in some super-class final Method m = cls.getMethod(methodName, parameterTypes); m.setAccessible(true); return m.getAnnotations(); } } } catch (NoSuchMethodException e) { String msg = String.format("couldn't find a method named %s.%s to extract annotations from", className, methodName); throw new RuntimeException(msg, e); } catch (Exception e) { throw new RuntimeException("error getting annotations", e); } } }