Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ dependencies {
implementation "org.gradlex:extra-java-module-info:${props.getProperty('extra_java_module_info_version')}"
implementation "com.gradleup.shadow:shadow-gradle-plugin:${props.getProperty('shadow_version')}"
implementation "me.modmuss50:mod-publish-plugin:${props.getProperty('mod_publish_plugin_version')}"
implementation "org.openrewrite:plugin:${props.getProperty('openrewrite_plugin_version')}"
}

161 changes: 161 additions & 0 deletions buildSrc/src/main/groovy/matcher.openrewrite.base.gradle
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",
Comment on lines +8 to +22

Copy link
Copy Markdown
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.

@NebelNidas NebelNidas Mar 3, 2026

Copy link
Copy Markdown
Member Author

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.

"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"))
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/groovy/matcher.openrewrite.java11.gradle
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")
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/groovy/matcher.openrewrite.java17.gradle
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")
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ javafx_plugin_version = 0.1.0
extra_java_module_info_version = 1.9
shadow_version = 8.3.5
mod_publish_plugin_version = 0.8.4
openrewrite_plugin_version = 7.27.0

# Project Properties
version = 0.1.0
Expand Down
1 change: 1 addition & 0 deletions matcher-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'matcher.common'
id 'matcher.publishing.maven'
id 'matcher.publishing.github.no-natives'
id 'matcher.openrewrite.java17'
id 'org.gradlex.extra-java-module-info'
id 'application'
}
Expand Down
3 changes: 0 additions & 3 deletions matcher-cli/src/main/java/matcher/cli/MatcherCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.List;

import com.beust.jcommander.JCommander;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import matcher.cli.provider.CliCommandProvider;
import matcher.cli.provider.CliParameterProvider;
Expand Down Expand Up @@ -60,7 +58,6 @@ public void processArgs(String[] args) {
}
}

public static final Logger LOGGER = LoggerFactory.getLogger("Matcher CLI");
private final List<CliParameterProvider> paramProviders = new ArrayList<>(5);
private final List<CliCommandProvider> commandProviders = new ArrayList<>(5);
private final boolean acceptUnknownParams;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package matcher.cli.provider.builtin;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -9,10 +10,11 @@

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.mappingio.MappingReader;

import matcher.cli.MatcherCli;
import matcher.cli.provider.CliCommandProvider;
import matcher.core.Matcher;
import matcher.core.serdes.MatchesIo;
Expand All @@ -26,8 +28,8 @@
* Provides the default {@code automatch} command.
*/
public class AutomatchCliCommandProvider implements CliCommandProvider {
@Parameters(commandNames = {commandName})
class AutomatchCommand {
@Parameters(commandNames = {COMMAND_NAME})
static class AutomatchCommand {
@Parameter(names = {BuiltinCliParameters.INPUTS_A}, required = true)
List<Path> inputsA = Collections.emptyList();

Expand Down Expand Up @@ -76,7 +78,7 @@ class AutomatchCommand {

@Override
public String getCommandName() {
return commandName;
return COMMAND_NAME;
}

@Override
Expand Down Expand Up @@ -104,7 +106,7 @@ public void processArgs() {
.build();

Config.setProjectConfig(config);
matcher.init(config, (progress) -> { });
matcher.init(config, progress -> { });

if (config.getMappingsPathA() != null) {
Path mappingsPath = config.getMappingsPathA();
Expand All @@ -116,7 +118,7 @@ public void processArgs() {
MappingField.PLAIN, MappingField.MAPPED,
env.getEnvA(), true);
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException("Failed to load mappings for side A", e);
}
}

Expand All @@ -130,24 +132,25 @@ public void processArgs() {
MappingField.PLAIN, MappingField.MAPPED,
env.getEnvB(), true);
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException("Failed to load mappings for side B", e);
}
}

for (int i = 0; i < command.passes; i++) {
matcher.autoMatchAll((progress) -> { });
matcher.autoMatchAll(progress -> { });
}

try {
Files.deleteIfExists(command.outputFile);
MatchesIo.write(matcher, command.outputFile);
} catch (Throwable e) {
} catch (Exception e) {
throw new RuntimeException(e);
}

MatcherCli.LOGGER.info("Auto-matching done!");
LOGGER.info("Auto-matching done!");
}

private static final String commandName = "automatch";
private static final Logger LOGGER = LoggerFactory.getLogger(AutomatchCliCommandProvider.class);
private static final String COMMAND_NAME = "automatch";
private final AutomatchCommand command = new AutomatchCommand();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
/**
* All CLI parameters the CLI module handles by default.
*/
public class BuiltinCliParameters {
public final class BuiltinCliParameters {
private BuiltinCliParameters() {
}

public static final String ADDITIONAL_PLUGINS = "--additional-plugins";
public static final String INPUTS_A = "--inputs-a";
public static final String INPUTS_B = "--inputs-b";
Expand Down
1 change: 1 addition & 0 deletions matcher-cli/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SuppressWarnings("requires-transitive-automatic")
module matcher.cli {
requires transitive jcommander;
requires transitive matcher.core;
Expand Down
1 change: 1 addition & 0 deletions matcher-core/build.gradle
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 {
Expand Down
Loading
Loading