-
Notifications
You must be signed in to change notification settings - Fork 7
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
Inline Javatemplate in RefasterTemplateProcessor #57
Inline Javatemplate in RefasterTemplateProcessor #57
Conversation
@knutwannheden As expected
|
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.
Nice that we finally got this working!
final JavaTemplate before = Semantics.expression(this, "before", (String[] strings) -> String.join(", ", strings)).build(); | ||
final JavaTemplate after = Semantics.expression(this, "after", (String[] strings) -> String.join(":", strings)).build(); | ||
final JavaTemplate before = JavaTemplate | ||
.builder("String.join(\", \", #{strings:any(java.lang.String[])})") |
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.
Surprised the String
reference isn't qualified here. Will look into that separately.
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 see, we have an explicit exception for java.lang
:
rewrite-templating/src/main/java/org/openrewrite/java/template/internal/TemplateCode.java
Line 118 in 261ad17
print(sym.packge().fullname.contentEquals("java.lang") ? sym.name : sym.getQualifiedName()); |
It does make the template code a bit more readable, but it could cause problems when the Java class an after template gets embedded into is in a package which has a class by the same name, which is unusual but not unheard of.
I am a bit on the fence on this one. java.lang
is a special case also in the ShortenFullyQualifiedTypeReferences
recipe (for basically the same reason). But I think in probably around 90% of the cases the name would end up getting shortened, because the compilation unit already has another (unqualified) reference to the same type in which case the recipe knows it can shorten the reference.
As I pointed out before, this isn't directly related to your PR. It is just something that caught my eye.
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.
Yes we can tackle this separately; there's a few other items too I'd been looking to do after this lands, since any changes previously were likely to conflict with this one.
.build(); | ||
final JavaTemplate after = JavaTemplate | ||
.builder("String.join(\":\", #{strings:any(java.lang.String[])})") | ||
.build(); |
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.
The only downside I see with this refactoring is that the generated code is now harder to read and that the Semantics
mechanism isn't visible anymore. But I think that is acceptable.
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.
Yes the main motivator for me was PRs like this one that aim to use Java 9+ constructs in recipes, which previously meant that code was in the generated recipes as well(likely?) bumping the Java version required to run the recipe.
With this change I think we should be good to have the generated recipes included with the other Java 8 compatible classes.
WIP to replace directly create JavaTemplate in RefasterTemplateProcessor instead of indirection.