From 3045858c38b20d8a61e9463ef098204ee56e5c1e Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 3 Dec 2024 08:23:10 +0000 Subject: [PATCH] refactor: OpenRewrite best practices Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.OpenRewriteBestPractices?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../benchmarks/java/JavaTypeCacheBenchmark.java | 2 +- .../java/org/openrewrite/java/tree/TypeUtilsTest.java | 3 ++- .../org/openrewrite/java/DeleteMethodArgumentTest.java | 2 ++ .../java/org/openrewrite/java/search/FindTypes.java | 2 +- .../org/openrewrite/maven/RemoveUnusedProperties.java | 4 ++-- .../org/openrewrite/maven/ExcludeDependencyTest.java | 1 - .../openrewrite/maven/RemoveUnusedPropertiesTest.java | 2 ++ .../org/openrewrite/maven/UpdateMavenWrapperTest.java | 10 ++-------- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/rewrite-benchmarks/src/jmh/java/org/openrewrite/benchmarks/java/JavaTypeCacheBenchmark.java b/rewrite-benchmarks/src/jmh/java/org/openrewrite/benchmarks/java/JavaTypeCacheBenchmark.java index a79b9aaead9..42a5da8d16e 100644 --- a/rewrite-benchmarks/src/jmh/java/org/openrewrite/benchmarks/java/JavaTypeCacheBenchmark.java +++ b/rewrite-benchmarks/src/jmh/java/org/openrewrite/benchmarks/java/JavaTypeCacheBenchmark.java @@ -22,8 +22,8 @@ import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; -import org.openrewrite.java.internal.JavaTypeCache; import org.openrewrite.java.internal.AdaptiveRadixJavaTypeCache; +import org.openrewrite.java.internal.JavaTypeCache; import java.net.URISyntaxException; import java.util.Map; diff --git a/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/TypeUtilsTest.java b/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/TypeUtilsTest.java index a400ea4b0b3..214b81fa95e 100644 --- a/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/TypeUtilsTest.java +++ b/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/TypeUtilsTest.java @@ -32,7 +32,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.openrewrite.java.Assertions.java; -import static org.openrewrite.java.tree.TypeUtils.TypePosition.*; +import static org.openrewrite.java.tree.TypeUtils.TypePosition.Invariant; +import static org.openrewrite.java.tree.TypeUtils.TypePosition.Out; import static org.openrewrite.test.RewriteTest.toRecipe; @SuppressWarnings("ConstantConditions") diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/DeleteMethodArgumentTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/DeleteMethodArgumentTest.java index 5ad21d41e15..a7cd5c1bc8c 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/DeleteMethodArgumentTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/DeleteMethodArgumentTest.java @@ -17,6 +17,7 @@ import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -42,6 +43,7 @@ public void defaults(RecipeSpec spec) { spec.parser(JavaParser.fromJavaVersion().dependsOn(b)); } + @DocumentExample @Test void deleteMiddleArgumentDeclarative() { rewriteRun( diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/FindTypes.java b/rewrite-java/src/main/java/org/openrewrite/java/search/FindTypes.java index 9c936327614..3b9c7f4d254 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/FindTypes.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/FindTypes.java @@ -27,8 +27,8 @@ import org.openrewrite.java.table.TypeUses; import org.openrewrite.java.tree.*; import org.openrewrite.marker.SearchResult; -import org.openrewrite.trait.Trait; import org.openrewrite.trait.Reference; +import org.openrewrite.trait.Trait; import java.util.HashSet; import java.util.Set; diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveUnusedProperties.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveUnusedProperties.java index 3251d64f736..59fc3fc889a 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveUnusedProperties.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveUnusedProperties.java @@ -231,8 +231,8 @@ public FindFilteredResourcePathsVisitor(Accumulator acc) { public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { if (resourceMatcher.matches(getCursor())) { String directory = tag.getChildValue("directory").orElse(null); - if (tag.getChildValue("filtering").map(Boolean::valueOf).orElse(false) - && directory != null) { + if (tag.getChildValue("filtering").map(Boolean::valueOf).orElse(false) && + directory != null) { Path path = getCursor().firstEnclosingOrThrow(SourceFile.class).getSourcePath(); try { acc.filteredResourcePathsToDeclaringPoms.put(path.getParent().resolve(directory), getResolutionResult()); diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ExcludeDependencyTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ExcludeDependencyTest.java index cfbb8e331a2..db66ea54b4c 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ExcludeDependencyTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ExcludeDependencyTest.java @@ -20,7 +20,6 @@ import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import org.openrewrite.test.TypeValidation; import static org.openrewrite.maven.Assertions.pomXml; diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveUnusedPropertiesTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveUnusedPropertiesTest.java index f65bbf7418d..bc72cf62446 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveUnusedPropertiesTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveUnusedPropertiesTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -33,6 +34,7 @@ public void defaults(final RecipeSpec spec) { spec.recipe(new RemoveUnusedProperties(null)); } + @DocumentExample @Test void removesWholePropertiesSection() { rewriteRun( diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/UpdateMavenWrapperTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/UpdateMavenWrapperTest.java index 1cb62e262da..52fc8e4d9a1 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/UpdateMavenWrapperTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/UpdateMavenWrapperTest.java @@ -43,15 +43,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.openrewrite.maven.utilities.MavenWrapper.ASF_LICENSE_HEADER; -import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_BATCH_LOCATION; -import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_DOWNLOADER_LOCATION; -import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_JAR_LOCATION; -import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_SCRIPT_LOCATION; +import static org.openrewrite.maven.utilities.MavenWrapper.*; import static org.openrewrite.properties.Assertions.properties; -import static org.openrewrite.test.SourceSpecs.dir; -import static org.openrewrite.test.SourceSpecs.other; -import static org.openrewrite.test.SourceSpecs.text; +import static org.openrewrite.test.SourceSpecs.*; class UpdateMavenWrapperTest implements RewriteTest { private final UnaryOperator<@Nullable String> notEmpty = actual -> {