Search in sources :

Example 31 with CtExpression

use of spoon.reflect.code.CtExpression in project dspot by STAMP-project.

the class TestConstructorCreator method testGeneratorConstructionOfReturnNull.

@Test
public void testGeneratorConstructionOfReturnNull() throws Exception {
    final Factory factory = Utils.getFactory();
    final CtClass<?> createdClass = factory.Class().create("fr.inria.created.NewTestCreated");
    CtExpression constructionOf = ConstructorCreator.generateConstructionOf(createdClass.getReference());
    assertNull(constructionOf);
}
Also used : CtExpression(spoon.reflect.code.CtExpression) Factory(spoon.reflect.factory.Factory) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 32 with CtExpression

use of spoon.reflect.code.CtExpression in project dspot by STAMP-project.

the class TestConstructorCreator method testGenerateConstructorUsingFactory.

@Test
public void testGenerateConstructorUsingFactory() throws Exception {
    /*
            The ConstructorCreator can generate a call on factory.
            We consider has factory methods that:
                - are static
                - return the type expected
                - contains specific keyword in their names: build create //TODO we may need to update this list of names
         */
    final Factory factory = Utils.getFactory();
    Utils.findMethod("fr.inria.factory.FactoryTest", "test");
    final List<CtExpression<?>> aClass = ConstructorCreator.generateConstructorUsingFactory(factory.Class().get("fr.inria.factory.FactoryTest").getNestedType("aClass").getReference());
    assertEquals(2, aClass.size());
}
Also used : CtExpression(spoon.reflect.code.CtExpression) Factory(spoon.reflect.factory.Factory) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 33 with CtExpression

use of spoon.reflect.code.CtExpression in project dspot by STAMP-project.

the class TestConstructorCreator method testGenerateAllConstructorOfListOfSpecificObject.

@Test
public void testGenerateAllConstructorOfListOfSpecificObject() throws Exception {
    /*
            Test the good behavior when developers use specific implementation of List.
         */
    final Factory factory = Utils.getFactory();
    final CtTypeReference<ArrayList> listReference = factory.Type().createReference(ArrayList.class);
    listReference.addActualTypeArgument(factory.Type().get("fr.inria.statementadd.ClassParameterAmplify").getReference());
    final List<CtExpression> constructionOf = ConstructorCreator.generateAllConstructionOf(listReference);
    assertEquals(1, constructionOf.size());
}
Also used : CtExpression(spoon.reflect.code.CtExpression) ArrayList(java.util.ArrayList) Factory(spoon.reflect.factory.Factory) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Aggregations

CtExpression (spoon.reflect.code.CtExpression)33 Factory (spoon.reflect.factory.Factory)19 Test (org.junit.Test)16 CtTypeReference (spoon.reflect.reference.CtTypeReference)11 CtStatement (spoon.reflect.code.CtStatement)10 CtInvocation (spoon.reflect.code.CtInvocation)6 CtMethod (spoon.reflect.declaration.CtMethod)6 AbstractTest (fr.inria.AbstractTest)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CtAssignment (spoon.reflect.code.CtAssignment)5 CtLiteral (spoon.reflect.code.CtLiteral)5 CtNewArray (spoon.reflect.code.CtNewArray)5 Launcher (spoon.Launcher)4 CtConstructorCall (spoon.reflect.code.CtConstructorCall)4 CtLocalVariable (spoon.reflect.code.CtLocalVariable)4 CtClass (spoon.reflect.declaration.CtClass)4 CtElement (spoon.reflect.declaration.CtElement)4 CtExecutableReference (spoon.reflect.reference.CtExecutableReference)4 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)4