Search in sources :

Example 1 with Adobada

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

the class DeleteTest method testDeleteChainOfAssignment.

@Test
public void testDeleteChainOfAssignment() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod method = adobada.getMethod("m4", factory.Type().INTEGER_PRIMITIVE, factory.Type().FLOAT_PRIMITIVE, factory.Type().STRING);
    final CtAssignment chainOfAssignment = method.getElements(new TypeFilter<>(CtAssignment.class)).get(0);
    assertNotNull(chainOfAssignment.getAssignment());
    chainOfAssignment.getAssignment().delete();
    assertNull(chainOfAssignment.getAssignment());
}
Also used : CtAssignment(spoon.reflect.code.CtAssignment) Factory(spoon.reflect.factory.Factory) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Adobada(spoon.test.delete.testclasses.Adobada) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 2 with Adobada

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

the class DeleteTest method testDeleteAStatementInStaticAnonymousExecutable.

@Test
public void testDeleteAStatementInStaticAnonymousExecutable() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final List<CtAnonymousExecutable> anonymousExecutables = adobada.getAnonymousExecutables();
    final CtAnonymousExecutable staticExec = anonymousExecutables.get(1);
    assertEquals(2, staticExec.getBody().getStatements().size());
    final CtStatement statement = staticExec.getBody().getStatement(1);
    statement.delete();
    assertEquals(1, staticExec.getBody().getStatements().size());
    assertFalse(staticExec.getBody().getStatements().contains(statement));
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Factory(spoon.reflect.factory.Factory) Adobada(spoon.test.delete.testclasses.Adobada) CtAnonymousExecutable(spoon.reflect.declaration.CtAnonymousExecutable) Test(org.junit.Test)

Example 3 with Adobada

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

the class DeleteTest method testDeleteConditionInACondition.

@Test
public void testDeleteConditionInACondition() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod method = adobada.getMethod("m4", factory.Type().INTEGER_PRIMITIVE, factory.Type().FLOAT_PRIMITIVE, factory.Type().STRING);
    final CtIf anIf = method.getElements(new TypeFilter<>(CtIf.class)).get(0);
    assertNotNull(anIf.getCondition());
    anIf.getCondition().delete();
    assertNull(anIf.getCondition());
}
Also used : Factory(spoon.reflect.factory.Factory) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Adobada(spoon.test.delete.testclasses.Adobada) CtMethod(spoon.reflect.declaration.CtMethod) CtIf(spoon.reflect.code.CtIf) Test(org.junit.Test)

Example 4 with Adobada

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

the class DeleteTest method testDeleteAStatementInConstructor.

@Test
public void testDeleteAStatementInConstructor() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtConstructor<Adobada> constructor = adobada.getConstructor();
    assertEquals(3, constructor.getBody().getStatements().size());
    final CtStatement statement = constructor.getBody().getStatement(1);
    statement.delete();
    assertEquals(2, constructor.getBody().getStatements().size());
    assertFalse(constructor.getBody().getStatements().contains(statement));
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Factory(spoon.reflect.factory.Factory) Adobada(spoon.test.delete.testclasses.Adobada) Test(org.junit.Test)

Example 5 with Adobada

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

the class DeleteTest method testDeleteStatementInCase.

@Test
public void testDeleteStatementInCase() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod method = adobada.getMethod("m3");
    final CtCase aCase = method.getElements(new TypeFilter<>(CtCase.class)).get(0);
    assertEquals(2, aCase.getStatements().size());
    final CtStatement statement = aCase.getStatements().get(1);
    statement.delete();
    assertEquals(1, aCase.getStatements().size());
    assertFalse(aCase.getStatements().contains(statement));
}
Also used : CtStatement(spoon.reflect.code.CtStatement) CtCase(spoon.reflect.code.CtCase) Factory(spoon.reflect.factory.Factory) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Adobada(spoon.test.delete.testclasses.Adobada) CtMethod(spoon.reflect.declaration.CtMethod) 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