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

Consider merging TemplateProcessor into RefasterTemplateProcessor #48

Closed
timtebeek opened this issue Dec 17, 2023 · 1 comment · Fixed by #57
Closed

Consider merging TemplateProcessor into RefasterTemplateProcessor #48

timtebeek opened this issue Dec 17, 2023 · 1 comment · Fixed by #57
Labels
enhancement New feature or request

Comments

@timtebeek
Copy link
Contributor

What problem are you trying to solve?

Right now we maintain two separate processors, TemplateProcessor and RefasterTemplateProcessor which each produce Java files. These are then stitched together through Semantics, PatternBuilder and reflection.

public JavaTemplate.Builder build(JavaVisitor<?> owner) {
try {
Class<?> templateClass = Class.forName(owner.getClass().getName() + "_" + name, true,
owner.getClass().getClassLoader());
Method getTemplate = templateClass.getDeclaredMethod("getTemplate");
return (JavaTemplate.Builder) getTemplate.invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
throw new RuntimeException(e);
}

I think originally we had developed these separately with the idea that the generated templates could also be used independent of any generated Refaster recipe. In practice this hasn't happened, and I don't immediately see that happening still.

Describe the solution you'd like

I think we could merge the two into a single processor now and take out the extra generated classes and reflection glue.

Have you considered any alternatives or workarounds?

  • Keep these as-is.
  • Have RefasterTemplateProcessor call a method on TemplateProcessor to inline the templates.
@timtebeek timtebeek added the enhancement New feature or request label Dec 17, 2023
@timtebeek timtebeek moved this to Backlog in OpenRewrite Dec 17, 2023
@knutwannheden
Copy link
Contributor

I disagree. I think there is yet use for the annotation processor we use to process the Semantics calls, when more complex recipes than what can achieved with Refaster are required, yet, either the matching or templating mechanism based on lambdas is still desired. I think we have some examples in rewrite-micrometer.

This being said, I think it could still make sense to basically "inline" the templating processor into the Refaster processor, so we don't have to produce more Java source files. But also this has pros and cons.

@timtebeek timtebeek linked a pull request Mar 3, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Mar 4, 2024
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