Skip to content

Commit

Permalink
refactor CtExecutableReference#isOverriding
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Apr 16, 2017
1 parent 95de099 commit 2411e3f
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import spoon.reflect.visitor.filter.NameFilter;
import spoon.support.reflect.declaration.CtElementImpl;
import spoon.support.util.RtHelper;
import spoon.support.visitor.MethodTypingContext;
import spoon.support.visitor.SignaturePrinter;

import java.lang.reflect.AnnotatedElement;
Expand Down Expand Up @@ -232,14 +233,25 @@ 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;
CtExecutable<?> exec = executable.getDeclaration();
if (exec == null) {
//the declaration of this executable is not in spoon model
//use light detection algorithm, which ignores generic types
final boolean isSame = getSimpleName().equals(executable.getSimpleName()) && getParameters().equals(executable.getParameters()) && getActualTypeArguments().equals(executable.getActualTypeArguments());
if (!isSame) {
return false;
}
if (!getDeclaringType().isSubtypeOf(executable.getDeclaringType())) {
return false;
}
return true;
}
if (!getDeclaringType().isSubtypeOf(executable.getDeclaringType())) {
return false;
if (exec instanceof CtMethod<?>) {
CtMethod<?> method = (CtMethod<?>) exec;
return new MethodTypingContext().setExecutableReference(this).isOverriding(method);
}
return true;
//it is not a method. So we can return true only if it is reference to the this executable
return exec == getDeclaration();
}

@Override
Expand Down

0 comments on commit 2411e3f

Please sign in to comment.