use of spoon.Launcher in project spoon by INRIA.
the class GenericsTest method testGenericsInQualifiedNameInConstructorCall.
@Test
public void testGenericsInQualifiedNameInConstructorCall() throws Exception {
final Launcher launcher = new Launcher();
launcher.run(new String[] { "-i", "./src/test/java/spoon/test/generics/testclasses/", "-o", "./target/spooned/" });
final CtClass<Tacos> aTacos = launcher.getFactory().Class().get(Tacos.class);
final CtType<?> burritos = aTacos.getNestedType("Burritos");
SortedList<CtConstructorCall> elements = new SortedList<CtConstructorCall>(new CtLineElementComparator());
elements.addAll(burritos.getElements(new TypeFilter<>(CtConstructorCall.class)));
assertEquals(3, elements.size());
// Constructor call.
assertEquals(0, elements.get(1).getExecutable().getType().getActualTypeArguments().size());
assertNotNull(elements.get(1).getType().getDeclaringType());
assertEquals("new Pozole()", elements.get(1).toString());
assertEquals(2, elements.get(0).getExecutable().getType().getActualTypeArguments().size());
assertNotNull(elements.get(0).getType().getDeclaringType());
assertEquals("new Burritos<K, V>()", elements.get(0).toString());
// New class.
assertEquals(2, elements.get(2).getExecutable().getType().getActualTypeArguments().size());
assertNotNull(elements.get(2).getType().getDeclaringType());
assertEquals("new Burritos<K, V>() {}", elements.get(2).toString());
}
use of spoon.Launcher in project spoon by INRIA.
the class GenericsTest method testWildCardonShadowClass.
@Test
public void testWildCardonShadowClass() throws Exception {
// contract: generics should be treated the same way in shadow classes
// test that apply argument type contains a wildcard
Launcher launcher = new Launcher();
Factory factory = launcher.getFactory();
launcher.addInputResource("src/test/java/spoon/test/generics/testclasses/FakeTpl.java");
launcher.buildModel();
CtInterface<?> fakeTplItf = factory.Interface().get("spoon.test.generics.testclasses.FakeTpl");
checkFakeTpl(fakeTplItf);
// same test with a shadow class
launcher = new Launcher();
factory = launcher.getFactory();
CtInterface<?> fakeTplItf2 = factory.Interface().get(FakeTpl.class);
checkFakeTpl(fakeTplItf2);
}
use of spoon.Launcher in project spoon by INRIA.
the class GenericsTest method testIsSameSignatureWithMethodGenerics.
@Test
public void testIsSameSignatureWithMethodGenerics() {
Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/generics/testclasses2/SameSignature2.java");
launcher.buildModel();
CtClass ctClass = launcher.getFactory().Class().get(SameSignature2.class);
CtMethod classMethod = (CtMethod) ctClass.getMethodsByName("visitCtConditional").get(0);
CtType<?> iface = launcher.getFactory().Type().get("spoon.test.generics.testclasses2.ISameSignature");
CtMethod ifaceMethod = (CtMethod) iface.getMethodsByName("visitCtConditional").get(0);
ClassTypingContext ctcSub = new ClassTypingContext(ctClass.getReference());
assertTrue(ctcSub.isOverriding(classMethod, ifaceMethod));
assertTrue(ctcSub.isOverriding(ifaceMethod, classMethod));
assertTrue(ctcSub.isSubSignature(classMethod, ifaceMethod));
assertTrue(ctcSub.isSubSignature(ifaceMethod, classMethod));
assertTrue(ctcSub.isSameSignature(classMethod, ifaceMethod));
assertTrue(ctcSub.isSameSignature(ifaceMethod, classMethod));
}
use of spoon.Launcher in project spoon by INRIA.
the class GenericsTest method testIsSameSignatureWithGenerics.
@Test
public void testIsSameSignatureWithGenerics() {
Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/generics/testclasses/SameSignature.java");
launcher.buildModel();
CtClass ctClass = launcher.getFactory().Class().get(SameSignature.class);
List<CtMethod> methods = ctClass.getMethodsByName("forEach");
assertEquals(1, methods.size());
CtType<?> iterableItf = launcher.getFactory().Type().get(Iterable.class);
List<CtMethod<?>> methodsItf = iterableItf.getMethodsByName("forEach");
assertEquals(1, methodsItf.size());
ClassTypingContext ctc = new ClassTypingContext(ctClass.getReference());
assertTrue(ctc.isOverriding(methods.get(0), methodsItf.get(0)));
assertTrue(ctc.isSubSignature(methods.get(0), methodsItf.get(0)));
assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0)));
}
use of spoon.Launcher in project spoon by INRIA.
the class ImportTest method testImportStaticAndFieldAccessWithImport.
@Test
public void testImportStaticAndFieldAccessWithImport() throws Exception {
// contract: Qualified field access and an import static with import should import the type first, and not use static import
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput", "--with-imports" });
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses/internal4/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses/Tacos.java");
launcher.buildModel();
final CtType<Object> aTacos = launcher.getFactory().Type().get(Tacos.class);
final CtStatement assignment = aTacos.getMethod("m").getBody().getStatement(0);
assertTrue(assignment instanceof CtLocalVariable);
assertEquals("Constants.CONSTANT.foo", ((CtLocalVariable) assignment).getAssignment().toString());
}
Aggregations