Search in sources :

Example 1 with FieldGettersMismatchException

use of com.github.havardh.javaflow.exceptions.FieldGettersMismatchException in project javaflow by havardh.

the class ClassGetterNamingVerifier method validate.

private List<Exception> validate(Class classToValidate) {
    List<Method> getters = classToValidate.getGetters();
    List<Field> fields = classToValidate.getFields();
    if (getters.size() != fields.size()) {
        return singletonList(new FieldGettersMismatchException(classToValidate.getCanonicalName(), format("Number of getters and fields is not the same.\n" + "Fields in model: %s\n" + "Getters in model: %s", fields, getters)));
    }
    List<Exception> exceptions = new ArrayList<>();
    for (Method getter : getters) {
        try {
            Field correspondingField = findFieldByGetter(classToValidate, fields, getter);
            if (!correspondingField.getType().equals(getter.getType())) {
                throw new FieldGettersMismatchException(classToValidate.getCanonicalName(), format("Type of getter %s (%s) does not correspond to field %s (%s)", getter.getName(), getter.getType(), correspondingField.getName(), correspondingField.getType()));
            }
        } catch (FieldGettersMismatchException e) {
            exceptions.add(e);
        }
    }
    return exceptions;
}
Also used : Field(com.github.havardh.javaflow.ast.Field) ArrayList(java.util.ArrayList) Method(com.github.havardh.javaflow.ast.Method) FieldGettersMismatchException(com.github.havardh.javaflow.exceptions.FieldGettersMismatchException) AggregatedException(com.github.havardh.javaflow.exceptions.AggregatedException) FieldGettersMismatchException(com.github.havardh.javaflow.exceptions.FieldGettersMismatchException)

Aggregations

Field (com.github.havardh.javaflow.ast.Field)1 Method (com.github.havardh.javaflow.ast.Method)1 AggregatedException (com.github.havardh.javaflow.exceptions.AggregatedException)1 FieldGettersMismatchException (com.github.havardh.javaflow.exceptions.FieldGettersMismatchException)1 ArrayList (java.util.ArrayList)1