use of spoon.reflect.visitor.filter.InvocationFilter in project spoon by INRIA.
the class ExecutableRefTest method testOverridingMethod.
@Test
public void testOverridingMethod() throws Exception {
final CtType<Pozole> aPozole = ModelUtils.buildClass(Pozole.class);
final CtExecutableReference<?> run = aPozole.getMethodsByName("run").get(0).getReference();
final List<CtInvocation<?>> elements = Query.getElements(run.getFactory(), new InvocationFilter(run));
assertEquals(1, elements.size());
assertEquals(run, elements.get(0).getExecutable());
}
use of spoon.reflect.visitor.filter.InvocationFilter in project spoon by INRIA.
the class FilterTest method testInvocationFilterWithExecutableInLibrary.
@Test
public void testInvocationFilterWithExecutableInLibrary() throws Exception {
// contract: When we have an invocation of an executable declared in a library,
// we can filter it and get the executable of the invocation.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.run();
final CtClass<Tacos> aTacos = launcher.getFactory().Class().get(Tacos.class);
final CtInvocation<?> invSize = aTacos.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
if (element.getExecutable() == null) {
return false;
}
return "size".equals(element.getExecutable().getSimpleName()) && super.matches(element);
}
}).get(0);
final List<CtInvocation<?>> invocations = aTacos.getElements(new InvocationFilter(invSize.getExecutable()));
assertEquals(1, invocations.size());
final CtInvocation<?> expectedInv = invocations.get(0);
assertNotNull(expectedInv);
final CtExecutableReference<?> expectedExecutable = expectedInv.getExecutable();
assertNotNull(expectedExecutable);
assertEquals("size", expectedExecutable.getSimpleName());
assertNull(expectedExecutable.getDeclaration());
CtExecutable<?> exec = expectedExecutable.getExecutableDeclaration();
assertEquals("size", exec.getSimpleName());
assertEquals("ArrayList", ((CtClass) exec.getParent()).getSimpleName());
final CtExecutable<?> declaration = expectedExecutable.getExecutableDeclaration();
assertNotNull(declaration);
assertEquals("size", declaration.getSimpleName());
}
use of spoon.reflect.visitor.filter.InvocationFilter in project spoon by INRIA.
the class TemplateMatcher method getMethods.
/**
* Searches for all invocations of {@link TemplateParameter#S()} in "root", a CtClass model of {@link Template}
*
* @param root CtClass model of {@link Template}
*/
private List<CtInvocation<?>> getMethods(CtClass<? extends Template<?>> root) {
CtExecutableReference<?> methodRef = root.getFactory().Executable().createReference(root.getFactory().Type().createReference(TemplateParameter.class), root.getFactory().Type().createTypeParameterReference("T"), "S");
List<CtInvocation<?>> meths = Query.getElements(root, new InvocationFilter(methodRef));
return meths;
}
Aggregations