Skip to content

Commit

Permalink
Merge pull request #592 from GerardPaligot/fix_586
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed Apr 19, 2016
2 parents ff08cc7 + 4965331 commit 9d35cf4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,18 @@ public <S extends T> CtExecutableReference<S> 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;
}
} else if (!getDeclaringType().isSubtypeOf(executable.getDeclaringType())) {
return false;
}
return getSimpleName().equals(executable.getSimpleName())
&& getParameters().equals(executable.getParameters())
&& getActualTypeArguments().equals(executable.getActualTypeArguments());
return true;
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/spoon/test/executable/ExecutableRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,4 +112,14 @@ private CtAbstractInvocation<?> getInvocationFromMethod(String methodName) throw

return (CtAbstractInvocation<?>) ctStatement;
}

@Test
public void testOverridingMethod() throws Exception {
final CtType<Pozole> aPozole = ModelUtils.buildClass(Pozole.class);
final CtExecutableReference<?> run = aPozole.getMethodsByName("run").get(0).getReference();

final List<CtInvocation<?>> elements = Query.getElements(run.getFactory(), new InvocationFilter(run));
assertEquals(1, elements.size());
assertEquals(run, elements.get(0).getExecutable());
}
}
12 changes: 12 additions & 0 deletions src/test/java/spoon/test/executable/testclasses/Pozole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package spoon.test.executable.testclasses;

public class Pozole implements Runnable {
public void cook() {
run();
}

@Override
public void run() {

}
}

0 comments on commit 9d35cf4

Please sign in to comment.