Community
Participate
Working Groups
Would be nice to have a clean-up / save action which removes unused parameters from private methods.
There already is a "unused code" cleanup (UnusedCodeCleanUpCore). IMO, it would make more sense to add this cleanup as part of that class.
The "unused code" cleanups/fixes rely on problems reported by the compiler, I guess because it's easier than to do the usage analysis on the AST ourselves. There is a problem type "org.eclipse.jdt.core.compiler.IProblem.ArgumentIsNeverUsed" which can be used to find unused method parameters and there is even a fix being computed for the problem (see org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore.isUnusedMember(IProblemLocationCore)). However, there are two problemsi with this 1. The fix does not clean up any usages, so we're possibly introducing compile problems 2. The fix is also available for non-private methods where the parameter might be used in another implementation of the method As I understand it, cleanups should be localized to the open file, not reach out to other source code.
My plan is this: for efficiency's sake, I would make this cleanup part of "UnusedCoreCleanupCore", but only apply the cleanup for private methods and create our own rewrite operation that also removes any usages in the CU.
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/191020
Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/191020 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=77c45577a4043aaabdd62caf81e65cdf67c9ae62
Released for 4.24 M1
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/191946
Gerrit change https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/191946 was merged to [master]. Commit: http://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=2d80a9e3d5598ffc9ddc44125528f3f1259f6bb0
Thanks for this great feature, Thomas and welcome back. AFAICS you had a small break of Eclipse development starting 2004 until recently. :-)
If a parameter is annotated I think it should not be removed. Example: @Inject @Optional private void subscribeTopicAppStartup(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event) { // stuff } If you agree, I can open a new bug / GH issue for this additional change.
Verified for 4.24 M1 using I20220406 build
(In reply to Lars Vogel from comment #10) > If a parameter is annotated I think it should not be removed. Example: > > @Inject > @Optional > private void > subscribeTopicAppStartup(@UIEventTopic(UIEvents.UILifeCycle. > APP_STARTUP_COMPLETE) Event event) { > // stuff > } > > If you agree, I can open a new bug / GH issue for this additional change. I suggest you open a new bug and cc/assign Thomas to comment.
The New and Noteworthy of Eclipse 4.24 tells about "cleanup and quick-assist" (<https://www.eclipse.org/eclipse/news/4.24/jdt.php#strconcat-to-textblock>), but I cannot see any quick assist here. I guess "and quick-assist" is just a copy and paste error from the following Eclipse 4.22 New and Noteworthy item (see also the not adapted anchor name "strconcat-to-textblock"): https://www.eclipse.org/eclipse/news/4.22/jdt.php#strconcat-to-textblock So "and quick-assist" has to be removed from Eclipse 4.24 New and Noteworthy (and the anchor name should be adapted), right?
Disabling this option does not seem to actually disable this cleanup behavior.
(In reply to Peter Bull from comment #14) > Disabling this option does not seem to actually disable this cleanup > behavior. I cannot reproduce what you are saying. If the error is reproducible with the latest Eclipse SDK integration build (https://download.eclipse.org/eclipse/downloads/), please report it with a code example here: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues
(In reply to Holger Voormann from comment #15) > (In reply to Peter Bull from comment #14) > > Disabling this option does not seem to actually disable this cleanup > > behavior. > > I cannot reproduce what you are saying. > > If the error is reproducible with the latest Eclipse SDK integration build > (https://download.eclipse.org/eclipse/downloads/), please report it with a > code example here: > https://github.com/eclipse-jdt/eclipse.jdt.ui/issues OK, please see https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/313