use of org.androidannotations.ElementValidation in project androidannotations by androidannotations.
the class ValidatorParameterHelperTest method inOrderFail.
@Test
public void inOrderFail() throws Exception {
ExecutableElement executableElement = createMethod(AdapterView.class, long.class, boolean.class, Bundle.class);
ElementValidation valid = new ElementValidation("", executableElement);
//
validator.inOrder().type(boolean.class.getName()).optional().type(long.class.getName()).optional().type(int.class.getName()).optional().validate(executableElement, valid);
assertFalse(valid.isValid());
}
use of org.androidannotations.ElementValidation in project androidannotations by androidannotations.
the class BaseAnnotationHandler method validate.
@Override
public ElementValidation validate(Element element) {
ElementValidation validation = new ElementValidation(target, element);
validate(element, validation);
return validation;
}
use of org.androidannotations.ElementValidation in project androidannotations by androidannotations.
the class ValidatorParameterHelperTest method optionalStringParam.
@Test
public void optionalStringParam() throws Exception {
ExecutableElement executableElement = createMethod(String.class);
ElementValidation valid = new ElementValidation("", executableElement);
validator.type(CanonicalNameConstants.STRING).optional().validate(executableElement, valid);
assertTrue(valid.isValid());
ExecutableElement withoutArgument = createMethod();
ElementValidation valid2 = new ElementValidation("", executableElement);
validator.type(CanonicalNameConstants.STRING).optional().validate(withoutArgument, valid2);
assertTrue(valid2.isValid());
}
use of org.androidannotations.ElementValidation 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;
}
use of org.androidannotations.ElementValidation in project androidannotations by androidannotations.
the class ValidatorParameterHelperTest method anyOfTypes.
@Test
public void anyOfTypes() throws Exception {
ExecutableElement executableElement = createMethod(Integer.class, Long.class);
ElementValidation valid = new ElementValidation("", executableElement);
validator.anyOfTypes(CanonicalNameConstants.INTEGER, CanonicalNameConstants.LONG).multiple().validate(executableElement, valid);
assertTrue(valid.isValid());
}
Aggregations