use of com.github.havardh.javaflow.ast.Class 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.Class in project javaflow by havardh.
the class ClassGetterNamingVerifierTest method shouldFailForModelWithoutGetters.
@Test
public void shouldFailForModelWithoutGetters() {
Class aClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("Class").withField(FieldBuilder.fieldBuilder().withName("someField").withType(PRIMITIVE_INT).build()).build();
AggregatedException exception = assertThrows(AggregatedException.class, () -> verifier.verify(singletonList(aClass)));
assertThat(exception.getExceptions(), hasSize(1));
}
use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.
the class ClassGetterNamingVerifierTest method shouldFailAndReportOnMultipleErroneousClasses.
@Test
public void shouldFailAndReportOnMultipleErroneousClasses() {
Class aClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("aClass").withField(FieldBuilder.fieldBuilder().withName("fieldOne").withType(PRIMITIVE_INT).build()).build();
Class bClass = ClassBuilder.classBuilder().withPackageName("com.github.havardh.models").withName("bClass").withField(FieldBuilder.fieldBuilder().withName("fieldOne").withType(PRIMITIVE_INT).build()).build();
AggregatedException exception = assertThrows(AggregatedException.class, () -> verifier.verify(asList(aClass, bClass)));
assertThat(exception.getExceptions(), hasSize(2));
}
use of com.github.havardh.javaflow.ast.Class 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)));
}
use of com.github.havardh.javaflow.ast.Class in project javaflow by havardh.
the class InheritanceTransformerTest method shouldResolveNameConflictsWithPackageName.
@Test
public void shouldResolveNameConflictsWithPackageName() {
Class parentA = ClassBuilder.classBuilder().withName("Parent").withPackageName("com.github.havardh.a").build();
Class parentB = ClassBuilder.classBuilder().withName("Parent").withPackageName("com.github.havardh.b").build();
Class child = ClassBuilder.classBuilder().withName("Child").withParent(new Parent(CanonicalName.object("com.github.havardh.a", "Parent"))).build();
transformer.transform(asList(parentA, parentB, child));
assertThat(child.getParent().get().getReference(), is(parentA));
}
Aggregations