openrewrite / rewrite-templating

Automated templating using code snippets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support reuse of template method arguments

timtebeek opened this issue · comments

What problem are you trying to solve?

Template method arguments can only be used once in the after template.
Even relatively simple replacements such as this one currently fail.

    @AfterTemplate
    boolean notNullNotBlank(String s) {
        return s != null && !s.isEmpty();
    }

Describe the solution you'd like

Template arguments can reliably be used twice in after template and the resulting recipe.

A number of options have been proposed such as:

  1. adding the argument twice in the parameters passed into JavaTemplate.apply, which can't then support arguments that can have side effects
  2. adding named or numbered parameters to the argument handling in JavaTemplate as per @knutwannheden