openrewrite / openrewrite/rewrite

Support lst parameters for JavaTemplate in method Parameters, ClassDecl body...

Open
#5,853 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What problem are you trying to solve?

At this moment, JavaTemplate uses a __P__.p() method invocation to replace the parameter with the lst element. However, in certain locations the compiler crashes on MethodInvocations.

Replicated this in a unit test in https://github.com/openrewrite/rewrite/tree/show-issue-javatemplate-method-as-parameter. Copy the sysout template to a java scratch file and see that the template is invalid for the #{any()}

Describe the solution you'd like

Perhaps smart(er) template that allows for this. Perhaps we could use some kind of constant that we create in __P__ or __M__ and then in templating also resolve these FieldAccesses?

Have you considered any alternatives or workarounds?

I have manually worked around this limitation by setting Parametes myself on the generated template instance.

Are you interested in contributing this feature to OpenRewrite?

Obviously :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the unit-test reproduction on the show-issue-javatemplate-method-as-parameter branch and copy its sysout template into a Java scratch file. Investigate JavaTemplate parameter handling for method Parameters and ClassDecl bodies; done means lst parameters work there without the compiler crash or invalid #{any()} template behavior, with the reproduction covered by a unit test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.