use of com.github.havardh.javaflow.ast.Type in project javaflow by havardh.
the class JavaFlowTest method parseAll.
private static Map<String, Type> parseAll(String... modelNames) {
FileReader adapter = new FileReader();
Parser parser = new JavaParser();
Transformer transformer = new InheritanceTransformer();
List<Type> types = stream(modelNames).map(name -> BASE_PATH + name + ".java").map(adapter::read).map(Optional::get).map(parser::parse).map(Optional::get).collect(toList());
transformer.transform(types);
return types.stream().collect(toMap(type -> type.getCanonicalName().getName(), identity()));
}
use of com.github.havardh.javaflow.ast.Type in project javaflow by havardh.
the class MemberFieldsPresentVerifier method verify.
/**
* Verifies that there are no missing types referenced
* in the list of {@code Type}.
*
* A missing type is found when a type is referenced which is not
* in the given set of types of in the {@code TypeMap} of the verifier
* If a any missing types are discovered a {@code MissingTypeException}
* is thrown containing the complete list of missing types.
*
* @param types list of {@code Type} to verify
* @throws MissingTypeException when a missing type is found
*/
@Override
public void verify(List<Type> types) {
Set<CanonicalName> nameSet = types.stream().map(Type::getCanonicalName).collect(toSet());
Map<Type, List<Field>> missingTypes = new HashMap<>();
for (Type type : types.stream().filter(t -> t instanceof Class).collect(toList())) {
((Class) type).getFields().stream().filter(field -> !nameSet.contains(field.getType().getCanonicalName())).filter(field -> !isObject(field.getType().toString())).filter(field -> !isPrimitive(field.getType().toString())).filter(field -> !customTypes.containsKey(field.getType().toString())).forEach(field -> missingTypes.compute(type, (ignored, fields) -> fields == null ? singletonList(field) : concat(fields, singletonList(field))));
}
if (!missingTypes.isEmpty()) {
throw new MissingTypeException(missingTypes);
}
}
use of com.github.havardh.javaflow.ast.Type in project javaflow by havardh.
the class MemberFieldsPresentVerifierTest method shouldFailTypeWithMissingMember.
@Test
public void shouldFailTypeWithMissingMember() {
Field field = fieldBuilder().withName("name").withType(TypeBuilder.type().withName(CanonicalName.fromString("com.github.havardh.Type")).build()).build();
Class aClass = ClassBuilder.classBuilder().withName("Test1").withField(field).build();
MissingTypeException exception = assertThrows(MissingTypeException.class, () -> verifier.verify(singletonList(aClass)));
Map<Type, List<Field>> missing = exception.getTypes();
assertThat(missing.get(aClass), is(singletonList(field)));
}
Aggregations