Change static field access to static method access

Apache 2.0

Migrate accesses to a static field to invocations of a static method.

org.openrewrite.java.ChangeStaticFieldToMethod

Required

The fully qualified name of the class containing the field to replace.

The simple name of the static field to replace.

The simple name of the method to use. The method must be static and have no arguments.

Optional

The fully qualified name of the class containing the method to use. Leave empty to keep the same class.

An optional method target that can be used to specify a static field within the new class.

mod run . --recipe=org.openrewrite.java.ChangeStaticFieldToMethod \ -P oldClassName=java.util.Collections \ -P oldFieldName=EMPTY_LIST \ -P newMethodName=of

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