Skip to content

Commit

Permalink
ParameterizedLogging support for logger fields added through Lombok…
Browse files Browse the repository at this point in the history
… annotations (#205)

* Add test for lombok generated logger

* Update lombok initialization

* Drop missing marker reference

* Only run select tests with Lombok support enabled

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
nielsdebruin and timtebeek authored Dec 31, 2024
1 parent 93a6d77 commit 89f5789
Showing 1 changed file with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package org.openrewrite.java.logging;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
Expand All @@ -37,7 +40,7 @@ class ParameterizedLoggingTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.parser(JavaParser.fromJavaVersion()
.classpathFromResources(new InMemoryExecutionContext(), "slf4j-api-2.1", "log4j-api-2.23", "log4j-core-2.23"));
.classpathFromResources(new InMemoryExecutionContext(), "slf4j-api-2.1", "log4j-api-2.23", "log4j-core-2.23", "lombok"));
}

@DocumentExample
Expand Down Expand Up @@ -697,4 +700,48 @@ void method(int cnt, String name) {
);
}

@Nested
class LombokSupport {

@BeforeAll
static void setUp() {
System.setProperty("rewrite.lombok", "true");
}

@AfterAll
static void tearDown() {
System.clearProperty("rewrite.lombok");
}

@Test
void lombokLoggingAnnotation() {
rewriteRun(
spec -> spec.recipe(new ParameterizedLogging("org.slf4j.Logger info(..)", false)),
// language=java
java(
"""
import lombok.extern.slf4j.Slf4j;
@Slf4j
class Test {
static void method(String name) {
log.info("Hello " + name + ", nice to meet you " + name);
}
}
""",
"""
import lombok.extern.slf4j.Slf4j;
@Slf4j
class Test {
static void method(String name) {
log.info("Hello {}, nice to meet you {}", name, name);
}
}
"""
)
);
}

}
}

0 comments on commit 89f5789

Please sign in to comment.