use of spoon.Launcher in project spoon by INRIA.
the class FilterTest method testOverridingMethodFromSubClassOfAbstractClass.
@Test
public void testOverridingMethodFromSubClassOfAbstractClass() throws Exception {
// contract: When we ask all overriding methods from an overriding method, we must returns all methods
// below and not above (including the declaration).
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.run();
final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
TreeSet<CtMethod<?>> ts = new TreeSet<CtMethod<?>>(new DeepRepresentationComparator());
List<CtMethod<?>> elements = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aTostada.getMethodsByName("prepare").get(0)));
ts.addAll(elements);
final List<CtMethod<?>> overridingMethods = Arrays.asList(ts.toArray(new CtMethod[0]));
assertEquals(3, overridingMethods.size());
assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(2).getParent(CtClass.class).getQualifiedName());
assertEquals(SubTostada.class, overridingMethods.get(1).getParent(CtClass.class).getActualClass());
assertEquals("spoon.test.filters.testclasses.Tostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
final CtClass<SubTostada> aSubTostada = launcher.getFactory().Class().get(SubTostada.class);
assertEquals(0, Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aSubTostada.getMethodsByName("prepare").get(0))).size());
}
use of spoon.Launcher in project spoon by INRIA.
the class FilterTest method testReuseOfBaseQuery.
@Test
public void testReuseOfBaseQuery() throws Exception {
// contract: an empty query can be used on several inputs
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput", "--level", "info" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.run();
CtClass<?> cls = launcher.getFactory().Class().get(Tacos.class);
CtClass<?> cls2 = launcher.getFactory().Class().get(Tostada.class);
// here is the query
CtQuery q = launcher.getFactory().Query().createQuery().map((CtClass c) -> c.getSimpleName());
// using it on a first input
assertEquals("Tacos", q.setInput(cls).list().get(0));
// using it on a second input
assertEquals("Tostada", q.setInput(cls2).list().get(0));
}
use of spoon.Launcher in project spoon by INRIA.
the class FilterTest method testNameFilterWithGenericType.
@Test
public void testNameFilterWithGenericType() {
// contract: NamedElementFilter of T should only return T elements
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/imports/testclasses/internal4/Constants.java");
spoon.buildModel();
CtType type = spoon.getFactory().Type().get(Constants.class);
List<CtMethod> ctMethods = type.getElements(new NamedElementFilter<>(CtMethod.class, "CONSTANT"));
assertTrue(ctMethods.isEmpty());
List<CtField> ctFields = type.getElements(new NamedElementFilter<>(CtField.class, "CONSTANT"));
assertEquals(1, ctFields.size());
assertTrue(ctFields.get(0) instanceof CtField);
}
use of spoon.Launcher in project spoon by INRIA.
the class FilterTest method testInvalidQueryStepFailurePolicyIgnore.
@Test
public void testInvalidQueryStepFailurePolicyIgnore() throws Exception {
// contract: with QueryFailurePolicy.IGNORE, no exception is thrown
// and only valid elements are kept for the next step
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput", "--level", "info" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.run();
class Context {
int count = 0;
}
Context context = new Context();
launcher.getFactory().Package().getRootPackage().filterChildren((CtElement c) -> {
return true;
}).name("step1").map((CtMethod<?> m) -> m).name("invalidStep2").map((o) -> o).name("step3").failurePolicy(QueryFailurePolicy.IGNORE).forEach((CtElement c) -> {
assertTrue(c instanceof CtMethod);
context.count++;
});
assertTrue(context.count > 0);
}
use of spoon.Launcher in project spoon by INRIA.
the class FilterTest method testEmptyQuery.
@Test
public void testEmptyQuery() throws Exception {
// contract: unbound or empty query
final Launcher launcher = new Launcher();
// contract: empty query returns no element
assertEquals(0, launcher.getFactory().createQuery().list().size());
assertEquals(0, launcher.getFactory().createQuery((Object) null).list().size());
// contract: empty query returns no element
launcher.getFactory().createQuery().forEach(x -> fail());
launcher.getFactory().createQuery((Object) null).forEach(x -> fail());
// contract: empty query calls no mapping
assertEquals(0, launcher.getFactory().createQuery().map(x -> {
fail();
return true;
}).list().size());
assertEquals(0, launcher.getFactory().createQuery((Object) null).map(x -> {
fail();
return true;
}).list().size());
// contract: empty query calls no filterChildren
assertEquals(0, launcher.getFactory().createQuery().filterChildren(x -> {
fail();
return true;
}).list().size());
assertEquals(0, launcher.getFactory().createQuery((Object) null).filterChildren(x -> {
fail();
return true;
}).list().size());
}
Aggregations