Skip to content

Commit

Permalink
fix CtExecutableReference#isOverriding on anonymous class
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Mar 14, 2017
1 parent 34b1226 commit 29a7880
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ public boolean isOverriding(CtExecutableReference<?> executable) {
if (!isSame) {
return false;
}
if (getDeclaringType().isAnonymous()) {
if (!getDeclaringType().getDeclaringType().isSubtypeOf(executable.getDeclaringType())) {
return false;
}
} else if (!getDeclaringType().isSubtypeOf(executable.getDeclaringType())) {
if (!getDeclaringType().isSubtypeOf(executable.getDeclaringType())) {
return false;
}
return true;
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/spoon/test/filters/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ public void testOverridingMethodFromSubClassOfAbstractClass() throws Exception {


final List<CtMethod<?>> overridingMethods = Arrays.asList(ts.toArray(new CtMethod[0]));
assertEquals(2, overridingMethods.size());
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());

Expand Down Expand Up @@ -328,13 +329,15 @@ public void testOverridingMethodFromSubClassOfInterface() throws Exception {

final CtClass<AbstractTostada> anAbstractTostada = launcher.getFactory().Class().get(AbstractTostada.class);

final List<CtMethod<?>> overridingMethods = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(anAbstractTostada.getMethodsByName("make").get(0)));
List<CtMethod<?>> overridingMethods = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(anAbstractTostada.getMethodsByName("make").get(0)));
assertEquals(2, overridingMethods.size());
assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
assertEquals(Tostada.class, overridingMethods.get(1).getParent(CtClass.class).getActualClass());

final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
assertEquals(0, Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aTostada.getMethodsByName("make").get(0))).size());
overridingMethods = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aTostada.getMethodsByName("make").get(0)));
assertEquals(1, overridingMethods.size());
assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
}

@Test
Expand Down

0 comments on commit 29a7880

Please sign in to comment.