rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Remove unused private classes

Open thomasleplus opened this issue 3 years ago • 3 comments

Hi,

I think that a recipe to remove unused private classes could be useful, similar to the existing org.openrewrite.java.cleanup.RemoveUnusedPrivateMethods recipe.

Cheers,

Tom

thomasleplus avatar Aug 12 '22 11:08 thomasleplus

Hi Tom, This is a good suggestion

pway99 avatar Aug 12 '22 17:08 pway99

I have some experience with detecting unused (non private) methods and classes through ArchUnit. In practice there's a lot of caveats that are framework and project specific before you're able to say classes or methods are unused.

Like classes/methods only used in (de)serialization; classes and methods called by frameworks based on annotations; code that has unit tests, but nothing else calling it; classes that implement an interface and are discovered that way.

A lot of these details only show up once you start to implement such checks, and I think it would be quite hard to implement a defensive do-no-harm recipe that takes all this into account. Just thought I'd provide some insight here, before any naive attempts are made that might inadvertently break stuff.

timtebeek avatar Aug 23 '22 12:08 timtebeek

Thanks Tim!

pway99 avatar Aug 23 '22 15:08 pway99