@Override protected void handleInvocationTargetException(Throwable targetException, State state) { // superclass ignores NPEs, instead we should at least log them if (targetException instanceof NullPointerException) { logger.warn("Unexpected validation error", targetException); } super.handleInvocationTargetException(targetException, state); }
public List<MethodWrapper> apply(Class<?> param) { List<MethodWrapper> result = new ArrayList<MethodWrapper>(); for (MethodWrapper mw : checkMethods) { if (mw.isMatching(param)) result.add(mw); } return result; } });
@Override protected final boolean internalValidate(EClass class1, EObject object, DiagnosticChain diagnostics, Map<Object, Object> context) { if (checkMethods == null) { synchronized (this) { if (checkMethods == null) { Set<MethodWrapper> checkMethods = Sets.newLinkedHashSet(); checkMethods.addAll(collectMethods(getClass())); this.checkMethods = checkMethods; } } } CheckMode checkMode = CheckMode.getCheckMode(context); State state = new State(); state.chain = diagnostics; state.currentObject = object; state.checkMode = checkMode; state.context = context; for (MethodWrapper method : methodsForType.get(object.getClass())) { method.invoke(state); } return !state.hasErrors; }
private void collectMethodsImpl(AbstractDeclarativeValidator instance, Class<? extends AbstractDeclarativeValidator> clazz, Collection<Class<?>> visitedClasses, Collection<MethodWrapper> result) { if (!visitedClasses.add(clazz)) return; AbstractDeclarativeValidator instanceToUse; instanceToUse = instance; if (instanceToUse == null) { instanceToUse = newInstance(clazz); } Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { if (method.getAnnotation(Check.class) != null && method.getParameterTypes().length == 1) { result.add(new MethodWrapper(instanceToUse, method)); } } Class<? extends AbstractDeclarativeValidator> superClass = getSuperClass(clazz); if (superClass != null) collectMethodsImpl(instanceToUse, superClass, visitedClasses, result); }