Search in sources :

Example 16 with Adobada

use of spoon.test.delete.testclasses.Adobada in project spoon by INRIA.

the class QualifiedThisRefTest method testCloneThisAccess.

@Test
public void testCloneThisAccess() throws Exception {
    // contract: the target of "this" is correct and can be cloned
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod<?> m2 = adobada.getMethod("methodUsingjlObjectMethods");
    CtThisAccess th = (CtThisAccess) m2.getElements(new TypeFilter(CtThisAccess.class)).get(0);
    assertEquals(true, th.isImplicit());
    assertEquals("notify()", th.getParent().toString());
    CtInvocation<?> clone = m2.clone().getBody().getStatement(0);
    // clone preserves implicitness
    assertEquals(true, clone.getTarget().isImplicit());
    // the original bug
    assertEquals("notify()", clone.toString());
// note that this behavior means that you can only keep cloned "this" in the same class,
// and you cannot "transplant" a cloned "this" to another class
// it makes perfectly sense about the meaning of this.
// to "transplant" a this, you have to first set the target to null
}
Also used : Factory(spoon.reflect.factory.Factory) CtThisAccess(spoon.reflect.code.CtThisAccess) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Adobada(spoon.test.delete.testclasses.Adobada) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Factory (spoon.reflect.factory.Factory)16 Adobada (spoon.test.delete.testclasses.Adobada)16 CtMethod (spoon.reflect.declaration.CtMethod)9 CtStatement (spoon.reflect.code.CtStatement)6 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)5 CtCase (spoon.reflect.code.CtCase)2 CtAnonymousExecutable (spoon.reflect.declaration.CtAnonymousExecutable)2 CtAssignment (spoon.reflect.code.CtAssignment)1 CtIf (spoon.reflect.code.CtIf)1 CtSwitch (spoon.reflect.code.CtSwitch)1 CtThisAccess (spoon.reflect.code.CtThisAccess)1 CtPackage (spoon.reflect.declaration.CtPackage)1 CtParameter (spoon.reflect.declaration.CtParameter)1 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)1