openrewrite / rewrite-templating

Automated templating using code snippets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support additional Refaster features seen in error-prone-support

timtebeek opened this issue · comments

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.

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

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!

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.

@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 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.

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

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

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

[INFO] @Matches is currently not supported=1
[INFO] @Repeated is currently not supported=1
[INFO] Method references are currently not supported=1
[INFO] Lambdas are currently not supported=2
[INFO] If statements are currently not supported=8
[INFO] @AlsoNegation is currently not supported=11
[INFO] @Placeholder is currently not supported=15
[INFO] com.google.errorprone.refaster.Refaster is currently not supported=75
[INFO] Generic type parameters are currently not supported=495

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

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.

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.

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.

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

  • Also link to the docs for nested inner classes, when the outer class is annotated
  • Use the OnlineDocumentation annotation assigned or default value, rather than assume the URLs are stable