openrewrite / openrewrite/rewrite
Support lst parameters for JavaTemplate in method Parameters, ClassDecl body...
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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