List of utility methods to do Reflection Method Annotation
Method | getMethod(Class extends Annotation> annotationClass, Class> aClass) Return the first method with the given annotation. for (Method method : aClass.getMethods()) { if (method.isAnnotationPresent(annotationClass)) { method.setAccessible(true); return method; return null; |
Method | getMethod(Class> compClassOrSuper, Class extends Annotation> annotation) Checks for annotation of the class for (Method m : compClassOrSuper.getMethods()) { if (m.getAnnotation(annotation) != null) { return m; return null; |
List | getMethodAnnotatedWith(Class> toIntrospect, Class extends Annotation> c) get Method Annotated With ArrayList<Method> result = new ArrayList<Method>(); Map<String, Method> allM = new HashMap<String, Method>(); Class<?> currentToIntrospect = toIntrospect; while (currentToIntrospect != null) { for (Method me : currentToIntrospect.getMethods()) { if (Modifier.isPublic(me.getModifiers())) { if (allM.containsKey(me.getName()) == false) allM.put(me.getName(), me); ... |
T | getMethodAnnotation(Class Returns the specified annotation on the specified method. T t = m.getAnnotation(a); if (t != null) return t; Class<?> pc = m.getDeclaringClass().getSuperclass(); if (pc != null) { for (Method m2 : pc.getDeclaredMethods()) { if (isSameMethod(m, m2)) { t = getMethodAnnotation(a, m2); ... |
Annotation | getMethodAnnotation(final Method method, final Class annoClass) get Method Annotation final Set<Class> visited = new HashSet<Class>(); final LinkedList<Class> stack = new LinkedList<Class>(); stack.add(method.getDeclaringClass()); while (!stack.isEmpty()) { Class classToChk = stack.pop(); if (classToChk == null || visited.contains(classToChk)) { continue; visited.add(classToChk); Method m = getMethod(classToChk, method.getName(), method.getParameterTypes()); if (m == null) { continue; Annotation a = m.getAnnotation(annoClass); if (a != null) { return a; stack.push(classToChk.getSuperclass()); addInterfaces(method.getDeclaringClass(), stack); return null; |
T | getMethodAnnotation(final Method method, final Class Gets the Annotation for the method, null if does not exists. final Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation.annotationType().equals(annotationType)) { return (T) annotation; return null; |
Annotation | getMethodAnnotation(Method method, Class annotation) get Method Annotation return method.getAnnotation(annotation);
|
T | getMethodAnnotation(Method method, Class get Method Annotation T ann = method.getAnnotation(annotationType); if (ann == null) { for (Class iface : method.getDeclaringClass().getInterfaces()) { for (Method otherMethod : iface.getMethods()) { if (isMatchingMethodSignatures(method, otherMethod)) { return getMethodAnnotation(otherMethod, annotationType); return ann; |
T | getMethodAnnotation(Method method, Class get Method Annotation T t = method.getAnnotation(clazz);
return t;
|
Map | getMethodAnnotationMap(Method method, Collection get Method Annotation Map Annotation[] methodAnnotations = method.getAnnotations(); Map<Class<? extends Annotation>, Annotation> methodAnnotationMap = new HashMap<Class<? extends Annotation>, Annotation>(); for (Annotation methodAnnotation : methodAnnotations) { methodAnnotationMap.put(methodAnnotation.annotationType(), methodAnnotation); methodAnnotationMap.keySet().retainAll(annotationClasses); return methodAnnotationMap; |