Skip to content

feat: add recipe that prefers guava ranges #787

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

timo-a
Copy link
Contributor

@timo-a timo-a commented Jul 6, 2025

What's changed?

adds recipe that converts from.compareTo(candidate) <= 0 && candidate.compareTo(to) <= 0 into more idiomatic guava ranges.
Covers opened, closed and half-open intervals of Comparables and primitives.

What's your motivation?

Make code more readable

Anything in particular you'd like reviewers to focus on?

  1. I chose candidate as a name for the object that is tested for its membership. Maybe there is a better name.
  2. from <= candidate && candidate <= to is fairly easy to read. For uniformity, I chose to have it converted to Range.closed(from, to).contains(candidate) anyway.

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jul 6, 2025
@timtebeek timtebeek self-requested a review July 7, 2025 08:45
@timtebeek timtebeek added the recipe Recipe requested label Jul 7, 2025
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Jul 7, 2025
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Perfect use case for Refaster here @timo-a ; thanks a lot for adding these. Did you already try them out in detail on your projects?

I'll need to take a closer look still at the various open/closed vs <= operators used, but should be fairly straightforward to compare and get merged after that.

@timtebeek timtebeek self-requested a review July 7, 2025 08:49
@timo-a
Copy link
Contributor Author

timo-a commented Jul 8, 2025

I have not tried them out in any project! Take your time to review, there is no rush 😄

One more thing, can these be published under Apache 2? I believe the community involvement here is significant, so that should work according to the license page. As that page now explicitly forbids consultants to use MSAL recipes, I want to ensure my colleagues and I can use those recipes at work. (I have already published them in my own repo under apache 2 but it would be nice to have them in the official catalogue)

@timtebeek timtebeek marked this pull request as draft July 8, 2025 21:46
@timtebeek
Copy link
Member

Hi @timo-a ; while I'm certainly sympathetic to your request, for now we lack an ability to license individual recipes separately. We apply recipes per module, and apply those licenses through a mixture of build tool plugins to update headers, META-INF and pom.xml <license> entries. Those plugins all work per module as opposed to per recipe, and it could get quite complicated to explain what is and isn't licensed in a particular way.

So while we'd love to adopt your recipes and distribute those to the wider community, we can not make individual exceptions here unfortunately.

Up to you then if you'd still like to contribute these for the wider community to consume, where we take on a role to polish, release and maintain these going forward. And of course you can still separately keep your own internal copies in parallel as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Status: Ready to Review
Development

Successfully merging this pull request may close these issues.

2 participants