openrewrite / openrewrite/rewrite

Expand getCoordinates of newClass to access arguments

Open
#4,089 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What problem are you trying to solve?

I would like to switch one constructor call for an other with JavaTemplate. E.g. if a class A offers two constructors A(int foo), A(int foo, double ba) I would like to be able to insert a new argument after, or replace the list of arguments altogether.

Describe the solution you'd like

API offers suitable methods through getCoordinates.

Have you considered any alternatives or workarounds?

Replacing the entire constructor call should work in theory.
withArguments() works as well, but JavaTemplates seem to be the way to go.

Additional context

Currently a constructor call can be replaced entirely, but it would be nice to be able to operate it without putting "new A" into the template, which requires me to find out the class name at runtime.
J.MethodInvocation already has getCoordinates().replaceArguments(), that could just be implemented in newClass as well.

Are you interested in contributing this feature to OpenRewrite?

probably won't find the time

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 by locating the getCoordinates implementation for newClass and the existing J.MethodInvocation replaceArguments support. Compare how JavaTemplate handles constructor calls and determine how argument insertion or replacement can work without embedding "new A". Done means the newClass coordinates expose the requested argument operations with suitable coverage for the constructor-call cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.