public static Method findAnnotatedMethod(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation, String methodName, Class<?>... paramTypes) { try { Method method = configClass.getDeclaredMethod(methodName, paramTypes); if (method != null && method.isAnnotationPresent(annotation)) { return method; } } catch (NoSuchMethodException e) { // ignore } if (configClass.getSuperclass() != null) { Method managedMethod = findAnnotatedMethod(configClass.getSuperclass(), annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } for (Class<?> iface : configClass.getInterfaces()) { Method managedMethod = findAnnotatedMethod(iface, annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } return null; }
public static Method findAnnotatedMethod(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation, String methodName, Class<?>... paramTypes) { try { Method method = configClass.getDeclaredMethod(methodName, paramTypes); if (method != null && method.isAnnotationPresent(annotation)) { return method; } } catch (NoSuchMethodException e) { // ignore } if (configClass.getSuperclass() != null) { Method managedMethod = findAnnotatedMethod(configClass.getSuperclass(), annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } for (Class<?> iface : configClass.getInterfaces()) { Method managedMethod = findAnnotatedMethod(iface, annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } return null; }
public static Method findAnnotatedMethod(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation, String methodName, Class<?>... paramTypes) { try { Method method = configClass.getDeclaredMethod(methodName, paramTypes); if (method != null && method.isAnnotationPresent(annotation)) { return method; } } catch (NoSuchMethodException e) { // ignore } if (configClass.getSuperclass() != null) { Method managedMethod = findAnnotatedMethod(configClass.getSuperclass(), annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } for (Class<?> iface : configClass.getInterfaces()) { Method managedMethod = findAnnotatedMethod(iface, annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } return null; }
/** * Find methods that are tagged with a given annotation somewhere in the hierarchy * * @param configClass the class to analyze * @return a map that associates a concrete method to the actual method tagged * (which may belong to a different class in class hierarchy) */ private static Collection<Method> findAnnotatedMethods(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation) { List<Method> result = new ArrayList<>(); // gather all publicly available methods // this returns everything, even if it's declared in a parent for (Method method : configClass.getMethods()) { // skip methods that are used internally by the vm for implementing covariance, etc if (method.isSynthetic() || method.isBridge() || Modifier.isStatic(method.getModifiers())) { continue; } // look for annotations recursively in super-classes or interfaces Method managedMethod = findAnnotatedMethod(configClass, annotation, method.getName(), method.getParameterTypes()); if (managedMethod != null) { result.add(managedMethod); } } return result; }
/** * Find methods that are tagged with a given annotation somewhere in the hierarchy * * @param configClass the class to analyze * @return a map that associates a concrete method to the actual method tagged * (which may belong to a different class in class hierarchy) */ private static Collection<Method> findAnnotatedMethods(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation) { List<Method> result = new ArrayList<>(); // gather all publicly available methods // this returns everything, even if it's declared in a parent for (Method method : configClass.getMethods()) { // skip methods that are used internally by the vm for implementing covariance, etc if (method.isSynthetic() || method.isBridge() || Modifier.isStatic(method.getModifiers())) { continue; } // look for annotations recursively in super-classes or interfaces Method managedMethod = findAnnotatedMethod(configClass, annotation, method.getName(), method.getParameterTypes()); if (managedMethod != null) { result.add(managedMethod); } } return result; }
/** * Find methods that are tagged with a given annotation somewhere in the hierarchy * * @param configClass the class to analyze * @return a map that associates a concrete method to the actual method tagged * (which may belong to a different class in class hierarchy) */ private static Collection<Method> findAnnotatedMethods(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation) { List<Method> result = new ArrayList<>(); // gather all publicly available methods // this returns everything, even if it's declared in a parent for (Method method : configClass.getMethods()) { // skip methods that are used internally by the vm for implementing covariance, etc if (method.isSynthetic() || method.isBridge() || Modifier.isStatic(method.getModifiers())) { continue; } // look for annotations recursively in super-classes or interfaces Method managedMethod = findAnnotatedMethod(configClass, annotation, method.getName(), method.getParameterTypes()); if (managedMethod != null) { result.add(managedMethod); } } return result; }