Change method target to variable

Apache 2.0

Change method invocations to method calls on a variable.

org.openrewrite.java.ChangeMethodTargetToVariable

Required

A method pattern is used to find matching method invocations. For example, to find all method invocations in the Guava library, use the pattern: com.google.common..*#*(..).

The pattern format is <PACKAGE>#<METHOD_NAME>(<ARGS>).

..* includes all subpackages of com.google.common.
*(..) matches any method name with any number of arguments.

For more specific queries, like Guava's ImmutableMap, use com.google.common.collect.ImmutableMap#*(..) to narrow down the results.

Name of variable to use as target for the modified method invocation.

Type attribution to use for the return type of the modified method invocation.

Optional

matchOverridesBoolean

When enabled, find methods that are overrides of the method pattern.

mod run . --recipe=org.openrewrite.java.ChangeMethodTargetToVariable \ -P methodPattern='org.mycorp.A method(..)' \ -P variableName=foo \ -P variableType=java.lang.String

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.