-
Notifications
You must be signed in to change notification settings - Fork 28
Add ArgumentArrayToVarargs
for logger methods that take a var args argument Object array
#246
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
Conversation
src/test/java/org/openrewrite/java/logging/ArgumentArrayToVarargsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/ArgumentArrayToVarargsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/ArgumentArrayToVarargsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/jboss/JBossLoggingBestPracticesTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/ArgumentArrayToVarargsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/jboss/JBossLoggingBestPracticesTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/ArgumentArrayToVarargsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/logging/jboss/JBossLoggingBestPracticesTest.java
Outdated
Show resolved
Hide resolved
ArgumentArrayToVarargs
for logger methods that take a var args argument Object array
|
||
class Test { | ||
void test(Logger logger, String msg, Object o) { | ||
logger.infov(msg, o); |
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.
It's subtle, but this chains back to back two recipes to go from info
to infov
and from that object array to just the arguments taken from it.
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.
Committed a change to make JulParameterizedArguments
use ArgumentArrayToVarargs
but might be a tad hackish: I wish I could make the MethodInvocation from the JavaTemplate have a varargs, but we have to set that flag after the fact.
Also have to coerce the MI vararg argument to Object[] to make sure that:
- ArgumentArrayToVarargs' visitor will filter in the MI, it would reject it if the argument was of another type.
- Have the JavaTemplate generate the MI with a methodType.parametersType[2] of Object[], it would otherwise create the parameter type based on the provided argument type. If that parameter isn't Object[], it won't match the MethodMatcher of the
ArgumentArrayToVarargs
.
public void defaults(RecipeSpec spec) { | ||
spec.recipe(new ArgumentArrayToVarargs()) | ||
.parser(JavaParser.fromJavaVersion() | ||
.classpathFromResources(new InMemoryExecutionContext(), "slf4j-api-2.1.+")); |
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.
Tests are passing without the extra config
public void defaults(RecipeSpec spec) { | |
spec.recipe(new ArgumentArrayToVarargs()) | |
.parser(JavaParser.fromJavaVersion() | |
.classpathFromResources(new InMemoryExecutionContext(), "slf4j-api-2.1.+")); | |
spec.recipe(new ArgumentArrayToVarargs()); |
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.
I suspect that's a result of a leaky classloader, as we do really need the SLF4J classes on the classpath, which ought not to be present by default. Hence why I'd added them here as that might change in the future.
|
||
@SuppressWarnings("ConfusingArgumentToVarargsMethod") | ||
@Test | ||
void nonObjectArrayNotConverted() { |
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.
Why not support arrays of any type? slf4j ends up calling .toString()
on the arguments no matter their type anyways?
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.
…y-to-varargs # Conflicts: # src/main/java/org/openrewrite/java/logging/slf4j/JulParameterizedArguments.java
…rom 3.7.0 to 3.13.0 [skip ci] Bumps [org.openrewrite.recipe:rewrite-logging-frameworks](https://github.com/openrewrite/rewrite-logging-frameworks) from 3.7.0 to 3.13.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-logging-frameworks's releases](https://github.com/openrewrite/rewrite-logging-frameworks/releases).* > 3.13.0 > ------ > > What's Changed > -------------- > > * Recipe to migrate deprecated JBoss Logging calls by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#245](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/245) > * Add `ArgumentArrayToVarargs` for logger methods that take a var args argument Object array by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-logging-frameworks#246](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/246) > * Avoid unsafe changes in `JulParameterizedArguments` when `JavaType.Array` argument is not a `J.NewArray` by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#244](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/244) > * LoggerLevelArgumentToMethod for JBoss Logging by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#243](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/243) > * Add a recipe to migrate from JBoss Logging to SLF4J by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#241](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/241) > * rename settings.local.json to settings.json by [`@zieka`](https://github.com/zieka) in [openrewrite/rewrite-logging-frameworks#247](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/247) > > **Full Changelog**: <openrewrite/rewrite-logging-frameworks@v3.12.0...v3.13.0> > > 3.12.1 > ------ > > What's Changed > -------------- > > * OpenRewrite v8.59.1: <https://github.com/openrewrite/rewrite> > > **Full Changelog**: <https://github.com/openrewrite/rewrite-logging-frameworks> > > 3.12.0 > ------ > > What's Changed > -------------- > > * Adds filePattern parameter to ConfigureLoggerLevel by [`@simonzn`](https://github.com/simonzn) in [openrewrite/rewrite-logging-frameworks#235](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/235) > * Handle existing arguments alongside concatenation in `ParameterizedLogging` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-logging-frameworks#237](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/237) > * Fix Slf4jLogShouldBeConstant to preserve format specifiers with width, alignment, and precision. by [`@motlin`](https://github.com/motlin) in [openrewrite/rewrite-logging-frameworks#239](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/239) > > New Contributors > ---------------- > > * [`@simonzn`](https://github.com/simonzn) made their first contribution in [openrewrite/rewrite-logging-frameworks#235](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/235) > * [`@motlin`](https://github.com/motlin) made their first contribution in [openrewrite/rewrite-logging-frameworks#239](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/239) > > **Full Changelog**: <openrewrite/rewrite-logging-frameworks@v3.11.0...v3.12.0> > > 3.11.0 > ------ > > What's Changed > -------------- > > * fix: any last argument matching `Throwable.toString()` is left as is by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#229](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/229) > * refactor: org.openrewrite.mavencentral by [`@Laurens-W`](https://github.com/Laurens-W) in [openrewrite/rewrite-logging-frameworks#230](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/230) > * Don't if-wrap logs when arguments are getters by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#233](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/233) > > **Full Changelog**: <openrewrite/rewrite-logging-frameworks@v3.10.0...v3.11.0> > > 3.10.0 > ------ > > What's Changed > -------------- > > * Add recipe to change logger fields to private by [`@jhl221123`](https://github.com/jhl221123) in [openrewrite/rewrite-logging-frameworks#221](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/221) > * Add `MatchIsLogLevelEnabledWithLogStatements` to SLF4J best practices by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-logging-frameworks#222](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/222) > * Exclude spotbugs dependency by [`@greg-at-moderne`](https://github.com/greg-at-moderne) in [openrewrite/rewrite-logging-frameworks#225](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/225) > * Recipe to remove `.toString()` called on parameterized logging statement arguments by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#224](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/224) > * fix: match `.toString()` on any type, not just java.lang.Object by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-logging-frameworks#226](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/226) > > New Contributors > ---------------- > > * [`@jhl221123`](https://github.com/jhl221123) made their first contribution in [openrewrite/rewrite-logging-frameworks#221](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/221) > * [`@pdelagrave`](https://github.com/pdelagrave) made their first contribution in [openrewrite/rewrite-logging-frameworks#224](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/224) ... (truncated) Commits * [`946d0ce`](openrewrite/rewrite-logging-frameworks@946d0ce) Update documentation examples * [`210eff9`](openrewrite/rewrite-logging-frameworks@210eff9) rename settings.local.json to settings.json ([#247](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/issues/247)) * [`2e67627`](openrewrite/rewrite-logging-frameworks@2e67627) Add a recipe to migrate from JBoss Logging to SLF4J ([#241](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/issues/241)) * [`c59c405`](openrewrite/rewrite-logging-frameworks@c59c405) LoggerLevelArgumentToMethod for JBoss Logging ([#243](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/issues/243)) * [`36a5200`](openrewrite/rewrite-logging-frameworks@36a5200) OpenRewrite recipe best practices * [`aa3f14f`](openrewrite/rewrite-logging-frameworks@aa3f14f) Avoid unsafe changes in `JulParameterizedArguments` when `JavaType.Array` arg... * [`249944e`](openrewrite/rewrite-logging-frameworks@249944e) Add `ArgumentArrayToVarargs` for logger methods that take a var args argument... * [`bb34ecf`](openrewrite/rewrite-logging-frameworks@bb34ecf) Create Claude settings file * [`ce8bc2d`](openrewrite/rewrite-logging-frameworks@ce8bc2d) refactor: Static imports for Collections and Collectors * [`af44c67`](openrewrite/rewrite-logging-frameworks@af44c67) Recipe to migrate deprecated JBoss Logging calls ([#245](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/issues/245)) * Additional commits viewable in [compare view](openrewrite/rewrite-logging-frameworks@v3.7.0...v3.13.0) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
No description provided.