-
Notifications
You must be signed in to change notification settings - Fork 79
Add recipe to remove unused constructor and method parameters #560
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done!
try polish.
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
This one done: Do we cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 660-659
- lines 705-721
- lines 1254-1273
- lines 1306-1305
- lines 2337-2336
- lines 2352-2364
- lines 2801-2800
- lines 2820-2831
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 660-659
- lines 705-721
- lines 1254-1273
- lines 1306-1305
- lines 2337-2336
- lines 2352-2364
- lines 2801-2800
- lines 2820-2831
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
RemoveUnusedParams only handles unused parameters. Unused assignments would need their own recipe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 328-345
- lines 660-659
- lines 705-721
- lines 1254-1273
- lines 1306-1305
- lines 2251-2250
- lines 2337-2336
- lines 2352-2364
- lines 2801-2800
- lines 2820-2831
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
…s.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try avoid feature envy (& DRY) giving single point of truth (SPOT)
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new test case - cover constructor as well.
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments Updated review comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 328-345
- lines 660-659
- lines 705-721
- lines 1254-1273
- lines 1306-1305
- lines 2251-2250
- lines 2337-2336
- lines 2352-2364
- lines 2801-2800
- lines 2820-2831
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
…s.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…s.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last polish.
Done very well, could already merge.
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveUnusedParamsTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 328-345
- lines 660-659
- lines 705-721
- lines 1254-1273
- lines 1306-1305
- lines 2251-2250
- lines 2337-2336
- lines 2352-2364
- lines 2801-2800
- lines 2820-2831
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks already! Couple fixes applied just now, and a few more hints added where more work is needed. Let me know if you'd like to continue this yourself.
Thank you for the updates and guidance! I’m tied up with some other work as well, but I’ll tackle the remaining items as soon as I have some free time. Please feel free to continue in the meantime. |
Hey @timtebeek, thanks for flagging those edge cases—avoidDirectConflict, avoidInheritedConflict, and cascadeRemoveUnusedArguments. I’ll revisit the pruning logic with those in mind. In the meantime, if you have any suggestions on how to handle them, Let me know your thoughts! |
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
you are really talented, keep pushing @iddeepak. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- build.gradle.kts
- lines 23-22
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
…s.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/main/java/org/openrewrite/staticanalysis/RemoveUnusedParams.java
Outdated
Show resolved
Hide resolved
…s.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
What’s changed?
I’ve added a new recipe class, RemoveUnusedParams, that automatically removes parameters from Java methods when they’re declared but never referenced in the method body. It still respects:
@Deprecated
)Alongside the main recipe, I’ve expanded the unit tests to cover:
What’s your motivation?
Over time, code tends to accumulate unused parameters—leftovers from refactoring, changing requirements, or evolving APIs. They add noise, make signatures harder to read, and can confuse future maintainers. This recipe:
Anything in particular you'd like reviewers to focus on?
JavaIsoVisitor
pass—does it still scale on large projects?Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
MethodMatcher
or type-based override detection; this felt like overkill for a simple annotation check.Any additional context
mvn test
.Checklist