-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support for Lombok log annotations in three recipes #115
Changes from 5 commits
74886eb
d24a86e
e84f32a
f19b1f0
751f9e9
93410e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ | |||||||||||||||||
import org.openrewrite.Issue; | ||||||||||||||||||
import org.openrewrite.java.JavaParser; | ||||||||||||||||||
import org.openrewrite.test.RewriteTest; | ||||||||||||||||||
import org.openrewrite.test.TypeValidation; | ||||||||||||||||||
|
||||||||||||||||||
import static org.openrewrite.java.Assertions.java; | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -235,4 +236,45 @@ public void close() { | |||||||||||||||||
) | ||||||||||||||||||
); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@Test | ||||||||||||||||||
@Issue("https://github.com/openrewrite/rewrite-logging-frameworks/issues/114") | ||||||||||||||||||
void supportLombokLogAnnotations() { | ||||||||||||||||||
rewriteRun( | ||||||||||||||||||
spec -> spec.recipe(new PrintStackTraceToLogError(null, null, null)) | ||||||||||||||||||
.parser(JavaParser.fromJavaVersion().classpath("slf4j-api", "lombok")) | ||||||||||||||||||
.typeValidationOptions(TypeValidation.builder().identifiers(false).build()), | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the fields are absent, we have missing type information in the result. I figured that's ok & to be expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess there is no way to get the type information from the annotation processor... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No we don't run the Lombok annotation processor, so we don't have that information available; it's good enough to make this code change; not quite sure if any followup recipes would work, but the JavaTemplates we use should have the type information, as per rewrite-logging-frameworks/src/main/java/org/openrewrite/java/logging/SystemErrToLogging.java Lines 178 to 185 in 53f8787
|
||||||||||||||||||
//language=java | ||||||||||||||||||
java( | ||||||||||||||||||
""" | ||||||||||||||||||
import lombok.extern.slf4j.Slf4j; | ||||||||||||||||||
@Slf4j | ||||||||||||||||||
class Test { | ||||||||||||||||||
void test() { | ||||||||||||||||||
try { | ||||||||||||||||||
} catch(Throwable t) { | ||||||||||||||||||
t.printStackTrace(); | ||||||||||||||||||
t.printStackTrace(System.err); | ||||||||||||||||||
t.printStackTrace(System.out); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
""", | ||||||||||||||||||
""" | ||||||||||||||||||
import lombok.extern.slf4j.Slf4j; | ||||||||||||||||||
@Slf4j | ||||||||||||||||||
class Test { | ||||||||||||||||||
void test() { | ||||||||||||||||||
try { | ||||||||||||||||||
} catch(Throwable t) { | ||||||||||||||||||
log.error("Exception", t); | ||||||||||||||||||
log.error("Exception", t); | ||||||||||||||||||
log.error("Exception", t); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
""" | ||||||||||||||||||
) | ||||||||||||||||||
); | ||||||||||||||||||
} | ||||||||||||||||||
} |
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.
By default fields are named
log
, as per: https://projectlombok.org/features/logDidn't quite feel like parsing any lombok configuration files in case folks set a different
lombok.log.fieldName
.If they do that, then can set the
loggerName
option to have that be used for the logging statements instead.