List of utility methods to do Reflection Method Annotation
List | getMethods(final Class> t, final Class extends Annotation> a) get Methods final List<Method> ms = new ArrayList<Method>(); Class<?> c = t; while (c != null && c != Object.class) { for (final Method m : c.getDeclaredMethods()) if (m.isAnnotationPresent(a)) { m.setAccessible(true); ms.add(m); c = c.getSuperclass(); return ms; |
List | getMethodsAnnotated(Class extends Annotation> anno, Class> holder) get Methods Annotated ArrayList<Method> methods = new ArrayList<>(); List<Method> all = Arrays.asList(holder.getMethods()); all.stream().filter((method) -> (hasAnnotation(anno, method))).forEach((method) -> { methods.add(method); }); return methods; |
List | getMethodsAnnotatedBy(Class> clazz, Class extends Annotation> annotClass) get Methods Annotated By List<Method> annotMethList = new ArrayList<>( Arrays.asList(clazz.getDeclaredMethods()).stream().filter(dm -> { return dm.getAnnotation(annotClass) != null; }).collect(Collectors.toList())); if (clazz.getSuperclass() != Object.class) { annotMethList.addAll(getMethodsAnnotatedBy(clazz.getSuperclass(), annotClass)); return annotMethList; ... |
List | getMethodsAnnotatedWith(Class owner, Class extends Annotation> annotationClass, boolean includeSuper) get Methods Annotated With List<Method> selectedMethods = new ArrayList<Method>(); Method[] allMethods = owner.getMethods(); for (Method method : allMethods) { if (!includeSuper && isMethodInherited(owner, method)) { continue; if (method.isAnnotationPresent(annotationClass)) { selectedMethods.add(method); ... |
List | getMethodsAnnotatedWith(Class> clazz, Class extends Annotation> annotClazz) Gets a List of all the Method s in the given class, annotated with the given annotation class. return Arrays.stream(clazz.getDeclaredMethods()).filter(m -> m.getClass().isAnnotationPresent(annotClazz))
.collect(Collectors.toList());
|
Set | getMethodsAnnotatedWith(Class> clazz, Class Returns the given class's (and superclasses) declared methods that are marked with the given annotation return getMethodsAnnotatedWith(clazz, annotation, true);
|
List | getMethodsAnnotatedWith(final Class> type, final Class extends Annotation> annotation) get Methods Annotated With final List<Method> methods = new ArrayList<Method>(); Class<?> klass = type; while (klass != Object.class) { final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(klass.getDeclaredMethods())); for (final Method method : allMethods) { if (annotation == null || method.isAnnotationPresent(annotation)) { Annotation annotInstance = method.getAnnotation(annotation); methods.add(method); ... |
Method[] | getMethodsInAnnotation(Annotation anno) Returns an array containing all methods occur in the given Annotation Method[] methods = anno.annotationType().getDeclaredMethods();
return methods;
|
List | getMethodsWithAnnotation(Class extends Annotation> annotation, Class clazz) Gets a list of methods with the given annotation Method[] methods = clazz.getMethods(); List<Method> annotated = new ArrayList<Method>(); for (Method m : methods) if (m.isAnnotationPresent(annotation)) annotated.add(m); return annotated; |
Method[] | getMethodsWithAnnotation(Class extends Annotation> type, Class> obj) get Methods With Annotation return getMethodsWithAnnotation(type, obj, false);
|