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

Recipe to convert explicit getters to the Lombok annotation #623

Merged
merged 20 commits into from
Dec 13, 2024

Conversation

timo-a
Copy link
Contributor

@timo-a timo-a commented Dec 8, 2024

What's changed?

Adds new recipe to convert explicit getter methods to the lombok annotation

What's your motivation?

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

Please check especially the naming.

Anyone you would like to review specifically?

@timtebeek as discussed this is the first of several of my lombok recipes to be moved to rewrite-migrate-java

Have you considered any alternatives or workarounds?

Any additional context

This recipe was written before the introduction of traits. I guess the methods of the utils class could be traits nowadays but I'd need really specific hints to use traits here.

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

@timo-a timo-a changed the title feat: add recipe that converts explicit getters to the lombok annotation Recipe that converts explicit getters to the lombok annotation Dec 8, 2024
@timo-a timo-a marked this pull request as ready for review December 8, 2024 00:14
@timtebeek timtebeek self-requested a review December 8, 2024 10:51
timo-a and others added 3 commits December 8, 2024 13:20
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek timtebeek added the recipe Recipe requested label Dec 8, 2024
Copy link
Contributor

@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.

Great to see this already @timo-a ! I've added some polish to move the field/method name check to utils as well, and added a failing test for the inner class case not yet covered. Figured you might like the puzzle of solving that one, but do let me know if you'd like some more guidance, or me stepping in for the fix there.

@timo-a
Copy link
Contributor Author

timo-a commented Dec 10, 2024

Could you step in, please @timtebeek ? I don't have a lot of time at the moment.

BTW, you included a name check in isEffectivelyGetter. But that method didn't check the name because later recipes needed it not to (that's what I meant with "effectively": It acts as a getter, even if the name doesn't match). I have therefore renamed the method to isGetter and will reintroduce the original isEffectivelyGetter with a future recipe.

had copy-pasted from the example recipe
Copy link
Contributor

@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.

Thanks a lot for the work done here @timo-a ! The tests made it easy to simplify the logic. I quite like what we've arrived at now: just a single pass through method declarations, with doAfterVisit to annotate the field based on type, not simple name.

@timtebeek timtebeek changed the title Recipe that converts explicit getters to the lombok annotation Recipe to convert explicit getters to the Lombok annotation Dec 13, 2024
@timtebeek timtebeek merged commit 64b80fe into openrewrite:main Dec 13, 2024
@timo-a
Copy link
Contributor Author

timo-a commented Dec 15, 2024

Thanks, I had no idea you could stack doAfterVisit calls, this looks much cleaner now!

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

Successfully merging this pull request may close these issues.

Auto Lombok @Getter
2 participants