-
Notifications
You must be signed in to change notification settings - Fork 50
Add OpenRewrite Gradle plugin, refactor and modernize code #48
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
Open
NebelNidas
wants to merge
2
commits into
FabricMC:master
Choose a base branch
from
NebelNidas:openrewrite
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
buildSrc/src/main/groovy/matcher.openrewrite.base.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| plugins { | ||
| id 'org.openrewrite.rewrite' | ||
| } | ||
|
|
||
| rewrite { | ||
| failOnDryRunResults = true | ||
|
|
||
| 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", | ||
| "org.openrewrite.java.migrate.lang.StringRulesRecipes", | ||
| "org.openrewrite.java.migrate.lang.UseStringIsEmptyRecipe", | ||
| "org.openrewrite.java.migrate.util.JavaUtilAPIs", | ||
| "org.openrewrite.java.migrate.util.UseEnumSetOf", | ||
| "org.openrewrite.java.migrate.util.UseListOf", | ||
| "org.openrewrite.java.migrate.util.UseSetOf", | ||
| "org.openrewrite.java.format.NormalizeFormat", | ||
| "org.openrewrite.java.format.RemoveTrailingWhitespace", | ||
| "org.openrewrite.java.format.SingleLineComments", | ||
| // "org.openrewrite.java.format.Spaces", // Conflicts with Checkstyle config regarding { } vs {} | ||
|
|
||
| // TODO: https://docs.openrewrite.org/recipes/java/recipes/recipenullabilitybestpractices | ||
|
|
||
| /* | ||
| * org.openrewrite.staticanalysis.CommonStaticAnalysis (modified), based on commit 69d43a5: | ||
| * https://github.com/openrewrite/rewrite-static-analysis/blob/63586c0ffa2f8dd7150a6a1767b808532b2560a8/src/main/resources/META-INF/rewrite/common-static-analysis.yml | ||
| */ | ||
| "org.openrewrite.staticanalysis.AbstractClassPublicConstructor", | ||
| "org.openrewrite.staticanalysis.AtomicPrimitiveEqualsUsesGet", | ||
| "org.openrewrite.staticanalysis.BigDecimalDoubleConstructorRecipe", | ||
| "org.openrewrite.staticanalysis.BigDecimalRoundingConstantsToEnums", | ||
| "org.openrewrite.staticanalysis.BooleanChecksNotInverted", | ||
| "org.openrewrite.staticanalysis.CaseInsensitiveComparisonsDoNotChangeCase", | ||
| "org.openrewrite.staticanalysis.CatchClauseOnlyRethrows", | ||
| "org.openrewrite.staticanalysis.ChainStringBuilderAppendCalls", | ||
| "org.openrewrite.staticanalysis.CollectionToArrayShouldHaveProperType", | ||
| "org.openrewrite.staticanalysis.CovariantEquals", | ||
| "org.openrewrite.staticanalysis.DefaultComesLast", | ||
| "org.openrewrite.staticanalysis.EmptyBlock", | ||
| // "org.openrewrite.staticanalysis.EqualsAvoidsNull", | ||
| "org.openrewrite.staticanalysis.ExplicitInitialization", | ||
| "org.openrewrite.staticanalysis.ExternalizableHasNoArgsConstructor", | ||
| "org.openrewrite.staticanalysis.FinalizePrivateFields", | ||
| "org.openrewrite.staticanalysis.FinalClass", | ||
| "org.openrewrite.staticanalysis.FixStringFormatExpressions", | ||
| "org.openrewrite.staticanalysis.ForLoopIncrementInUpdate", | ||
| "org.openrewrite.staticanalysis.HideUtilityClassConstructor", | ||
| "org.openrewrite.staticanalysis.IndexOfChecksShouldUseAStartPosition", | ||
| "org.openrewrite.staticanalysis.IndexOfReplaceableByContains", | ||
| "org.openrewrite.staticanalysis.IndexOfShouldNotCompareGreaterThanZero", | ||
| "org.openrewrite.staticanalysis.InlineVariable", | ||
| "org.openrewrite.staticanalysis.IsEmptyCallOnCollections", | ||
| "org.openrewrite.staticanalysis.LambdaBlockToExpression", | ||
| "org.openrewrite.staticanalysis.LowercasePackage", | ||
| "org.openrewrite.staticanalysis.MethodNameCasing", | ||
| "org.openrewrite.staticanalysis.ModifierOrder", | ||
| // "org.openrewrite.staticanalysis.MultipleVariableDeclarations", | ||
| // "org.openrewrite.staticanalysis.NeedBraces", | ||
| "org.openrewrite.staticanalysis.NestedEnumsAreNotStatic", | ||
| "org.openrewrite.staticanalysis.NewStringBuilderBufferWithCharArgument", | ||
| "org.openrewrite.staticanalysis.NoDoubleBraceInitialization", | ||
| "org.openrewrite.staticanalysis.NoEmptyCollectionWithRawType", | ||
| "org.openrewrite.staticanalysis.NoEqualityInForCondition", | ||
| "org.openrewrite.staticanalysis.NoFinalizer", | ||
| "org.openrewrite.staticanalysis.NoPrimitiveWrappersForToStringOrCompareTo", | ||
| "org.openrewrite.staticanalysis.NoRedundantJumpStatements", | ||
| "org.openrewrite.staticanalysis.NoToStringOnStringType", | ||
| "org.openrewrite.staticanalysis.NoValueOfOnStringType", | ||
| "org.openrewrite.staticanalysis.ObjectFinalizeCallsSuper", | ||
| "org.openrewrite.staticanalysis.PreferSystemGetPropertyOverGetenv", | ||
| "org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf", | ||
| "org.openrewrite.staticanalysis.RedundantFileCreation", | ||
| "org.openrewrite.staticanalysis.RemoveExtraSemicolons", | ||
| "org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeInstanceof", | ||
| "org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeLiteralEquals", | ||
| "org.openrewrite.staticanalysis.RemoveRedundantTypeCast", | ||
| // "org.openrewrite.staticanalysis.RemoveUnusedLocalVariables", | ||
| // "org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods", | ||
| // "org.openrewrite.staticanalysis.RenameLocalVariablesToCamelCase", | ||
| "org.openrewrite.staticanalysis.RenameMethodsNamedHashcodeEqualOrToString", | ||
| // "org.openrewrite.staticanalysis.RenamePrivateFieldsToCamelCase", // Always generates empty diff for UidSetupPane.java | ||
| "org.openrewrite.staticanalysis.ReplaceClassIsInstanceWithInstanceof", | ||
| "org.openrewrite.staticanalysis.ReplaceLambdaWithMethodReference", | ||
| "org.openrewrite.staticanalysis.ReplaceStringBuilderWithString", | ||
| "org.openrewrite.staticanalysis.ReplaceStringConcatenationWithStringValueOf", | ||
| "org.openrewrite.staticanalysis.SimplifyArraysAsList", | ||
| "org.openrewrite.staticanalysis.SimplifyBooleanExpression", | ||
| // "org.openrewrite.staticanalysis.SimplifyBooleanReturn", | ||
| "org.openrewrite.staticanalysis.SimplifyTernaryRecipes", | ||
| "org.openrewrite.staticanalysis.StaticMethodNotFinal", | ||
| "org.openrewrite.staticanalysis.StringLiteralEquality", | ||
| "org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources", | ||
| "org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments", | ||
| "org.openrewrite.staticanalysis.UnnecessaryParentheses", | ||
| "org.openrewrite.staticanalysis.UnnecessaryPrimitiveAnnotations", | ||
| "org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement", | ||
| // "org.openrewrite.staticanalysis.UnwrapElseAfterReturn", | ||
| "org.openrewrite.staticanalysis.UpperCaseLiteralSuffixes", | ||
| "org.openrewrite.staticanalysis.UnnecessaryThrows", | ||
| "org.openrewrite.staticanalysis.UseCollectionInterfaces", | ||
| "org.openrewrite.staticanalysis.UseDiamondOperator", | ||
| "org.openrewrite.staticanalysis.UseJavaStyleArrayDeclarations", | ||
| "org.openrewrite.staticanalysis.UsePortableNewlines", | ||
| "org.openrewrite.staticanalysis.UseLambdaForFunctionalInterface", | ||
| "org.openrewrite.staticanalysis.UseStringReplace", | ||
| "org.openrewrite.staticanalysis.WhileInsteadOfFor", | ||
| "org.openrewrite.staticanalysis.WriteOctalValuesAsDecimal", | ||
|
|
||
| /* | ||
| * org.openrewrite.staticanalysis.CodeCleanup (modified), based on commit a32c4e3: | ||
| * https://github.com/openrewrite/rewrite-static-analysis/blob/63586c0ffa2f8dd7150a6a1767b808532b2560a8/src/main/resources/META-INF/rewrite/static-analysis.yml | ||
| */ | ||
| "org.openrewrite.staticanalysis.DefaultComesLast", | ||
| "org.openrewrite.staticanalysis.EmptyBlock", | ||
| "org.openrewrite.java.format.EmptyNewlineAtEndOfFile", | ||
| "org.openrewrite.staticanalysis.ForLoopControlVariablePostfixOperators", | ||
| "org.openrewrite.staticanalysis.FinalizePrivateFields", | ||
| "org.openrewrite.java.format.MethodParamPad", | ||
| "org.openrewrite.java.format.NoWhitespaceAfter", | ||
| "org.openrewrite.java.format.NoWhitespaceBefore", | ||
| "org.openrewrite.java.format.PadEmptyForLoopComponents", | ||
| "org.openrewrite.staticanalysis.TypecastParenPad", | ||
| // "org.openrewrite.staticanalysis.EqualsAvoidsNull", | ||
| "org.openrewrite.staticanalysis.ExplicitInitialization", | ||
| // "org.openrewrite.staticanalysis.FallThrough", | ||
| "org.openrewrite.staticanalysis.HideUtilityClassConstructor", | ||
| // "org.openrewrite.staticanalysis.NeedBraces", | ||
| "org.openrewrite.staticanalysis.OperatorWrap", | ||
| "org.openrewrite.staticanalysis.UnnecessaryParentheses", | ||
| "org.openrewrite.staticanalysis.ReplaceThreadRunWithThreadStart", | ||
| "org.openrewrite.staticanalysis.ChainStringBuilderAppendCalls", | ||
| "org.openrewrite.staticanalysis.ReplaceStringBuilderWithString", | ||
| "org.openrewrite.java.ShortenFullyQualifiedTypeReferences", | ||
| "org.openrewrite.java.SimplifySingleElementAnnotation", | ||
| // "org.openrewrite.java.OrderImports", | ||
| ) | ||
| } | ||
|
|
||
| dependencies { | ||
| rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.25.0")) | ||
| rewrite("org.openrewrite.recipe:rewrite-migrate-java") | ||
| rewrite("org.openrewrite.recipe:rewrite-static-analysis") | ||
| rewrite("org.openrewrite.recipe:rewrite-logging-frameworks") | ||
| rewrite("org.openrewrite.recipe:rewrite-rewrite") | ||
| } | ||
|
|
||
| tasks.named("check").configure { | ||
| dependsOn(tasks.named("rewriteDryRun")) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| plugins { | ||
| id 'org.openrewrite.rewrite' | ||
| id 'matcher.openrewrite.base' | ||
| } | ||
|
|
||
| rewrite { | ||
| activeRecipe("org.openrewrite.java.migrate.Java8toJava11") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| plugins { | ||
| id 'org.openrewrite.rewrite' | ||
| id 'matcher.openrewrite.base' | ||
| } | ||
|
|
||
| rewrite { | ||
| activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| plugins { | ||
| id 'matcher.common' | ||
| id 'matcher.publishing.maven' | ||
| id 'matcher.openrewrite.java11' | ||
| } | ||
|
|
||
| base { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.