use of spoon.test.fieldaccesses.testclasses.Panini in project spoon by INRIA.
the class FieldAccessTest method testIncrementationOnAVarIsAUnaryOperator.
@Test
public void testIncrementationOnAVarIsAUnaryOperator() throws Exception {
// contract: When we use var++, the variable is a read access with an unary operator.
final CtType<Panini> aMole = buildClass(Panini.class);
final CtMethod<?> make = aMole.getMethodsByName("make").get(0);
final List<CtUnaryOperator<?>> unaryOperators = make.getElements(new TypeFilter<CtUnaryOperator<?>>(CtUnaryOperator.class));
final CtFieldWrite<Object> fieldRead = aMole.getFactory().Core().createFieldWrite();
fieldRead.setTarget(aMole.getFactory().Code().createThisAccess(aMole.getReference(), true));
final CtFieldReference fieldReference = aMole.getField("i").getReference();
fieldRead.setVariable(fieldReference);
assertEquals(2, unaryOperators.size());
final CtUnaryOperator<?> first = unaryOperators.get(0);
assertEquals(UnaryOperatorKind.POSTINC, first.getKind());
assertEquals(fieldRead, first.getOperand());
assertEquals("(i)++", first.toString());
final CtUnaryOperator<?> second = unaryOperators.get(1);
assertEquals(UnaryOperatorKind.PREINC, second.getKind());
assertEquals(fieldRead, second.getOperand());
assertEquals("++(i)", second.toString());
}
use of spoon.test.fieldaccesses.testclasses.Panini in project spoon by INRIA.
the class FieldAccessTest method testFieldAccessInAnonymousClass.
@Test
public void testFieldAccessInAnonymousClass() throws Exception {
final Factory factory = build(Panini.class);
final CtType<Panini> panini = factory.Type().get(Panini.class);
final CtFieldRead fieldInAnonymous = panini.getElements(new TypeFilter<>(CtFieldRead.class)).get(0);
assertEquals("ingredient", fieldInAnonymous.getTarget().toString());
assertEquals("next", fieldInAnonymous.getVariable().getSimpleName());
assertEquals("ingredient.next", fieldInAnonymous.toString());
}
Aggregations