use of org.androidannotations.internal.exception.ValidationException in project androidannotations by androidannotations.
the class ModelValidator method validate.
public AnnotationElements validate(AnnotationElements extractedModel, AnnotationElementsHolder validatingHolder) throws ValidationException {
LOGGER.info("Validating elements");
List<ElementValidation> failedValidations = new ArrayList<>();
for (AnnotationHandler annotationHandler : environment.getHandlers()) {
if (!annotationHandler.isEnabled()) {
continue;
}
String validatorSimpleName = annotationHandler.getClass().getSimpleName();
String annotationName = annotationHandler.getTarget();
Set<? extends Element> annotatedElements = extractedModel.getRootAnnotatedElements(annotationName);
Set<Element> validatedAnnotatedElements = new LinkedHashSet<>();
validatingHolder.putRootAnnotatedElements(annotationName, validatedAnnotatedElements);
if (!annotatedElements.isEmpty()) {
LOGGER.debug("Validating with {}: {}", validatorSimpleName, annotatedElements);
}
for (Element annotatedElement : annotatedElements) {
ElementValidation elementValidation = annotationHandler.validate(annotatedElement);
AnnotationMirror annotationMirror = elementValidation.getAnnotationMirror();
for (ElementValidation.Error error : elementValidation.getErrors()) {
LOGGER.error(error.getMessage(), error.getElement(), annotationMirror);
}
for (String warning : elementValidation.getWarnings()) {
LOGGER.warn(warning, elementValidation.getElement(), elementValidation.getAnnotationMirror());
}
if (elementValidation.isValid()) {
validatedAnnotatedElements.add(annotatedElement);
} else {
failedValidations.add(elementValidation);
LOGGER.warn("Element {} invalidated by {}", annotatedElement, annotatedElement, validatorSimpleName);
}
}
}
if (!failedValidations.isEmpty()) {
throw new ValidationException(failedValidations);
}
return validatingHolder;
}
Aggregations