Search in sources :

Example 16 with Factory

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()));
}
Also used : ModelUtils.createFactory(spoon.testing.utils.ModelUtils.createFactory) Factory(spoon.reflect.factory.Factory) Test(org.junit.Test)

Example 17 with Factory

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());
}
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 18 with Factory

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));
}
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 19 with Factory

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());
}
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 20 with Factory

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));
}
Also used : CtStatement(spoon.reflect.code.CtStatement) Factory(spoon.reflect.factory.Factory) Adobada(spoon.test.delete.testclasses.Adobada) Test(org.junit.Test)

Aggregations

Factory (spoon.reflect.factory.Factory)364 Test (org.junit.Test)322 Launcher (spoon.Launcher)154 CtClass (spoon.reflect.declaration.CtClass)87 CtMethod (spoon.reflect.declaration.CtMethod)73 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)65 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)53 File (java.io.File)41 CtStatement (spoon.reflect.code.CtStatement)36 CtTypeReference (spoon.reflect.reference.CtTypeReference)32 CtAnnotation (spoon.reflect.declaration.CtAnnotation)31 CtInvocation (spoon.reflect.code.CtInvocation)30 SpoonModelBuilder (spoon.SpoonModelBuilder)29 DefaultCoreFactory (spoon.support.DefaultCoreFactory)29 List (java.util.List)25 FileSystemFile (spoon.support.compiler.FileSystemFile)25 ArrayList (java.util.ArrayList)24 CtExpression (spoon.reflect.code.CtExpression)20 Annotation (java.lang.annotation.Annotation)19 MainTest (spoon.test.main.MainTest)19