Search in sources :

Example 11 with CtFor

use of spoon.reflect.code.CtFor in project spoon by INRIA.

the class LoopTest method testAnnotationInForLoop.

@Test
public void testAnnotationInForLoop() throws Exception {
    CtType<?> aFoo = ModelUtils.build(new File("./src/test/resources/spoon/test/loop/testclasses/")).Type().get("spoon.test.loop.testclasses.Foo");
    CtFor aFor = aFoo.getMethod("m").getElements(new TypeFilter<>(CtFor.class)).get(0);
    assertEquals(1, ((CtLocalVariable) aFor.getForInit().get(0)).getType().getAnnotations().size());
    assertEquals(1, ((CtLocalVariable) aFor.getForInit().get(1)).getType().getAnnotations().size());
    CtForEach aForEach = aFoo.getMethod("m").getElements(new TypeFilter<>(CtForEach.class)).get(0);
    assertEquals(1, aForEach.getVariable().getType().getAnnotations().size());
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) File(java.io.File) CtFor(spoon.reflect.code.CtFor) CtForEach(spoon.reflect.code.CtForEach) Test(org.junit.Test)

Aggregations

CtFor (spoon.reflect.code.CtFor)11 Test (org.junit.Test)9 CtClass (spoon.reflect.declaration.CtClass)4 CtMethod (spoon.reflect.declaration.CtMethod)4 Factory (spoon.reflect.factory.Factory)4 CtDo (spoon.reflect.code.CtDo)3 CtIf (spoon.reflect.code.CtIf)3 CtLocalVariable (spoon.reflect.code.CtLocalVariable)3 CtSwitch (spoon.reflect.code.CtSwitch)3 CtComment (spoon.reflect.code.CtComment)2 CtConstructorCall (spoon.reflect.code.CtConstructorCall)2 CtForEach (spoon.reflect.code.CtForEach)2 CtInvocation (spoon.reflect.code.CtInvocation)2 CtReturn (spoon.reflect.code.CtReturn)2 CtStatement (spoon.reflect.code.CtStatement)2 CtSynchronized (spoon.reflect.code.CtSynchronized)2 CtTry (spoon.reflect.code.CtTry)2 CtAnonymousExecutable (spoon.reflect.declaration.CtAnonymousExecutable)2 CtConstructor (spoon.reflect.declaration.CtConstructor)2 CtParameter (spoon.reflect.declaration.CtParameter)2