use of spoon.reflect.factory.ConstructorFactory in project spoon by INRIA.
the class ConstructorFactoryTest method testCreateDefault.
@Test
public void testCreateDefault() {
Factory factory = new FactoryImpl(new DefaultCoreFactory(), new StandardEnvironment());
ClassFactory classf = factory.Class();
ConstructorFactory ctorf = factory.Constructor();
CtClass<?> ctclass = classf.create("Sample");
ctorf.createDefault(ctclass);
CtConstructor<?> c = ctclass.getConstructor();
Assert.assertEquals(0, c.getParameters().size());
}
use of spoon.reflect.factory.ConstructorFactory in project spoon by INRIA.
the class ConstructorFactoryTest method testCreate.
@Test
public void testCreate() throws Exception {
CtClass<?> type = build("spoon.test.testclasses", "SampleClass");
Factory factory = type.getFactory();
ConstructorFactory ctorf = factory.Constructor();
CoreFactory coref = factory.Core();
Set<ModifierKind> mods = new HashSet<ModifierKind>();
mods.add(ModifierKind.PUBLIC);
List<CtParameter<?>> params = new ArrayList<CtParameter<?>>();
CtParameter<?> param = coref.createParameter();
CtTypeReference<?> tref = factory.Type().createReference(String.class);
param.setType((CtTypeReference) tref);
param.setSimpleName("str");
params.add(param);
Set<CtTypeReference<? extends Throwable>> thrownTypes = new HashSet<CtTypeReference<? extends Throwable>>();
ctorf.create(type, mods, params, thrownTypes);
CtConstructor<?> c = type.getConstructor(tref);
Assert.assertEquals(1, c.getParameters().size());
Assert.assertEquals("str", c.getParameters().get(0).getSimpleName());
}
Aggregations