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

feature: add CtElement#descendantIterator and CtElement#asIterable #1986

Merged
merged 8 commits into from
May 15, 2018
Merged

feature: add CtElement#descendantIterator and CtElement#asIterable #1986

merged 8 commits into from
May 15, 2018

Conversation

AndreFCruz
Copy link
Contributor

@AndreFCruz AndreFCruz commented May 8, 2018

This is a method for obtaining an Iterator over the CtElement's descendants, as suggested in #1077 .
It aims to make the CtIterator class easier to find.

@monperrus
Copy link
Collaborator

Thanks a lot for this pull-request.

Could you add a test to verify that one can use this feature in a foreach loop?

@AndreFCruz
Copy link
Contributor Author

AndreFCruz commented May 9, 2018

I added a static method CtElement.asIterable that I think facilitates the use of the Iterator.

In this way, a user can iterate with the regular for loop:

for (CtElement elem : CtElement.asIterable(ctElem)) {
        ...
}

and using the iterator's forEachRemaining (as was possible with the previous method)

ctElem.descendantIterator().forEachRemaining((CtElement elem) -> ... );

And added a test for both methods.

@monperrus
Copy link
Collaborator

Thanks a lot!

In Spoon, we don't use static interface methods.

Instead of a static method, is it possible to directly have Iterable<CtElement> asIterable() as normal interface method + implementation in CtElementImpl?

Side-note: would you put your test directly in CtIteratorTest.java?

Cheers --Martin

@AndreFCruz
Copy link
Contributor Author

Sure, moved the method to the class implementation as non-static, and moved all iteration tests to CtIteratorTest.java

@spoon-bot
Copy link
Collaborator

API changes: 4 (Detected by Revapi)

Old API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-20180503.225317-66 / New API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-SNAPSHOT

Class no longer implements interface 'java.util.Iterator'.
Old class CtIterator
New class CtIterator
Breaking binary: breaking,
Class now implements interface 'java.util.Iterator<spoon.reflect.declaration.CtElement>'.
:---: :---:
Old class CtIterator
New class CtIterator
Breaking binary: non_breaking,
Super type's type parameters changed from 'java.util.Iterator' to 'java.util.Iterator<spoon.reflect.declaration.CtElement>'.
:---: :---:
Old class CtIterator
New class CtIterator
Breaking binary: potentially_breaking,
Method was added to an interface.
Old none
New method CtElement#asIterable()
Breaking binary: non_breaking,
Method was added to an interface.
Old none
New method CtElement#descendantIterator()
Breaking binary: non_breaking,
The return type changed covarianly from 'java.lang.Object' to 'spoon.reflect.declaration.CtElement'.
Old method CtIterator#next()
New method CtIterator#next()
Breaking binary: breaking,

@monperrus
Copy link
Collaborator

Thanks a lot. I'm OK to merge if nobody disagrees with those two new methods in CtElement.

@monperrus monperrus changed the title aid for issue #1077 feature: add CtElement#descendantIterator and CtElement#asIterable May 12, 2018
@pvojtechovsky
Copy link
Collaborator

I like this PR too 👍

@monperrus monperrus merged commit c79078a into INRIA:master May 15, 2018
@monperrus
Copy link
Collaborator

Thanks a lot André for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants