Search in sources :

Example 1 with OverriddenMethodFilter

use of spoon.reflect.visitor.filter.OverriddenMethodFilter in project spoon by INRIA.

the class FilterTest method testOverriddenMethodFromSubClassOfInterface.

@Test
public void testOverriddenMethodFromSubClassOfInterface() throws Exception {
    // contract: When we ask all overridden methods from an overriding method, we must returns all methods
    // above and not below.
    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<AbstractTostada> anAbstractTostada = launcher.getFactory().Class().get(AbstractTostada.class);
    final List<CtMethod<?>> overriddenMethods = Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(anAbstractTostada.getMethodsByName("make").get(0)));
    assertEquals(1, overriddenMethods.size());
    assertEquals(ITostada.class, overriddenMethods.get(0).getParent(CtInterface.class).getActualClass());
    final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
    OverriddenMethodFilter filter = new OverriddenMethodFilter(aTostada.getMethodsByName("make").get(0));
    final List<CtMethod<?>> overriddenMethodsFromSub = Query.getElements(launcher.getFactory(), filter);
    assertEquals(2, overriddenMethodsFromSub.size());
    assertEquals(AbstractTostada.class, overriddenMethodsFromSub.get(0).getParent(CtType.class).getActualClass());
    assertEquals(ITostada.class, overriddenMethodsFromSub.get(1).getParent(CtType.class).getActualClass());
}
Also used : OverriddenMethodFilter(spoon.reflect.visitor.filter.OverriddenMethodFilter) AbstractTostada(spoon.test.filters.testclasses.AbstractTostada) Tostada(spoon.test.filters.testclasses.Tostada) ITostada(spoon.test.filters.testclasses.ITostada) AbstractTostada(spoon.test.filters.testclasses.AbstractTostada) SubTostada(spoon.test.filters.testclasses.SubTostada) Launcher(spoon.Launcher) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 2 with OverriddenMethodFilter

use of spoon.reflect.visitor.filter.OverriddenMethodFilter in project spoon by INRIA.

the class FilterTest method testOverriddenMethodsFromSubClassOfAbstractClass.

@Test
public void testOverriddenMethodsFromSubClassOfAbstractClass() throws Exception {
    // contract: When we ask all overridden methods from an overriding method, we must returns all methods
    // above and not below.
    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);
    final List<CtMethod<?>> overridenMethods = Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(aTostada.getMethodsByName("prepare").get(0)));
    assertEquals(1, overridenMethods.size());
    assertEquals(AbstractTostada.class, overridenMethods.get(0).getParent(CtClass.class).getActualClass());
    final CtClass<SubTostada> aSubTostada = launcher.getFactory().Class().get(SubTostada.class);
    final List<CtMethod<?>> overridenMethodsFromSub = Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(aSubTostada.getMethodsByName("prepare").get(0)));
    assertEquals(2, overridenMethodsFromSub.size());
    assertEquals(AbstractTostada.class, overridenMethodsFromSub.get(0).getParent(CtClass.class).getActualClass());
    assertEquals(Tostada.class, overridenMethodsFromSub.get(1).getParent(CtClass.class).getActualClass());
}
Also used : OverriddenMethodFilter(spoon.reflect.visitor.filter.OverriddenMethodFilter) Tostada(spoon.test.filters.testclasses.Tostada) ITostada(spoon.test.filters.testclasses.ITostada) AbstractTostada(spoon.test.filters.testclasses.AbstractTostada) SubTostada(spoon.test.filters.testclasses.SubTostada) Launcher(spoon.Launcher) SubTostada(spoon.test.filters.testclasses.SubTostada) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with OverriddenMethodFilter

use of spoon.reflect.visitor.filter.OverriddenMethodFilter in project spoon by INRIA.

the class FilterTest method testOverriddenMethodFromAbstractClass.

@Test
public void testOverriddenMethodFromAbstractClass() throws Exception {
    // contract: When we declare an abstract method on an abstract class, we must return an empty list
    // when we ask all overriden methods from this 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<AbstractTostada> aClass = launcher.getFactory().Class().get(AbstractTostada.class);
    assertEquals(0, Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(aClass.getMethodsByName("prepare").get(0))).size());
    assertEquals(0, aClass.getMethodsByName("prepare").get(0).map(new OverriddenMethodQuery()).list().size());
}
Also used : OverriddenMethodFilter(spoon.reflect.visitor.filter.OverriddenMethodFilter) AbstractTostada(spoon.test.filters.testclasses.AbstractTostada) OverriddenMethodQuery(spoon.reflect.visitor.filter.OverriddenMethodQuery) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 4 with OverriddenMethodFilter

use of spoon.reflect.visitor.filter.OverriddenMethodFilter in project spoon by INRIA.

the class FilterTest method testOverriddenMethodFromInterface.

@Test
public void testOverriddenMethodFromInterface() throws Exception {
    // contract: When we declare a method in an interface, we must return an empty list
    // when we ask all overridden methods from this 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 CtInterface<ITostada> aITostada = launcher.getFactory().Interface().get(ITostada.class);
    OverriddenMethodFilter filter = new OverriddenMethodFilter(aITostada.getMethodsByName("make").get(0));
    List<CtMethod<?>> overridingMethods = Query.getElements(launcher.getFactory(), filter);
    assertEquals(0, overridingMethods.size());
    List<CtMethod> overridingMethods2 = aITostada.getMethodsByName("make").get(0).map(new OverriddenMethodQuery()).list(CtMethod.class);
    assertEquals(0, overridingMethods2.size());
}
Also used : OverriddenMethodFilter(spoon.reflect.visitor.filter.OverriddenMethodFilter) OverriddenMethodQuery(spoon.reflect.visitor.filter.OverriddenMethodQuery) Launcher(spoon.Launcher) ITostada(spoon.test.filters.testclasses.ITostada) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Launcher (spoon.Launcher)4 OverriddenMethodFilter (spoon.reflect.visitor.filter.OverriddenMethodFilter)4 CtMethod (spoon.reflect.declaration.CtMethod)3 AbstractTostada (spoon.test.filters.testclasses.AbstractTostada)3 ITostada (spoon.test.filters.testclasses.ITostada)3 OverriddenMethodQuery (spoon.reflect.visitor.filter.OverriddenMethodQuery)2 SubTostada (spoon.test.filters.testclasses.SubTostada)2 Tostada (spoon.test.filters.testclasses.Tostada)2