use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class ExecutableFactoryTest method testCreateReference.
@Test
public void testCreateReference() {
Factory f = createFactory();
ExecutableFactory ef = f.Executable();
String signature = "boolean Object#equals(Object)";
CtExecutableReference<Object> eref = ef.createReference(signature);
String type = eref.getType().getQualifiedName();
String decltype = eref.getDeclaringType().getQualifiedName();
String name = eref.getSimpleName();
List<CtTypeReference<?>> params = eref.getParameters();
List<CtTypeReference<?>> atas = eref.getActualTypeArguments();
Assert.assertEquals("boolean", type);
Assert.assertEquals("Object", decltype);
Assert.assertEquals("equals", name);
Assert.assertEquals(1, params.size());
Assert.assertEquals(0, atas.size());
}
use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class FieldFactoryTest method testCreateFromSource.
@Test
public void testCreateFromSource() throws Exception {
CtClass<?> target = build("spoon.test.testclasses", "SampleClass");
Factory factory = build(Foo.class, Bar.class, SuperClass.class);
final CtClass<Object> type = factory.Class().get(Foo.class);
CtField<?> source = type.getField("i");
FieldFactory ff = type.getFactory().Field();
TypeFactory tf = type.getFactory().Type();
ff.create(target, source);
CtField<?> field = target.getField("i");
Assert.assertEquals("i", field.getSimpleName());
CtTypeReference<?> tref = tf.createReference("int");
Assert.assertEquals(tref, field.getType());
CtElement parent = field.getParent();
Assert.assertTrue(parent instanceof CtClass<?>);
Assert.assertEquals("SampleClass", ((CtClass<?>) parent).getSimpleName());
}
use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class ExceptionTest method testExceptionIfNotCompilable.
@Test
public void testExceptionIfNotCompilable() throws Exception {
try {
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/resources/spoon/test/exceptions/ClassWithError.java")).build();
fail();
} catch (ModelBuildingException e) {
// perfect
}
}
use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class ExceptionTest method testExceptionInSnippet.
@Test
public void testExceptionInSnippet() {
try {
Factory factory = createFactory();
factory.Code().createCodeSnippetStatement("" + "class X {" + "public void foo() {" + // does not compile here
" int x=Foo;" + "}};").compile();
fail();
} catch (ModelBuildingException e) {
// perfect
}
}
use of spoon.reflect.factory.Factory in project spoon by INRIA.
the class EnumsTest method testGetAllMethods.
@Test
public void testGetAllMethods() throws Exception {
// contract: getAllMethods also returns the methods of Enum
final Factory factory = build(Burritos.class);
final CtType<Burritos> burritos = factory.Type().get(Burritos.class);
CtMethod name = factory.Core().createMethod();
// from Enum
name.setSimpleName("name");
name.setType(factory.Type().createReference(String.class));
assertTrue(burritos.hasMethod(name));
assertTrue(burritos.getAllMethods().contains(name));
}
Aggregations