Add OpenRewrite Gradle plugin, refactor and modernize code#48
Add OpenRewrite Gradle plugin, refactor and modernize code#48NebelNidas wants to merge 2 commits intoFabricMC:masterfrom
Conversation
| 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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Refactor code for improved readability and consistency:
Most of the changes were made by OpenRewrite recipes, ran via the
rewriteRunGradle task. Just like Checkstyle or Spotless, I've configured the OpenRewrite plugin to fail thechecktask when it finds code snippets to improve.