use of spoon.Metamodel in project spoon by INRIA.
the class MetamodelTest method testGetAllMetamodelInterfacess.
@Test
public void testGetAllMetamodelInterfacess() {
// contract: Spoon supports runtime introspection on the metamodel
SpoonAPI interfaces = new Launcher();
interfaces.addInputResource("src/main/java/spoon/reflect/declaration");
interfaces.addInputResource("src/main/java/spoon/reflect/code");
interfaces.addInputResource("src/main/java/spoon/reflect/reference");
interfaces.buildModel();
assertThat(Metamodel.getAllMetamodelInterfaces().stream().map(x -> x.getQualifiedName()).collect(Collectors.toSet()), equalTo(interfaces.getModel().getAllTypes().stream().map(x -> x.getQualifiedName()).collect(Collectors.toSet())));
}
use of spoon.Metamodel in project spoon by INRIA.
the class MetamodelTest method testGetterSetterFroRole.
@Test
public void testGetterSetterFroRole() {
// contract: all roles in spoon metamodel must at least have a setter and a getter
SpoonAPI interfaces = new Launcher();
interfaces.addInputResource("src/main/java/spoon/reflect/declaration");
interfaces.addInputResource("src/main/java/spoon/reflect/code");
interfaces.addInputResource("src/main/java/spoon/reflect/reference");
interfaces.buildModel();
Factory factory = interfaces.getFactory();
CtTypeReference propertyGetter = factory.Type().get(PropertyGetter.class).getReference();
CtTypeReference propertySetter = factory.Type().get(PropertySetter.class).getReference();
Set<String> expectedRoles = Arrays.stream(CtRole.values()).map(r -> r.name()).collect(Collectors.toSet());
List<CtMethod<?>> getters = interfaces.getModel().getElements(new AnnotationFilter<CtMethod<?>>(PropertyGetter.class));
Set<String> getterRoles = getters.stream().map(g -> ((CtFieldRead) g.getAnnotation(propertyGetter).getValue("role")).getVariable().getSimpleName()).collect(Collectors.toSet());
Set<CtMethod<?>> isNotGetter = getters.stream().filter(m -> !(m.getSimpleName().startsWith("get") || m.getSimpleName().startsWith("is"))).collect(Collectors.toSet());
List<CtMethod<?>> setters = interfaces.getModel().getElements(new AnnotationFilter<CtMethod<?>>(PropertySetter.class));
Set<String> setterRoles = setters.stream().map(g -> ((CtFieldRead) g.getAnnotation(propertySetter).getValue("role")).getVariable().getSimpleName()).collect(Collectors.toSet());
Set<CtMethod<?>> isNotSetter = setters.stream().filter(m -> !(m.getSimpleName().startsWith("set") || m.getSimpleName().startsWith("add") || m.getSimpleName().startsWith("insert") || m.getSimpleName().startsWith("remove"))).collect(Collectors.toSet());
Assert.assertEquals(expectedRoles, getterRoles);
Assert.assertEquals(expectedRoles, setterRoles);
Assert.assertEquals(Collections.EMPTY_SET, isNotGetter);
Assert.assertEquals(Collections.EMPTY_SET, isNotSetter);
}
Aggregations