Make inner classes static when they use no enclosing instance
ProprietaryAdds static to a member class that does not use an instance of an enclosing class: no instance field or method of an enclosing class by simple name, no qualified Outer.this or Outer.super, no unqualified creation or extension of another inner class of an enclosing class, and no type parameter, local variable or parameter of an enclosing declaration. Each instance of such a class keeps its enclosing instance reachable for no reason. A class that is public or protected, Serializable or with a supertype that cannot be resolved, created as outer.new C() or extended through outer.super() or selected as Outer<T>.C anywhere in the repository, or a member of an inner class before Java 16, is marked instead. Interfaces, enums, records, local and anonymous classes and JUnit @Nested classes are left alone, as is a class in which some simple name cannot be resolved. Test sources are not changed.
io. moderne. staticanalysis. MakeInnerClassStaticmod run . --recipe= io. moderne. staticanalysis. MakeInnerClassStaticInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.