use of spoon.reflect.factory.Factory 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));
}
use of spoon.reflect.factory.Factory 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));
}
use of spoon.reflect.factory.Factory 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));
}
use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class EqualTest method testEqualsComment.
@Test
public void testEqualsComment() throws Exception {
Factory factory = new Launcher().createFactory();
CtLocalVariable<?> var = factory.Code().createCodeSnippetStatement("int i=0").compile();
CtLocalVariable<?> var2 = var.clone();
var2.addComment(factory.Code().createComment("foo", CtComment.CommentType.INLINE));
assertNotEquals(1, var.getComments().size());
assertNotEquals(var2, var);
}
use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class EqualTest method testEqualsMultitype.
@Test
public void testEqualsMultitype() throws Exception {
Factory factory = new Launcher().createFactory();
CtTry var = factory.Code().createCodeSnippetStatement("try{}catch(RuntimeException | AssertionError e){}").compile();
CtTry var2 = var.clone();
assertEquals(2, var2.getCatchers().get(0).getParameter().getMultiTypes().size());
// removing a multitype
var2.getCatchers().get(0).getParameter().getMultiTypes().remove(0);
assertEquals(1, var2.getCatchers().get(0).getParameter().getMultiTypes().size());
assertNotEquals(var2, var);
}
Aggregations