Search in sources :

Example 6 with Adobada

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

the class DeleteTest method testDeleteACaseOfASwitch.

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

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

the class DeleteTest method testDeleteReturn.

@Test
public void testDeleteReturn() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod method = adobada.getMethod("m2");
    assertEquals(1, method.getBody().getStatements().size());
    final CtStatement statement = method.getBody().getStatement(0);
    statement.delete();
    assertEquals(0, method.getBody().getStatements().size());
    assertFalse(method.getBody().getStatements().contains(statement));
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Factory(spoon.reflect.factory.Factory) Adobada(spoon.test.delete.testclasses.Adobada) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 8 with Adobada

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

the class MethodTest method testClone.

@Test
public void testClone() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod<?> m2 = adobada.getMethod("m2");
    CtMethod<?> clone = m2.clone();
    clone.setVisibility(ModifierKind.PRIVATE);
    assertEquals(ModifierKind.PUBLIC, m2.getModifiers().iterator().next());
}
Also used : Factory(spoon.reflect.factory.Factory) ModelUtils.createFactory(spoon.testing.utils.ModelUtils.createFactory) Adobada(spoon.test.delete.testclasses.Adobada) Test(org.junit.Test)

Example 9 with Adobada

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

the class DeleteTest method testDeleteAStatementInMethod.

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

Example 10 with Adobada

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

the class DeleteTest method testDeleteMethod.

@Test
public void testDeleteMethod() 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);
    int n = adobada.getMethods().size();
    // deleting m4
    method.delete();
    assertEquals(n - 1, adobada.getMethods().size());
    assertFalse(adobada.getMethods().contains(method));
}
Also used : Factory(spoon.reflect.factory.Factory) 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