openrewrite / rewrite-templating

Automated templating using code snippets.
Apache License 2.0
16 stars 7 forks source link

Split annotation processor from refaster converter #65

Closed Bananeweizen closed 6 months ago

Bananeweizen commented 6 months ago

What problem are you trying to solve?

I've just written a custom rewrite module with several refaster templates in Eclipse, and built it with Maven, which was quite some adventure (but it was far less complicated than getting the original refaster engine to work in an OSGi context with ECJ some years ago). While I was wondering if I might be able to debug even the annotation processor with that setup, it occurred to me that it should not be necessary to debug through the annotation processor interface.

Describe the solution you'd like

Split the annotation processor into 2 classes:

If I get it right, the annotation processor already converts the input to its own AST representation at the root level (the compilation unit), so the parsing should already be independent of the APT interface.

This would have two benefits:

Or do I miss something obvious that prohibits this separation?

timtebeek commented 6 months ago

Hi @Bananeweizen ; Neat to hear how you're applying the tools! Can't say this usage was foreseen, but that makes it all the more fun to hear about.

You're right in calling out that currently there's no clear separation between the annotation processor and the conversion of refaster templates to rewite recipes. I'm not sure how easy that separation would be, given that we use com.sun.tools.javac liberally throughout the code. While we're open to explore the option, there's also some ongoing efforts in #57 to reuse TemplateCode and elsewhere to support generics. Might be best to coordinate such that there's no conflicts with any work you might plan to do.

Bananeweizen commented 6 months ago

Thanks for the explanation. In that case I'll close this ticket, because the other restructuring tasks have more important benefits.

timtebeek commented 6 months ago

Welcome to revisit this once the other features have landed! Always nice to see if tools can be used in multiple ways, and a better separation would help the code quality as well.