Class<?> lastClassWithTheMethod = null;
// search on method @ValidateOnExecution
Collections.reverse(classHierarchy);
ValidateOnExecution validateOnExecution = null;
for (final Class<?> c : classHierarchy) {
try {
validateOnExecution = c.getDeclaredMethod(method.getName(), method.getParameterTypes()).getAnnotation(ValidateOnExecution.class);
if (lastClassWithTheMethod == null) {
lastClassWithTheMethod = c;
}
if (validateOnExecution != null) {
lastClassWithTheMethod = null;
break;
}
} catch (final Throwable h) {
// no-op
}
}
// if not found look in the class declaring the method
if (validateOnExecution == null && lastClassWithTheMethod != null) {
validateOnExecution = lastClassWithTheMethod.getAnnotation(ValidateOnExecution.class);
}
if (validateOnExecution == null) {
methodConfig = doValidMethod(method, classConfiguration);
} else {
final Collection<ExecutableType> config = new HashSet<ExecutableType>();
for (final ExecutableType type : validateOnExecution.type()) {
if (ExecutableType.IMPLICIT.equals(type)) { // on method it just means validate, even on getters
config.add(ExecutableType.NON_GETTER_METHODS);
if (lastClassWithTheMethod == null) {
config.add(ExecutableType.GETTER_METHODS);
} // else the annotation was not on the method so implicit doesn't mean getters