use of spoon.test.filters.testclasses.FieldAccessFilterTacos in project spoon by INRIA.
the class FilterTest method testFieldAccessFilter.
@Test
public void testFieldAccessFilter() throws Exception {
// also specifies VariableAccessFilter since FieldAccessFilter is only a VariableAccessFilter with additional static typing
CtClass<?> foo = factory.Package().get("spoon.test.filters").getType("Foo");
assertEquals("Foo", foo.getSimpleName());
List<CtNamedElement> elements = foo.getElements(new NamedElementFilter<>(CtNamedElement.class, "i"));
assertEquals(1, elements.size());
CtFieldReference<?> ref = (CtFieldReference<?>) (elements.get(0)).getReference();
List<CtFieldAccess<?>> expressions = foo.getElements(new FieldAccessFilter(ref));
assertEquals(2, expressions.size());
final Factory build = build(FieldAccessFilterTacos.class);
final CtType<FieldAccessFilterTacos> fieldAccessFilterTacos = build.Type().get(FieldAccessFilterTacos.class);
try {
List<CtField> fields = fieldAccessFilterTacos.getElements(new TypeFilter<CtField>(CtField.class));
for (CtField ctField : fields) {
fieldAccessFilterTacos.getElements(new FieldAccessFilter(ctField.getReference()));
}
} catch (NullPointerException e) {
fail("FieldAccessFilter must not throw a NPE.");
}
}
Aggregations