-
Notifications
You must be signed in to change notification settings - Fork 169
chore: Apply OpenRewrite recipe best practices #1926
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
chore: Apply OpenRewrite recipe best practices #1926
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR applies OpenRewrite recipe best practices to the codebase, including code formatting improvements, parameter naming consistency, and IDE language injection hints for better developer experience. The changes also add the OpenRewrite Maven plugin configuration to make it easier to run these best practices in the future.
Key Changes
- Added OpenRewrite Maven plugin to enable automated best practice enforcement
- Improved test code readability by converting string concatenation to text blocks with
@Language("java")annotations - Standardized parameter naming in visitor methods from
executionContexttoctx - Simplified conditional logic by removing unnecessary else blocks and using early returns
- Applied string literal comparison best practices using
.equals()with literals on the left side
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| migration/pom.xml | Added OpenRewrite Maven plugin configuration with rewrite-migrate-java and rewrite-rewrite dependencies |
| SortingMigrationRecipeTest.java | Added @language annotations and converted to helper methods with language hints |
| SolverManagerBuilderRecipeTest.java | Added @language annotations, reordered imports, and added //language=java comment |
| SolutionManagerRecommendAssignmentRecipeTest.java | Added @language annotations to helper methods |
| SingleConstraintAssertionRecipeTest.java | Added @language annotations to helper methods |
| ScoreManagerMethodsRecipeTest.java | Added @language annotations to helper methods |
| ScoreGettersRecipeTest.java | Added @language annotations, converted string concatenation to text blocks |
| RemoveConstraintPackageRecipeTest.java | Converted string concatenation to text blocks with @language annotations |
| NullableRecipeTest.java | Added @language annotations and //language=java comments |
| ConstraintRefRecipeTest.java | Added @language annotations to helper methods |
| AsConstraintRecipeTest.java | Converted extensive string concatenation to text blocks, added @language annotations |
| SolverManagerBuilderRecipe.java | Renamed executionContext parameter to ctx |
| ScoreManagerMethodsRecipe.java | Renamed executionContext parameter to ctx, fixed string formatting |
| ScoreGettersRecipe.java | Renamed executionContext parameter to ctx, simplified if-else logic, reformatted string concatenation |
| ConstraintRefRecipe.java | Renamed executionContext parameter to ctx |
| AsConstraintRecipe.java | Renamed executionContext parameter to ctx, simplified nested if-else logic, applied string comparison best practices |
| TimefoldChangeDependencies.java | Applied string comparison best practices |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ok there's quite a few checks on the builds here that I have yet to work out; to start with spotless doesn't apply for me, which is annoying, and then it seems I have to manage the dependency of a new jetbrains annotations dependency. Would you even want that added here before I put more effort in? |
|
Hello @timtebeek! |
migration/src/test/java/ai/timefold/solver/migration/v8/ScoreGettersRecipeTest.java
Show resolved
Hide resolved
|
Pulling out some surprising likely unrelated failures from the logs: |
|
@timtebeek I think this one will go away if you rebase to latest |
|
Great, thanks for the help! Should be ok to review now. :) |
triceo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed and pushed minor changes.
I decided against including the POM changes. We try to inherit as much of OpenRewrite from the BOM, but this upgrade recipe is not part of that. This would have unfortunate consequences, specifically:
- Dependabot creates PRs automatically on all dependency updates.
- OpenRewrite already triggers two of them every time you release a new version. (One for the BOM, another for the plugin.) This would have introduced a third.
- And this happens frequently enough as to cause churn, which I'd like to keep to a minimum.
However, I see the benefit of these refactors made here; once (if) the recipe becomes part of the BOM, I will be happy to use it.
|
|
Thanks for the review! Fine indeed to drop the plugin; it's not necessary to add but does make it easier to find. The same recipe can also be run using this command without changes to the build file: |
|
Thank you, @timtebeek! |



We've defined some recipe best practices at OpenRewrite to ensure recipes look and behave the same, and avoid some potential problems: https://docs.openrewrite.org/recipes/recipes/rewrite/openrewriterecipebestpractices
I've applied these best practices here already, and added the plugin to make them easy to run again. It would also be possible to run these best practices on pull requests and get suggestions for improvements there. Let me know if that is of interest.