Search in sources :

Example 11 with Adobada

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

the class DeleteTest method testDeleteParameterOfMethod.

@Test
public void testDeleteParameterOfMethod() 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 CtParameter param = (CtParameter) method.getParameters().get(1);
    assertEquals(3, method.getParameters().size());
    param.delete();
    assertEquals(2, method.getParameters().size());
    assertFalse(method.getParameters().contains(param));
}
Also used : Factory(spoon.reflect.factory.Factory) CtParameter(spoon.reflect.declaration.CtParameter) Adobada(spoon.test.delete.testclasses.Adobada) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 12 with Adobada

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

the class DeleteTest method testDeleteAnnotationOnAClass.

@Test
public void testDeleteAnnotationOnAClass() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    assertEquals(1, adobada.getAnnotations().size());
    final CtAnnotation<? extends Annotation> annotation = adobada.getAnnotations().get(0);
    annotation.delete();
    assertEquals(0, adobada.getAnnotations().size());
    assertFalse(adobada.getAnnotations().contains(annotation));
}
Also used : Factory(spoon.reflect.factory.Factory) Adobada(spoon.test.delete.testclasses.Adobada) Test(org.junit.Test)

Example 13 with Adobada

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

the class DeleteTest method testDeleteAClassTopLevel.

@Test
public void testDeleteAClassTopLevel() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtPackage aPackage = adobada.getParent(CtPackage.class);
    assertEquals(1, aPackage.getTypes().size());
    adobada.delete();
    assertEquals(0, aPackage.getTypes().size());
    assertFalse(aPackage.getTypes().contains(adobada));
}
Also used : Factory(spoon.reflect.factory.Factory) CtPackage(spoon.reflect.declaration.CtPackage) Adobada(spoon.test.delete.testclasses.Adobada) Test(org.junit.Test)

Example 14 with Adobada

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

the class DeleteTest method testDeleteAStatementInAnonymousExecutable.

@Test
public void testDeleteAStatementInAnonymousExecutable() 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 instanceExec = anonymousExecutables.get(0);
    assertEquals(2, instanceExec.getBody().getStatements().size());
    final CtStatement statement = instanceExec.getBody().getStatement(1);
    statement.delete();
    assertEquals(1, instanceExec.getBody().getStatements().size());
    assertFalse(instanceExec.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 15 with Adobada

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

the class DeleteTest method testDeleteBodyOfAMethod.

@Test
public void testDeleteBodyOfAMethod() throws Exception {
    final Factory factory = build(Adobada.class);
    final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
    final CtMethod method = adobada.getMethod("m");
    assertNotNull(method.getBody());
    method.getBody().delete();
    assertNull(method.getBody());
}
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