Change method invocation return type

Apache 2.0

Changes the return type of a method invocation.

org.openrewrite.java.ChangeMethodInvocationReturnType

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.

The fully qualified new return type of method invocation. Parameterized types like java.util.Set<java.lang.String> are supported; java.lang type arguments may use their simple name, e.g. java.util.List<String>. Nested types may be written with a $ separator, e.g. mockwebserver3.MockResponse$Builder; dots also work, e.g. mockwebserver3.MockResponse.Builder, in which case the first segment that is followed only by segments starting with an uppercase letter is taken to be the outermost type.

mod run . --recipe=org.openrewrite.java.ChangeMethodInvocationReturnType \ -P methodPattern='org.mockito.Matchers anyVararg()' \ -P newReturnType=long

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