Search in sources :

Example 1 with Tapas

use of spoon.test.targeted.testclasses.Tapas in project spoon by INRIA.

the class TargetedExpressionTest method testClassDeclaredInALambda.

@Test
public void testClassDeclaredInALambda() throws Exception {
    // contract: A class can be declared in a lambda expression where we use final fields.
    final CtType<Tapas> type = buildClass(Tapas.class);
    final List<CtFieldAccess> elements = new SortedList(new CtLineElementComparator());
    elements.addAll(type.getElements(new TypeFilter<>(CtFieldAccess.class)));
    assertEquals(3, elements.size());
    final CtTypeReference<Object> firstExpected = type.getFactory().Type().createReference("spoon.test.targeted.testclasses.Tapas$1$InnerSubscriber");
    CtThisAccess<Object> expectedThisAccess = type.getFactory().Code().createThisAccess(firstExpected);
    assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(firstExpected).target(expectedThisAccess).type(CtFieldWrite.class).result("this.index"), elements.get(0));
    final CtTypeReference<Object> secondExpectedInner = type.getFactory().Type().createReference("spoon.test.targeted.testclasses.Tapas$3InnerSubscriber");
    expectedThisAccess = type.getFactory().Code().createThisAccess(secondExpectedInner);
    assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(secondExpectedInner).target(expectedThisAccess).type(CtFieldWrite.class).result("this.index").isLocal(), elements.get(1));
    final CtTypeReference<Object> thirdExpectedInner = type.getFactory().Type().createReference("spoon.test.targeted.testclasses.Tapas$4InnerSubscriber");
    expectedThisAccess = type.getFactory().Code().createThisAccess(thirdExpectedInner);
    assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(thirdExpectedInner).target(expectedThisAccess).type(CtFieldWrite.class).result("this.index").isLocal(), elements.get(2));
}
Also used : CtFieldAccess(spoon.reflect.code.CtFieldAccess) CtFieldWrite(spoon.reflect.code.CtFieldWrite) Tapas(spoon.test.targeted.testclasses.Tapas) SortedList(spoon.support.util.SortedList) CtLineElementComparator(spoon.support.comparator.CtLineElementComparator) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 CtFieldAccess (spoon.reflect.code.CtFieldAccess)1 CtFieldWrite (spoon.reflect.code.CtFieldWrite)1 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)1 CtLineElementComparator (spoon.support.comparator.CtLineElementComparator)1 SortedList (spoon.support.util.SortedList)1 Tapas (spoon.test.targeted.testclasses.Tapas)1