Change method target to static
Apache 2.0Change method invocations to static method calls.
org. openrewrite. java. ChangeMethodTargetToStaticRequired
The original method call may or may not be a static method invocation. 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 fully-qualified class name of the type upon which the static method is defined.
Optional
Sometimes changing the target type also changes the return type. In the Guava example, changing from ImmutableSet#of(..) to Set#of(..) widens the return type from Guava's ImmutableSet to just java.util.Set.
When enabled, find methods that are overrides of the method pattern.
When enabled, include method invocations which appear to match if full type information is missing. Using matchUnknownTypes can improve recipe resiliency for an AST with missing type information, but also increases the risk of false-positive matches on unrelated method invocations.
mod run . --recipe= org. openrewrite. java. ChangeMethodTargetToStatic \
-P methodPattern= 'com. google. common. collect. ImmutableSet of(.. )' \
-P fullyQualifiedTargetTypeName= java. util. SetInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.