Closed Dinozavvvr closed 1 month ago
Thanks a lot for the start @Dinozavvvr ! As indicated in the issue we'll likely want to add an override of visitClassDeclaration
, that uses FindAnnotations
to find the suppress annotation on the class, inspects the value, and if that contains unused
then do not call super.visitClassDeclaration
, but return the original argument classDeclaration. That'll be in between these lines in the recipe itself.
https://github.com/openrewrite/rewrite-static-analysis/blob/b7b1bd1fd82c5e713d7ea5777375c6daf6eb9067/src/main/java/org/openrewrite/staticanalysis/RemoveUnusedPrivateMethods.java#L55-L57
@timtebeek thank you a lot for your suggestion!
@timtebeek I found that solution based on visiting J.ClassDeclaration ignores nested classes (I'm not sure should it or not), so if is it I will move this check to visitMethodDeclaration
Did it
Great to see you've worked this out @Dinozavvvr ! I've added a small polishing commit to better fit in with our code conventions. Seems like a handy pattern to limit recipe execution by looking for suppressed warnings. We might just want to apply that in a few more cases, or pull this up to a higher level even. Neat stuff!
Fix #294
294