-
-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review: fix issue related with overridden methods retrieved from getAllMethods #1375
Conversation
I may use your help on this one @pvojtechovsky : I'm trying to use |
I will have a look at it today evening |
@@ -894,6 +895,14 @@ public String getQualifiedName() { | |||
map(new AllTypeMembersFunction(CtMethod.class)).forEach(new CtConsumer<CtMethod<?>>() { | |||
@Override | |||
public void accept(CtMethod<?> method) { | |||
ClassTypingContext ctc = new ClassTypingContext(CtTypeImpl.this); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to move creation of ClassTypingContext above (out of the cycle). It will perform faster, because creation of ClassTypingContext is expensive and it is better to use cached information about super type hierarchy, then to create it always again.
Like this:
@Override
public Set<CtMethod<?>> getAllMethods() {
final Set<String> distinctSignatures = new HashSet<>();
final Set<CtMethod<?>> l = new SignatureBasedSortedSet<>();
final ClassTypingContext ctc = new ClassTypingContext(CtTypeImpl.this);
map(new AllTypeMembersFunction(CtMethod.class)).forEach(new CtConsumer<CtMethod<?>>() {
@Override
public void accept(CtMethod<?> method) {
for (CtMethod<?> methods : l) {
if (ctc.isSameSignature(methods, method)) {
return;
}
}
if (distinctSignatures.add(method.getSignature())) {
l.add(method);
}
}
});
return Collections.unmodifiableSet(l);
}
I would commit into this branch, but I have no permission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to move creation of ClassTypingContext above (out of the cycle).
Yes, this was my first move but as I got a lot of errors in tests, I tried inside the loop to be sure of the state of ClassTypingContext
I will change that :)
Ok, I wasn't sure but I had this feeling indeed. I'll look at your PR right now. |
@@ -643,7 +646,7 @@ private boolean isSubTypeArg(CtTypeReference<?> subArg, CtTypeReference<?> super | |||
if (typeRef instanceof CtTypeParameterReference) { | |||
CtTypeParameterReference typeParamRef = (CtTypeParameterReference) typeRef; | |||
CtTypeParameter typeParam = typeParamRef.getDeclaration(); | |||
if (typeParam.getTypeParameterDeclarer() instanceof CtExecutable) { | |||
if (typeParam != null && typeParam.getTypeParameterDeclarer() instanceof CtExecutable) { | |||
//the parameter is declared in scope of Method or Constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If typeParamRef.getDeclaration();
returns null then something is wrong ... may be it should throw SpoonException?
In what situtation it happens? Is it really correct to ignore that null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was happening in LambdaTest.testCompileLambdaGeneratedBySpoon
and MainTest.testTest
. Apparently the problem is it tries to resolve R
in public abstract R apply(T arg0);
but it never reach the interface Function
where it's defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it sounds like another bug of CtTypeParameterReference#getDeclaration()
And then I do not like the idea to ignore null here. It should throw SpoonExpeception instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it sounds like another bug of CtTypeParameterReference#getDeclaration()
Ok I'm working on it, it seems to be related with my recent changes with CtTypeParameter on method parameters.
And then I do not like the idea to ignore null here. It should throw SpoonExpeception instead.
I'll change that.
@@ -891,9 +892,16 @@ public String getQualifiedName() { | |||
public Set<CtMethod<?>> getAllMethods() { | |||
final Set<String> distinctSignatures = new HashSet<>(); | |||
final Set<CtMethod<?>> l = new SignatureBasedSortedSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This set should not be needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right! Please remove it too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would first merge this, with a clean implementation, and maybe a temporary behavioral change highlighted in the test diff. And then, we can concentrate on #1407.
getAllMethods
should not retrieve a parent method if an overridden method is defined, even if the signature is different.For example, if a class implements the method
public int compareTo(T o);
with object it will have the following signature:public int compareTo(Object o)
andgetAllMethod
should only retrieve this one.