Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoveUnusedPrivateMethods should ignore class annotated with @SupressWarning("unused") #293

Conversation

Dinozavvvr
Copy link
Contributor

@Dinozavvvr Dinozavvvr commented May 13, 2024

@timtebeek timtebeek added the enhancement New feature or request label May 14, 2024
@timtebeek timtebeek changed the title Fix #4188 org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods issue with ignored @SupressWarning("unused") on class RemoveUnusedPrivateMethods should ignore class annotated with @SupressWarning("unused") May 14, 2024
@timtebeek
Copy link
Contributor

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.

return Preconditions.check(new NoMissingTypes(), new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {

@Dinozavvvr
Copy link
Contributor Author

@timtebeek thank you a lot for your suggestion!

@Dinozavvvr
Copy link
Contributor Author

Dinozavvvr commented May 15, 2024

@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

@Dinozavvvr
Copy link
Contributor Author

Did it

@Dinozavvvr Dinozavvvr marked this pull request as ready for review May 15, 2024 05:22
@timtebeek
Copy link
Contributor

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!

@timtebeek timtebeek changed the title RemoveUnusedPrivateMethods should ignore class annotated with @SupressWarning("unused") RemoveUnusedPrivateMethods should ignore class annotated with @SupressWarning("unused") May 21, 2024
@timtebeek timtebeek merged commit 5a391c1 into openrewrite:main May 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods ignores class level @SuppressWarnings("unused")
2 participants