openrewrite / rewrite-templating

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

Detect method calls beyond static imports for `UsesMethod` in `Precondition.check` #26

Closed timtebeek closed 1 year ago

timtebeek commented 1 year ago

What problem are you trying to solve?

We want to limit recipe execution to improve performance, by adding appropriate preconditions. As of #24 we have some rudimentary preconditions based on imports.

Describe the solution you'd like

It would be even better to detect additional method invocations in the before templates and use those in our preconditions.

Have you considered any alternatives or workarounds?

No.

Additional context

timtebeek commented 1 year ago

Additional note to pick up: https://github.com/openrewrite/rewrite-templating/pull/24#discussion_r1298284366

For HashMap we could actually pass the [UsesType] second argument [includeImplicit] as false, because it must be directly referenced. Map is different, because you got that from the template's return type and not the template body. But we can still fix this later.

So in https://github.com/openrewrite/rewrite-templating/pull/24 we went for a quick solution where both before template input and return types both get includeImplicit = true, but that's only necessary for the return type, likely not for the input types.