Add a literal method argument

Apache 2.0

Add a literal String or primitive argument to method invocations.

org.openrewrite.java.AddLiteralMethodArgument

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.

A zero-based index indicating where to insert the new argument.

The literal value to add as an argument.

Optional

The parameter type for the added argument. Defaults to String.

mod run . --recipe=org.openrewrite.java.AddLiteralMethodArgument \ -P methodPattern='com.yourorg.A foo(int, int)' \ -P argumentIndex=0 \ -P literal=abc

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