Skip to content

Add OpenRewrite Gradle plugin, refactor and modernize code#48

Open
NebelNidas wants to merge 2 commits intoFabricMC:masterfrom
NebelNidas:openrewrite
Open

Add OpenRewrite Gradle plugin, refactor and modernize code#48
NebelNidas wants to merge 2 commits intoFabricMC:masterfrom
NebelNidas:openrewrite

Conversation

@NebelNidas
Copy link
Member

Refactor code for improved readability and consistency:

  • Address deprecations
  • Address compiler warnings, suppress where not fixable
  • Use modern language features where applicable
  • Modernize standard library usage
  • Remove unnecessary semicolons
  • Change class declarations to final where advisable
  • Prevent instantiation of utility/helper classes
  • Improve logging statements and exception messages
  • Ensure consistent spacing and formatting throughout the codebase
  • Apply a few suggestions provided by IntelliJ IDEA
  • Remove various other code smells

Most of the changes were made by OpenRewrite recipes, ran via the rewriteRun Gradle task. Just like Checkstyle or Spotless, I've configured the OpenRewrite plugin to fail the check task when it finds code snippets to improve.

Comment on lines +8 to +22
activeRecipe(
"org.openrewrite.java.RemoveObjectsIsNull",
"org.openrewrite.java.RemoveUnusedImports",
// "org.openrewrite.java.logging.PrintStackTraceToLogError", // Breaks Util#getStackTrace, see https://github.com/openrewrite/rewrite-logging-frameworks/issues/281
"org.openrewrite.java.logging.SystemErrToLogging",
"org.openrewrite.java.logging.SystemOutToLogging",
"org.openrewrite.java.logging.slf4j.Slf4jBestPractices",
"org.openrewrite.staticanalysis.CompareEnumsWithEqualityOperator",
"org.openrewrite.staticanalysis.JavaApiBestPractices",
"org.openrewrite.staticanalysis.MissingOverrideAnnotation",
"org.openrewrite.staticanalysis.SimplifyConstantIfBranchExecution",
"org.openrewrite.staticanalysis.UseStandardCharset",
"org.openrewrite.java.recipes.BlankLinesAroundFieldsWithAnnotations",
"org.openrewrite.java.migrate.RemoveIllegalSemicolons",
"org.openrewrite.java.migrate.lang.IfElseIfConstructToSwitch",
Copy link
Member

Choose a reason for hiding this comment

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

We need to be really really careful about making automated changes such as this, a lot of the time it can miss nuances from the hand written code. It might seem good on the surface but you need to understand all of the changes being made. Im honestly not keen on making changes for the sake of making changes.

Im not dismissing this PR, but I am quite skepticial this actually improves anything.

Copy link
Member Author

@NebelNidas NebelNidas Mar 3, 2026

Choose a reason for hiding this comment

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

I've spent the last few days carefully reviewing every single change and making sure no semantics are changed. The recipes are hand-picked to not conflict with any consciously made decisions regarding code style in the current code base. Personally, I very much think that OpenRewrite does have merit; it helps addressing deprecations, bad coding habits and enforces consistency. It also makes you aware and helps you take advantage of newer Java language and standard library features.
I very much agree with you that automatic refactoring tools can "miss nuances from the hand written code"; however, none of the OpenRewrite recipes I added pose a risk in that regard. Especially since the Gradle task to apply the suggestions still has to be run manually. IntelliJ IDEA's inspections were definitely more hit-or-miss, many of the "boolean expression can be simplified" ones would've made the code harder to follow, for example.

- Address deprecations
- Address compiler warnings, suppress where not fixable
- Use modern language features where applicable
- Modernize standard library usage
- Remove unnecessary semicolons
- Change class declarations to final where advisable
- Prevent instantiation of utility/helper classes
- Improve logging statements and exception messages
- Ensure consistent spacing and formatting throughout the codebase
- Apply a few suggestions provided by IntelliJ IDEA
- Remove various other code smells
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants