Skip to content

Replace JulGetLoggerToLoggerFactory Refaster recipe with imperative visitor#278

Merged
timtebeek merged 1 commit intomainfrom
replace-jul-refaster-with-imperative
Feb 12, 2026
Merged

Replace JulGetLoggerToLoggerFactory Refaster recipe with imperative visitor#278
timtebeek merged 1 commit intomainfrom
replace-jul-refaster-with-imperative

Conversation

@steve-aom-elliott
Copy link
Contributor

@steve-aom-elliott steve-aom-elliott commented Feb 12, 2026

Summary

  • Replaces the Refaster-based JulGetLoggerToLoggerFactory recipe with a hand-written JavaIsoVisitor implementation
  • Fixes malformed YAML in inline-log4j-api-methods.yml where preconditions: was concatenated onto the description

Problem

The Refaster-generated JulGetLoggerToLoggerFactoryRecipes class was failing to correctly match and transform Logger.getLogger(SomeClass.class.getName()) and Logger.getLogger(SomeClass.class.getCanonicalName()) calls. Instead of simplifying to LoggerFactory.getLogger(SomeClass.class), it was leaving the .getName() / .getCanonicalName() calls intact, causing JulToSlf4jTest.loggerToLoggerFactory() and staticFinalLoggerIsStaticFinal() to fail.

Solution

Replaced the Refaster template with an imperative JavaIsoVisitor that:

  1. Matches java.util.logging.Logger.getLogger(String) calls
  2. Checks if the argument is a Class.getName() or Class.getCanonicalName() invocation
  3. Extracts the class expression and rewrites to LoggerFactory.getLogger(clazz) via JavaTemplate

Also fixed inline-log4j-api-methods.yml where a missing newline caused the preconditions: YAML key to be parsed as part of the description text.

Notes

This was necessary due to

Test plan

  • All 9 tests in JulToSlf4jTest pass
  • Full test suite passes
  • recipeCsvGenerate and recipeCsvValidateContent pass

…isitor

The Refaster-generated recipe was failing due to changes in how Refaster
templates match method chain arguments like clazz.getName() and
clazz.getCanonicalName(). This replaces it with a hand-written
JavaIsoVisitor that explicitly matches Logger.getLogger() calls where
the argument is Class.getName() or Class.getCanonicalName(), and
rewrites them to LoggerFactory.getLogger(clazz).

Also fixes a malformed YAML in inline-log4j-api-methods.yml where the
preconditions key was concatenated onto the description line.
@steve-aom-elliott
Copy link
Contributor Author

I suppose I'd note that it did convert it with Class rather than Class<?>, though I'm not sure that is really going to make a difference here.

@steve-aom-elliott steve-aom-elliott moved this from In Progress to Ready to Review in OpenRewrite Feb 12, 2026
@steve-aom-elliott steve-aom-elliott added bug Something isn't working recipe Recipe Requested labels Feb 12, 2026
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@timtebeek timtebeek merged commit 1d4b8f7 into main Feb 12, 2026
1 check passed
@timtebeek timtebeek deleted the replace-jul-refaster-with-imperative branch February 12, 2026 22:30
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 12, 2026
mergify bot added a commit to robfrank/linklift that referenced this pull request Feb 26, 2026
…rom 3.23.0 to 3.24.0 [skip ci]

[//]: # (dependabot-start)
⚠️ \*\*Dependabot is rebasing this PR\*\* ⚠️
Rebasing might not happen immediately, so don't worry if this takes some time.
Note: if you make any changes to this PR yourself, they will take precedence over the rebase.
---
[//]: # (dependabot-end)
Bumps [org.openrewrite.recipe:rewrite-logging-frameworks](https://github.com/openrewrite/rewrite-logging-frameworks) from 3.23.0 to 3.24.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-logging-frameworks's releases](https://github.com/openrewrite/rewrite-logging-frameworks/releases).*

> 3.24.0
> ------
>
> What's Changed
> --------------
>
> * Replace JulGetLoggerToLoggerFactory Refaster recipe with imperative visitor by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-logging-frameworks#278](https://github.com/openrewrite/rewrite-logging-frameworks/pull/278)
> * Fix CI: Change slf4j-api-2.1.+ to slf4j-api-2 by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-logging-frameworks#279](https://github.com/openrewrite/rewrite-logging-frameworks/pull/279)
>
> New Contributors
> ----------------
>
> * [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) made their first contribution in [openrewrite/rewrite-logging-frameworks#278](https://github.com/openrewrite/rewrite-logging-frameworks/pull/278)
>
> **Full Changelog**: <openrewrite/rewrite-logging-frameworks@v3.23.0...v3.24.0>


Commits

* [`da7581c`](openrewrite/rewrite-logging-frameworks@da7581c) OpenRewrite recipe best practices
* [`5130e9f`](openrewrite/rewrite-logging-frameworks@5130e9f) Update Gradle wrapper to 9.3.1
* [`2e1be67`](openrewrite/rewrite-logging-frameworks@2e1be67) Fix CI: Change slf4j-api-2.1.+ to slf4j-api-2 ([#279](https://github.com/openrewrite/rewrite-logging-frameworks/issues/279))
* [`acb11e3`](openrewrite/rewrite-logging-frameworks@acb11e3) OpenRewrite recipe best practices
* [`1d4b8f7`](openrewrite/rewrite-logging-frameworks@1d4b8f7) Replace JulGetLoggerToLoggerFactory Refaster recipe with imperative visitor (...
* See full diff in [compare view](openrewrite/rewrite-logging-frameworks@v3.23.0...v3.24.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-logging-frameworks&package-manager=maven&previous-version=3.23.0&new-version=3.24.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 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working recipe Recipe Requested

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants