openrewrite / rewrite-templating

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

Support additional Refaster features seen in error-prone-support #47

Open timtebeek opened 11 months ago

timtebeek commented 11 months ago

What problem are you trying to solve?

Expand the set of Refaster rules in Error Prone Support that we cover with OpenRewrite recipes.

Describe the solution you'd like

Support the following cases not currently covered.

Stephan202 commented 11 months ago

Hey @timtebeek! The @DoNotCall annotation has no impact for Refaster; it's there only to appease the DoNotCall check :)

timtebeek commented 11 months ago

Hey @timtebeek! The @DoNotCall annotation has no impact for Refaster; it's there only to appease the DoNotCall check :)

Thanks for that context! Right now we skip any rules where that annotation is present, but it seems like we can tolerate the presence of that annotation and just generate the recipes in those cases. Good to know!

timtebeek commented 11 months ago

Even if we ignore the presence of @UseImportOlicy annotation it seems we still have some work to do before recipe correctly compile, as we don't yet add resolve and imports explicitly. Internally we had relied on after templates always using fully qualified refs, but we can't expect that going forward.

knutwannheden commented 11 months ago

@timtebeek I think we can. I thought the template code is already being generated with all fully qualified references (regardless if the input uses qualified references or not). That was in any case the idea.

timtebeek commented 11 months ago

@timtebeek I think we can. I thought the template code is already being generated with all fully qualified references (regardless if the input uses qualified references or not). That was in any case the idea.

Exploring the addition of new static imports now in this PR; based on what we do versus need it looks like we have some work to do still.

timtebeek commented 11 months ago

Some quick stats on why various refaster rules were excluded, such that we know what to cover next:

[INFO] 791x Generics are currently not supported
[INFO] 40x com.google.errorprone.refaster.Refaster is currently not supported
[INFO] 19x @AlsoNegation is currently not supported
[INFO] 15x @Placeholder is currently not supported
[INFO] 8x If statements are currently not supported
[INFO] 1x @Matches is currently not supported
knutwannheden commented 9 months ago

Basic generics support is available. Not yet for gwneric type variables, however.

timtebeek commented 9 months ago

With Knut's support for generics and a very minor new exclusion, these are the new stats with regards to what's supported/skipped:

All together we now generate 442 before templates; for 298 after templates.

timtebeek commented 8 months ago

As discussed yesterday with @rickie we might want to detect any use of OnlineDocumentation, and if present add a link to that URL in the documentation that we generate, both to give credit and additional context to what a recipe would effectively do. https://github.com/PicnicSupermarket/error-prone-support/blob/8f64489fa0dded9255d20c227d0810af1cf52493/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java#L44-L48

We already parse any JavaDoc that's present (even if it's often missing); we might want to expand (or generate) the Javadocs present in Error Prone Support to improve how those are presented to our users.

We might also want to create an aggregate yaml recipe across all Refaster recipes generated, to make it easier to apply all recipes at once.

rickie commented 8 months ago

About the @OnlineDocumentation, it has default values that are used by Picnic. However, others can use the annotation to link to their own website if they have one. So supporting the annotation will not be a "Picnic-specific" solution.

timtebeek commented 8 months ago

We can also already generate templates for any rules that use @AlsoNegation, without generating that negation just yet. Adding that negated recipe can then be left as a next step.

timtebeek commented 8 months ago

With #78 we now also have some initial links to the docs for the wrapping outer classes. Possible future improvements are