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

Introduce CollectionIterator Refaster rule #1347

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

mohamedsamehsalah
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah commented Sep 30, 2024

Suggested commit message

Introduce `CollectionIterator` Refaster rule (#1347)

This rule supersedes the more specific `ImmutableCollectionIterator` rule.

Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 added this to the 0.19.0 milestone Sep 30, 2024
mohamedsamehsalah and others added 2 commits September 30, 2024 18:49
@Stephan202 Stephan202 force-pushed the mohamedsamehsalah/collection-iterator branch from beb74e6 to 012b5e4 Compare September 30, 2024 17:06
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit and updated the suggested commit message. Nice suggestion @mohamedsamehsalah!

* Don't call {@link ImmutableCollection#asList()} if {@link ImmutableCollection#iterator()} is
* called on the result; call it directly.
*/
/** Prefer {@link ImmutableCollection#iterator()} over more contrived alternatives. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also call out that these alternatives are likely less performant.

static final class ImmutableCollectionIterator<T> {
@BeforeTemplate
Iterator<T> before(ImmutableCollection<T> collection) {
return collection.asList().iterator();
return Refaster.anyOf(collection.stream().iterator(), collection.asList().iterator());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's due to copy-pasta from the rule above, but we can actually generalize the first expression to any Collection.

Copy link
Contributor Author

@mohamedsamehsalah mohamedsamehsalah Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I missed the generalization part 😅

Thanks @Stephan202 ❤️

return ImmutableSet.of(1).asList().iterator();
ImmutableSet<Iterator<Integer>> testImmutableCollectionIterator() {
return ImmutableSet.of(
ImmutableSet.of(1).stream().iterator(), ImmutableSet.of(1).asList().iterator());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ImmutableSet.of(1).stream().iterator(), ImmutableSet.of(1).asList().iterator());
ImmutableSet.of(1).stream().iterator(), ImmutableSet.of(2).asList().iterator());

@mohamedsamehsalah
Copy link
Contributor Author

Added a commit and updated the suggested commit message. Nice suggestion @mohamedsamehsalah!

It was actually your suggestion 🚀 Thanks for review. 😃

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🚀 !

@rickie rickie merged commit beb96f0 into master Oct 1, 2024
16 checks passed
@rickie rickie deleted the mohamedsamehsalah/collection-iterator branch October 1, 2024 08:05
@Stephan202 Stephan202 changed the title Extend ImmutableCollectionIterator refaster rule Introduce CollectionIterator Refaster rule Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants