Skip to content
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

feat: add method getTopDefinitions() to identify first signature in superclass/superinterface #1821

Closed
monperrus opened this issue Jan 12, 2018 · 5 comments · Fixed by #1844
Labels

Comments

@monperrus
Copy link
Collaborator

monperrus commented Jan 12, 2018

question: bug in getOverridingExecutable? sometimes the overridden method is not found

See monperrus@774e719

@pvojtechovsky this seems to be in parameter adaptation, could you have a look at it? Thanks!

@surli surli added the bug label Jan 15, 2018
@pvojtechovsky
Copy link
Collaborator

The first failure is on

class CtScanner implements CtVisitor {
public <T> void visitCtAnnotationMethod(spoon.reflect.declaration.CtAnnotationMethod<T> annotationMethod) {...}
}

and it fails, because CtExecutableReferenceImpl#getOverridingExecutable looks in super classes only, it completely ignores super interfaces. It is like that since NOV 2007. May be it was correct for Java 5, but later Override can be applied to interface methods too. So may be Spoon needs a change in API of this method, because since Java 6, such method can return LIST of overriden methods in result of getOverridingExecutable.

WDYT?

@monperrus
Copy link
Collaborator Author

Interesting, it means that getOverridingExecutable gives the super implementation but not the super declaration. I'll do a PR to update the documentation.

What about creating a new method getTopDefinition()? (other names may be getTopSignature() or getFirstDefinition()?

The signature could be

Collection<CtMethod> CtMethod#getTopDefinition()
or
Collection<CtExecutableReference> CtMethod#getTopDefinition()

WDYT?

@pvojtechovsky
Copy link
Collaborator

where would that getTopDefinition algorithm search in?
A) in direct implemening interfaces only
B) in all implementing intefaces recursively
C) in superClasses + A) or B)
D) ?

May be we should not add new method on CtExecutableReference - because there is many possibilities what client might need, but we should instead implement new mapping function MethodDeclarationFunction, which might be configurable like

  • checkInterfaces(boolean)

Then client can call

CtExecutableReference eref = ...
eref.map(new MethodDeclarationFunction().checkInterfaces(true)).first()

to get first definition of method in some interface.

WDYT?

@monperrus
Copy link
Collaborator Author

monperrus commented Jan 17, 2018 via email

@monperrus
Copy link
Collaborator Author

monperrus commented Jan 17, 2018 via email

@monperrus monperrus changed the title bug in getOverridingExecutable: sometimes the overridden method is not found feat: add method getTopDefinitions() to identify first signature in superclass/superinterface Jan 17, 2018
@monperrus monperrus added feature and removed bug labels Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants