Replace fields that every use writes first with local variables

Proprietary

Removes a private, non-final field whose value no method, constructor or initializer of its class ever observes on entry, and declares a local variable in each body that uses it instead. Every such body writes the field before each read, by the definite assignment rules of the Java language, so the local is declared at the first statement that mentions the field, or takes that statement's value when it assigns the field. A local takes another name when the body already has a variable of the field's name. A field is marked instead when it is a non-transient instance field of a Serializable class or of a class with a supertype that cannot be resolved, when its initializer is not a literal, when a body that reads it calls a method or constructor that may run code of its class, or when it is used in a field initializer, in more than one initializer block, or in an initializer block next to its own initializer. Fields with annotations, fields of classes with Lombok annotations, fields used in a lambda or a nested class, and instance fields used through another object than this are left alone. Test sources are not changed.

io.moderne.staticanalysis.ReplaceFieldWithLocalVariables
mod run . --recipe=io.moderne.staticanalysis.ReplaceFieldWithLocalVariables

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