Skip to content
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

Recipe generation should invoke ShortenFullyQualifiedTypeReferences for recipe code itself #74

Closed
Bananeweizen opened this issue Feb 7, 2024 · 1 comment · Fixed by #57
Labels
enhancement New feature or request

Comments

@Bananeweizen
Copy link
Contributor

What problem are you trying to solve?

In the generated recipes the lambdas used for matching contain fully qualified type names for all types not contained in java.lang. Examples can be seen in this repository itself (watch for LoggerFactory, Pattern, Primitive):

JavaTemplate.Builder after = Semantics.statement(this, "after", (String message) -> org.slf4j.LoggerFactory.getLogger(message));

JavaTemplate.Builder before = Semantics.statement(this, "before", (String message) -> java.util.regex.Pattern.compile(message, DOTALL));

JavaTemplate.Builder before = Semantics.statement(this, "before", (@org.openrewrite.java.template.Primitive Integer i) -> System.out.println(i));

Describe the solution you'd like

While recipes are generated code, the lambdas would still be more readable for humans trying to debug/understand them. If the template contains multiple expressions or statements, they grow quite quickly anyway. So the TemplateProcessor should run ShortenFullyQualifiedTypeReferences on the generated recipe code before serializing it.

Are you interested in contributing this feature to OpenRewrite?

I can try, but might take a bit of time...

@Bananeweizen Bananeweizen added the enhancement New feature or request label Feb 7, 2024
@knutwannheden
Copy link
Contributor

I am not sure it will be worth the effort, since we want to proceed with #57 and thus no longer generate the Java lambdas in the first place, but instead directly generate template code (in Java strings). That will then also not be very readable, but having fully qualified names in the template code help avoid clashes when the template is applied.

@timtebeek timtebeek linked a pull request Mar 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants