Search in sources :

Example 1 with LambdaFilter

use of spoon.reflect.visitor.filter.LambdaFilter in project spoon by INRIA.

the class LambdaTest method testLambdaFilter.

@Test
public void testLambdaFilter() throws Exception {
    // check constructor with CtInterface
    List<String> methodNames = foo.filterChildren(new LambdaFilter((CtInterface<?>) foo.getNestedType("CheckPerson"))).map((CtLambda l) -> l.getParent(CtMethod.class).getSimpleName()).list();
    assertHasStrings(methodNames);
    // check constructor with CtTypeReference
    methodNames = foo.filterChildren(new LambdaFilter(foo.getNestedType("Check").getReference())).map((CtLambda l) -> l.getParent(CtMethod.class).getSimpleName()).list();
    assertHasStrings(methodNames, "m", "m6");
    // check empty constructor and addImplementingInterface with Interface
    methodNames = foo.filterChildren(new LambdaFilter().addImplementingInterface((CtInterface<?>) foo.getNestedType("CheckPersons"))).map((CtLambda l) -> l.getParent(CtMethod.class).getSimpleName()).list();
    assertHasStrings(methodNames, "m3", "m5");
    // check empty constructor and addImplementingInterface with CtTypeReference
    methodNames = foo.filterChildren(new LambdaFilter().addImplementingInterface(factory.createCtTypeReference(Predicate.class))).map((CtLambda l) -> l.getParent(CtMethod.class).getSimpleName()).list();
    assertHasStrings(methodNames, "m2", "m4", "m7", "m8");
}
Also used : CtInterface(spoon.reflect.declaration.CtInterface) LambdaFilter(spoon.reflect.visitor.filter.LambdaFilter) CtLambda(spoon.reflect.code.CtLambda) CtMethod(spoon.reflect.declaration.CtMethod) Predicate(java.util.function.Predicate) Test(org.junit.Test)

Aggregations

Predicate (java.util.function.Predicate)1 Test (org.junit.Test)1 CtLambda (spoon.reflect.code.CtLambda)1 CtInterface (spoon.reflect.declaration.CtInterface)1 CtMethod (spoon.reflect.declaration.CtMethod)1 LambdaFilter (spoon.reflect.visitor.filter.LambdaFilter)1