Search in sources :

Example 1 with Tortillas

use of spoon.test.reference.testclasses.Tortillas in project spoon by INRIA.

the class VariableAccessTest method testReferences.

@Test
public void testReferences() throws Exception {
    /* test getReference on local variable
		*  getReference().getDeclaration() must be circular
		*/
    final CtType<Tortillas> aTortillas = buildClass(Tortillas.class);
    final CtMethod<Object> make = aTortillas.getMethod("make", aTortillas.getFactory().Type().stringType());
    final CtLocalVariable localVar = make.getBody().getStatement(0);
    final CtLocalVariable localVarCloned = localVar.clone();
    final CtLocalVariableReference localVarRef = localVar.getReference();
    final CtLocalVariableReference localVarRefCloned = localVarCloned.getReference();
    assertEquals(localVarRef.getDeclaration(), localVar);
    assertSame(localVarRef.getDeclaration(), localVar);
    assertEquals(localVar.getReference().getDeclaration(), localVar);
    assertSame(localVar.getReference().getDeclaration(), localVar);
    assertEquals(localVarRefCloned.getDeclaration(), localVarCloned);
    assertSame(localVarRefCloned.getDeclaration(), localVarCloned);
    assertEquals(localVarCloned.getReference().getDeclaration(), localVarCloned);
    assertSame(localVarCloned.getReference().getDeclaration(), localVarCloned);
}
Also used : CtLocalVariableReference(spoon.reflect.reference.CtLocalVariableReference) Tortillas(spoon.test.reference.testclasses.Tortillas) CtLocalVariable(spoon.reflect.code.CtLocalVariable) Test(org.junit.Test)

Example 2 with Tortillas

use of spoon.test.reference.testclasses.Tortillas in project spoon by INRIA.

the class VariableAccessTest method testReferencesInInitExpression.

@Test
public void testReferencesInInitExpression() throws Exception {
    /* test getReference on local variable
		*  getReference().getDeclaration() must be circular
		*/
    final CtType<Tortillas> aTortillas = buildClass(Tortillas.class);
    final CtMethod<Object> make = aTortillas.getMethod("make", aTortillas.getFactory().Type().stringType());
    final CtLocalVariable localVarNumber = make.getBody().getStatement(1);
    List<CtLocalVariableReference<?>> refs = localVarNumber.map(new LocalVariableReferenceFunction()).list();
    assertEquals(1, refs.size());
    assertSame(localVarNumber, refs.get(0).getParent(CtLocalVariable.class));
}
Also used : CtLocalVariableReference(spoon.reflect.reference.CtLocalVariableReference) Tortillas(spoon.test.reference.testclasses.Tortillas) CtLocalVariable(spoon.reflect.code.CtLocalVariable) LocalVariableReferenceFunction(spoon.reflect.visitor.filter.LocalVariableReferenceFunction) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 CtLocalVariable (spoon.reflect.code.CtLocalVariable)2 CtLocalVariableReference (spoon.reflect.reference.CtLocalVariableReference)2 Tortillas (spoon.test.reference.testclasses.Tortillas)2 LocalVariableReferenceFunction (spoon.reflect.visitor.filter.LocalVariableReferenceFunction)1