diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 1437b02fcf9..e8473ae26d0 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -223,6 +223,10 @@ public CtExecutableReference getOverridingExecutable( @Override public boolean isOverriding(CtExecutableReference executable) { + final boolean isSame = getSimpleName().equals(executable.getSimpleName()) && getParameters().equals(executable.getParameters()) && getActualTypeArguments().equals(executable.getActualTypeArguments()); + if (!isSame) { + return false; + } if (getDeclaringType().isAnonymous()) { if (!getDeclaringType().getDeclaringType().isSubtypeOf(executable.getDeclaringType())) { return false; @@ -230,9 +234,7 @@ public boolean isOverriding(CtExecutableReference executable) { } else if (!getDeclaringType().isSubtypeOf(executable.getDeclaringType())) { return false; } - return getSimpleName().equals(executable.getSimpleName()) - && getParameters().equals(executable.getParameters()) - && getActualTypeArguments().equals(executable.getActualTypeArguments()); + return true; } @Override diff --git a/src/test/java/spoon/test/executable/ExecutableRefTest.java b/src/test/java/spoon/test/executable/ExecutableRefTest.java index a5a743a2acb..8dc6d33d5ab 100644 --- a/src/test/java/spoon/test/executable/ExecutableRefTest.java +++ b/src/test/java/spoon/test/executable/ExecutableRefTest.java @@ -11,9 +11,14 @@ import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtMethod; +import spoon.reflect.declaration.CtType; import spoon.reflect.factory.Factory; import spoon.reflect.reference.CtExecutableReference; +import spoon.reflect.visitor.Query; +import spoon.reflect.visitor.filter.InvocationFilter; import spoon.reflect.visitor.filter.TypeFilter; +import spoon.test.executable.testclasses.Pozole; +import spoon.testing.utils.ModelUtils; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -107,4 +112,14 @@ private CtAbstractInvocation getInvocationFromMethod(String methodName) throw return (CtAbstractInvocation) ctStatement; } + + @Test + public void testOverridingMethod() throws Exception { + final CtType aPozole = ModelUtils.buildClass(Pozole.class); + final CtExecutableReference run = aPozole.getMethodsByName("run").get(0).getReference(); + + final List> elements = Query.getElements(run.getFactory(), new InvocationFilter(run)); + assertEquals(1, elements.size()); + assertEquals(run, elements.get(0).getExecutable()); + } } diff --git a/src/test/java/spoon/test/executable/testclasses/Pozole.java b/src/test/java/spoon/test/executable/testclasses/Pozole.java new file mode 100644 index 00000000000..84bf45e14e9 --- /dev/null +++ b/src/test/java/spoon/test/executable/testclasses/Pozole.java @@ -0,0 +1,12 @@ +package spoon.test.executable.testclasses; + +public class Pozole implements Runnable { + public void cook() { + run(); + } + + @Override + public void run() { + + } +}