use of com.github.havardh.javaflow.ast.Method 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;
}
use of com.github.havardh.javaflow.ast.Method in project javaflow by havardh.
the class ClassVisitor method visit.
@Override
public void visit(MethodDeclaration method, ClassBuilder builder) {
super.visit(method, builder);
TypeFactory factory = new TypeFactory(packageName, imports);
if (isClass((ClassOrInterfaceDeclaration) method.getParentNode()) && isGetter(method.getName(), method.getType().toString())) {
builder.withGetter(new Method(method.getName(), factory.build(method.getType().toString(), method.getType() instanceof PrimitiveType)));
}
}
Aggregations