From 34c072e008d687f0047d7bf2eacb7709002cfe4d Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 19:04:18 +0100 Subject: [PATCH 1/8] Recipe to migrate from AbstractLogEnabled to SLF4J --- build.gradle.kts | 3 + .../plexus/AbstractLogEnabledToSlf4j.java | 110 ++++++++++++++++++ .../codehaus/plexus/package-info.java | 21 ++++ .../plexus/AbstractLogEnabledToSlf4jTest.java | 84 +++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java create mode 100644 src/main/java/org/openrewrite/codehaus/plexus/package-info.java create mode 100644 src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java diff --git a/build.gradle.kts b/build.gradle.kts index ea990d2..fe42fa1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { implementation(platform("org.openrewrite:rewrite-bom:$rewriteVersion")) implementation("org.openrewrite:rewrite-java") implementation("org.openrewrite.recipe:rewrite-java-dependencies:$rewriteVersion") + implementation("org.openrewrite.recipe:rewrite-logging-frameworks:$rewriteVersion") implementation("org.openrewrite.recipe:rewrite-static-analysis:$rewriteVersion") implementation("org.openrewrite:rewrite-templating:$rewriteVersion") @@ -48,6 +49,8 @@ dependencies { testImplementation("commons-lang:commons-lang:2.6") testImplementation("org.apache.commons:commons-lang3:3.+") + testRuntimeOnly("org.codehaus.plexus:plexus-container-default:2.+") + testImplementation("org.junit.jupiter:junit-jupiter-engine:latest.release") } diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java new file mode 100644 index 0000000..14e630b --- /dev/null +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -0,0 +1,110 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.codehaus.plexus; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Preconditions; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.java.*; +import org.openrewrite.java.logging.AddLogger; +import org.openrewrite.java.search.UsesType; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.TypeTree; +import org.openrewrite.java.tree.TypeUtils; + +import java.util.concurrent.atomic.AtomicReference; + +public class AbstractLogEnabledToSlf4j extends Recipe { + + private static final String ABSTRACT_LOG_ENABLED = "org.codehaus.plexus.logging.AbstractLogEnabled"; + private static final MethodMatcher GET_LOGGER_MATCHER = new MethodMatcher(ABSTRACT_LOG_ENABLED + " getLogger()"); + private static final String PLEXUS_LOGGER = "org.codehaus.plexus.logging.Logger"; + + @Override + public String getDisplayName() { + return "Migrate from Plexus `AbstractLogEnabled` to SLF4J"; + } + + @Override + public String getDescription() { + return "Introduce a SLF4J `Logger` field and replace calls to `getLogger()` with calls to the field."; + } + + @Override + public TreeVisitor getVisitor() { + return Preconditions.check( + new UsesType<>(ABSTRACT_LOG_ENABLED, true), + new JavaIsoVisitor() { + @Override + public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { + J.ClassDeclaration cd = classDecl; + if (TypeUtils.isAssignableTo(ABSTRACT_LOG_ENABLED, cd.getType())) { + + // If we directly extend AbstractLogEnabled, remove the extends clause + TypeTree anExtends = cd.getExtends(); + if (anExtends != null && TypeUtils.isOfClassType(anExtends.getType(), ABSTRACT_LOG_ENABLED)) { + maybeRemoveImport(ABSTRACT_LOG_ENABLED); + cd = cd.withExtends(null); + } + + // Add a logger field + maybeAddImport("org.slf4j.Logger"); + maybeAddImport("org.slf4j.LoggerFactory"); + cd = (J.ClassDeclaration) AddLogger.addSlf4jLogger(cd, "logger", ctx) + .visit(cd, ctx, getCursor().getParentTreeCursor()); + AtomicReference loggerFieldReference = new AtomicReference<>(); + new JavaIsoVisitor>() { + @Override + public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, AtomicReference ref) { + for (J.VariableDeclarations.NamedVariable var : multiVariable.getVariables()) { + if (TypeUtils.isOfClassType(var.getType(), "org.slf4j.Logger")) { + ref.set(var.getName()); + } + } + return super.visitVariableDeclarations(multiVariable, ref); + } + }.visitClassDeclaration(cd, loggerFieldReference); + + // Replace calls to getLogger() with the logger field + cd = (J.ClassDeclaration) new JavaVisitor() { + @Override + public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx1) { + if (GET_LOGGER_MATCHER.matches(method)) { + return loggerFieldReference.get().withPrefix(method.getPrefix()); + } + return super.visitMethodInvocation(method, ctx1); + } + }.visit(cd, ctx, getCursor().getParentTreeCursor()); + + // Replace `fatal` calls with `error` + cd = (J.ClassDeclaration) new ChangeMethodName(PLEXUS_LOGGER + " fatalError(..)", "error", false, false) + .getVisitor().visit(cd, ctx, getCursor().getParentTreeCursor()); + cd = (J.ClassDeclaration) new ChangeMethodName(PLEXUS_LOGGER + " isFatalErrorEnabled(..)", "isErrorEnabled", false, false) + .getVisitor().visit(cd, ctx, getCursor().getParentTreeCursor()); + + // Change any leftover `org.codehaus.plexus.logging.Logger` types to SLF4J Logger + maybeRemoveImport(PLEXUS_LOGGER); + cd = (J.ClassDeclaration) new ChangeType(PLEXUS_LOGGER, "org.slf4j.Logger", false) + .getVisitor().visit(cd, ctx, getCursor().getParentTreeCursor()); + + } + return super.visitClassDeclaration(cd, ctx); + } + } + ); + } +} diff --git a/src/main/java/org/openrewrite/codehaus/plexus/package-info.java b/src/main/java/org/openrewrite/codehaus/plexus/package-info.java new file mode 100644 index 0000000..6aa6078 --- /dev/null +++ b/src/main/java/org/openrewrite/codehaus/plexus/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2021 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@NullMarked +@NonNullFields +package org.openrewrite.codehaus.plexus; + +import org.jspecify.annotations.NullMarked; +import org.openrewrite.internal.lang.NonNullFields; diff --git a/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java b/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java new file mode 100644 index 0000000..ef90ce9 --- /dev/null +++ b/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.codehaus.plexus; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +class AbstractLogEnabledToSlf4jTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(new AbstractLogEnabledToSlf4j()) + .parser(JavaParser.fromJavaVersion().classpath("plexus-container-default")); + } + + @Test + @DocumentExample + void addAndUseLoggerField(){ + rewriteRun( + //language=java + java( + """ + import org.codehaus.plexus.logging.AbstractLogEnabled; + import org.codehaus.plexus.logging.Logger; + + class A extends AbstractLogEnabled { + void method() { + getLogger().info("Hello"); + } + void method2() { + Logger log = getLogger(); + log.info("Hello"); + } + void method3() { + if (getLogger().isFatalErrorEnabled()) { + getLogger().fatalError("Hello"); + } + } + } + """, + """ + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + + class A { + private static final Logger logger = LoggerFactory.getLogger(A.class); + + void method() { + logger.info("Hello"); + } + void method2() { + Logger log = logger; + log.info("Hello"); + } + void method3() { + if (logger.isErrorEnabled()) { + logger.error("Hello"); + } + } + } + """ + ) + ); + } + +} From de7109217dc8f7b559071220b5d5792b7ff9b176 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 20:21:58 +0100 Subject: [PATCH 2/8] Adopt naming convention Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../codehaus/plexus/AbstractLogEnabledToSlf4j.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index 14e630b..ac28a88 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -82,9 +82,8 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m // Replace calls to getLogger() with the logger field cd = (J.ClassDeclaration) new JavaVisitor() { @Override - public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx1) { - if (GET_LOGGER_MATCHER.matches(method)) { - return loggerFieldReference.get().withPrefix(method.getPrefix()); + public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + return super.visitMethodInvocation(method, ctx); } return super.visitMethodInvocation(method, ctx1); } From 21241e159939e3626d7d511a975ad9884712fff8 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 20:22:49 +0100 Subject: [PATCH 3/8] Correct code-suggester error --- .../codehaus/plexus/AbstractLogEnabledToSlf4j.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index ac28a88..19872dc 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -83,9 +83,10 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m cd = (J.ClassDeclaration) new JavaVisitor() { @Override public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - return super.visitMethodInvocation(method, ctx); + if (GET_LOGGER_MATCHER.matches(method)) { + return loggerFieldReference.get().withPrefix(method.getPrefix()); } - return super.visitMethodInvocation(method, ctx1); + return super.visitMethodInvocation(method, ctx); } }.visit(cd, ctx, getCursor().getParentTreeCursor()); From def3b67af61cc6881d401b81520822669522ce6e Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 21:14:35 +0100 Subject: [PATCH 4/8] Remove awkward line wrapping seein in practice --- .../plexus/AbstractLogEnabledToSlf4j.java | 17 +++-- .../plexus/AbstractLogEnabledToSlf4jTest.java | 70 +++++++++++++++++-- 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index 19872dc..077854f 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -22,17 +22,16 @@ import org.openrewrite.java.*; import org.openrewrite.java.logging.AddLogger; import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.TypeTree; -import org.openrewrite.java.tree.TypeUtils; +import org.openrewrite.java.tree.*; import java.util.concurrent.atomic.AtomicReference; public class AbstractLogEnabledToSlf4j extends Recipe { private static final String ABSTRACT_LOG_ENABLED = "org.codehaus.plexus.logging.AbstractLogEnabled"; - private static final MethodMatcher GET_LOGGER_MATCHER = new MethodMatcher(ABSTRACT_LOG_ENABLED + " getLogger()"); + private static final MethodMatcher GET_LOGGER_MATCHER = new MethodMatcher(ABSTRACT_LOG_ENABLED + " getLogger()", true); private static final String PLEXUS_LOGGER = "org.codehaus.plexus.logging.Logger"; + private static final MethodMatcher PLEXUS_LOGGER_MATCHER = new MethodMatcher("org.codehaus.plexus.logging.Logger *(..)"); @Override public String getDisplayName() { @@ -83,10 +82,14 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m cd = (J.ClassDeclaration) new JavaVisitor() { @Override public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (GET_LOGGER_MATCHER.matches(method)) { - return loggerFieldReference.get().withPrefix(method.getPrefix()); + J.MethodInvocation mi = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); + if (GET_LOGGER_MATCHER.matches(mi)) { + return loggerFieldReference.get().withPrefix(mi.getPrefix()); } - return super.visitMethodInvocation(method, ctx); + if (PLEXUS_LOGGER_MATCHER.matches(mi)) { + return mi.getPadding().withSelect(JRightPadded.build(mi.getSelect())); + } + return mi; } }.visit(cd, ctx, getCursor().getParentTreeCursor()); diff --git a/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java b/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java index ef90ce9..ffb3e40 100644 --- a/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java +++ b/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java @@ -23,6 +23,7 @@ import static org.openrewrite.java.Assertions.java; +@SuppressWarnings("RedundantSlf4jDefinition") class AbstractLogEnabledToSlf4jTest implements RewriteTest { @Override @@ -49,11 +50,6 @@ void method2() { Logger log = getLogger(); log.info("Hello"); } - void method3() { - if (getLogger().isFatalErrorEnabled()) { - getLogger().fatalError("Hello"); - } - } } """, """ @@ -70,7 +66,37 @@ void method2() { Logger log = logger; log.info("Hello"); } - void method3() { + } + """ + ) + ); + } + + @Test + void renameFatal(){ + rewriteRun( + //language=java + java( + """ + import org.codehaus.plexus.logging.AbstractLogEnabled; + import org.codehaus.plexus.logging.Logger; + + class A extends AbstractLogEnabled { + void method() { + if (getLogger().isFatalErrorEnabled()) { + getLogger().fatalError("Hello"); + } + } + } + """, + """ + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + + class A { + private static final Logger logger = LoggerFactory.getLogger(A.class); + + void method() { if (logger.isErrorEnabled()) { logger.error("Hello"); } @@ -81,4 +107,36 @@ void method3() { ); } + @Test + void removeLineWrap(){ + rewriteRun( + //language=java + java( + """ + import org.codehaus.plexus.logging.AbstractLogEnabled; + import org.codehaus.plexus.logging.Logger; + + class A extends AbstractLogEnabled { + void method() { + getLogger() + .info("Really long line that caused the previous line to be wrapped, but looks add with field"); + } + } + """, + """ + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + + class A { + private static final Logger logger = LoggerFactory.getLogger(A.class); + + void method() { + logger.info("Really long line that caused the previous line to be wrapped, but looks add with field"); + } + } + """ + ) + ); + } + } From 5341618289962ab7d4482b05f172a8c2a24e78f2 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 21:25:25 +0100 Subject: [PATCH 5/8] Remove local variables named `logger` --- .../plexus/AbstractLogEnabledToSlf4j.java | 24 ++++++++++--- .../plexus/AbstractLogEnabledToSlf4jTest.java | 34 ++++++++++++++++++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index 077854f..f4600ac 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -15,6 +15,7 @@ */ package org.openrewrite.codehaus.plexus; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; @@ -60,11 +61,24 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex cd = cd.withExtends(null); } + // Remove local variables named `logger` + cd = (J.ClassDeclaration) new JavaIsoVisitor() { + @Override + public J.@Nullable VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) { + if (multiVariable.getVariables().stream() + .map(J.VariableDeclarations.NamedVariable::getSimpleName) + .anyMatch("logger"::equals)) { + return null; + } + return super.visitVariableDeclarations(multiVariable, ctx); + } + }.visitNonNull(cd, ctx, getCursor().getParentTreeCursor()); + // Add a logger field maybeAddImport("org.slf4j.Logger"); maybeAddImport("org.slf4j.LoggerFactory"); cd = (J.ClassDeclaration) AddLogger.addSlf4jLogger(cd, "logger", ctx) - .visit(cd, ctx, getCursor().getParentTreeCursor()); + .visitNonNull(cd, ctx, getCursor().getParentTreeCursor()); AtomicReference loggerFieldReference = new AtomicReference<>(); new JavaIsoVisitor>() { @Override @@ -91,18 +105,18 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) } return mi; } - }.visit(cd, ctx, getCursor().getParentTreeCursor()); + }.visitNonNull(cd, ctx, getCursor().getParentTreeCursor()); // Replace `fatal` calls with `error` cd = (J.ClassDeclaration) new ChangeMethodName(PLEXUS_LOGGER + " fatalError(..)", "error", false, false) - .getVisitor().visit(cd, ctx, getCursor().getParentTreeCursor()); + .getVisitor().visitNonNull(cd, ctx, getCursor().getParentTreeCursor()); cd = (J.ClassDeclaration) new ChangeMethodName(PLEXUS_LOGGER + " isFatalErrorEnabled(..)", "isErrorEnabled", false, false) - .getVisitor().visit(cd, ctx, getCursor().getParentTreeCursor()); + .getVisitor().visitNonNull(cd, ctx, getCursor().getParentTreeCursor()); // Change any leftover `org.codehaus.plexus.logging.Logger` types to SLF4J Logger maybeRemoveImport(PLEXUS_LOGGER); cd = (J.ClassDeclaration) new ChangeType(PLEXUS_LOGGER, "org.slf4j.Logger", false) - .getVisitor().visit(cd, ctx, getCursor().getParentTreeCursor()); + .getVisitor().visitNonNull(cd, ctx, getCursor().getParentTreeCursor()); } return super.visitClassDeclaration(cd, ctx); diff --git a/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java b/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java index ffb3e40..fea1499 100644 --- a/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java +++ b/src/test/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4jTest.java @@ -23,7 +23,7 @@ import static org.openrewrite.java.Assertions.java; -@SuppressWarnings("RedundantSlf4jDefinition") +@SuppressWarnings({"RedundantSlf4jDefinition", "UnnecessaryLocalVariable"}) class AbstractLogEnabledToSlf4jTest implements RewriteTest { @Override @@ -139,4 +139,36 @@ void method() { ); } + @Test + void removeLocalVariableDeclaration(){ + rewriteRun( + //language=java + java( + """ + import org.codehaus.plexus.logging.AbstractLogEnabled; + import org.codehaus.plexus.logging.Logger; + + class A extends AbstractLogEnabled { + void method() { + Logger logger = getLogger(); + logger.info("Hello"); + } + } + """, + """ + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + + class A { + private static final Logger logger = LoggerFactory.getLogger(A.class); + + void method() { + logger.info("Hello"); + } + } + """ + ) + ); + } + } From 868d4a4e012cdde71eb44f997a76e21cee34d136 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 21:26:57 +0100 Subject: [PATCH 6/8] Fix imports --- .../codehaus/plexus/AbstractLogEnabledToSlf4j.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index f4600ac..58a6300 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -23,7 +23,10 @@ import org.openrewrite.java.*; import org.openrewrite.java.logging.AddLogger; import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.*; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JRightPadded; +import org.openrewrite.java.tree.TypeTree; +import org.openrewrite.java.tree.TypeUtils; import java.util.concurrent.atomic.AtomicReference; From 2559078d5b536e732f218852a8af89013d860ef8 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 21:29:46 +0100 Subject: [PATCH 7/8] Add missing nullable annotation Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../codehaus/plexus/AbstractLogEnabledToSlf4j.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index 58a6300..0ff87c2 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -52,8 +52,8 @@ public TreeVisitor getVisitor() { return Preconditions.check( new UsesType<>(ABSTRACT_LOG_ENABLED, true), new JavaIsoVisitor() { - @Override - public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { + + public @Nullable J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { J.ClassDeclaration cd = classDecl; if (TypeUtils.isAssignableTo(ABSTRACT_LOG_ENABLED, cd.getType())) { From 7a2ef7264cf8acb079bff8b081e4636a745238f0 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Nov 2024 21:38:13 +0100 Subject: [PATCH 8/8] Remove suggested nullable annotation --- .../openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java index 0ff87c2..ca0a7d4 100644 --- a/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java +++ b/src/main/java/org/openrewrite/codehaus/plexus/AbstractLogEnabledToSlf4j.java @@ -53,7 +53,7 @@ public TreeVisitor getVisitor() { new UsesType<>(ABSTRACT_LOG_ENABLED, true), new JavaIsoVisitor() { - public @Nullable J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { + public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { J.ClassDeclaration cd = classDecl; if (TypeUtils.isAssignableTo(ABSTRACT_LOG_ENABLED, cd.getType())) {