use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class CtTypeTest method testHasMethodNotHasMethod.
@Test
public void testHasMethodNotHasMethod() {
Factory factory = createFactory();
CtClass<?> clazz = factory.Code().createCodeSnippetStatement("class X { public void foo() {} }").compile();
CtClass<?> clazz2 = factory.Code().createCodeSnippetStatement("class Y { public void foo2() {} }").compile();
assertFalse(clazz.hasMethod(clazz2.getMethods().iterator().next()));
}
use of spoon.reflect.factory.Factory 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());
}
use of spoon.reflect.factory.Factory 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));
}
use of spoon.reflect.factory.Factory 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());
}
use of spoon.reflect.factory.Factory 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));
}
Aggregations