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

Refaster rule that replaces redundant Stream#collect(..) calls #578

Closed
1 of 3 tasks
Stephan202 opened this issue Apr 11, 2023 · 0 comments · Fixed by #593
Closed
1 of 3 tasks

Refaster rule that replaces redundant Stream#collect(..) calls #578

Stephan202 opened this issue Apr 11, 2023 · 0 comments · Fixed by #593
Assignees
Labels
good first issue Good for newcomers new feature WIP Work in progress
Milestone

Comments

@Stephan202
Copy link
Member

Problem

There are several types of Stream#collect(..) calls for which a simpler and more canonical alternative exists. We should nudge users to use those features.

Description of the proposed new feature

  • Support a stylistic preference.
  • Avoid a common gotcha, or potential problem.
  • Improve performance.

Concretely, the idea is to implement Refaster rules for each of the cases mentioned by SonarCloud rule S4266.

So to take the first example mentioned by the rule, we would like to rewrite the following code:

stream.collect(counting())

to:

stream.count()

Considerations

  1. Some of these rules are parametric on a comparator or mapping. Make sure that those Refaster rules use the maximally generic type, such as Comparator<? super T> in case of comparator. See the method signatures of the replaced methods for details.
  2. If Introduce SonarCloud integration and resolve assorted violations #575 is merged before this issue is picked up, then we'll need to add @SuppressWarnings("java:S4266") to the new @BeforeTemplate methods. See the changes in Introduce SonarCloud integration and resolve assorted violations #575 for similar suppressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers new feature WIP Work in progress
Development

Successfully merging a pull request may close this issue.

2 participants