You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Support Eclipse "Source Clean Up" actions #1626
Eclipse provides a feature called Clean up (Right click a source folder: Source -> Clean Up). Clean up profile can be defined from
Preferences -> Java -> Code Style -> Clean Up. Clean up profiles can be exported to an xml file.
Like format settings, clean up settings could be set up with an xml file.
Reacted by Chris Hoff, Matteo Hausner, Rene Svetina, Marinello, dlicois, Shi Chen, Alexander01998, jaysonsosweet, Lucas Welscher, Aylon Carrijo and 2 more
Anything stopping this enhancement? I see most of cleanup implementation doesn’t have ui component dependencies. Could we move those in jdt ui like we have done for type hierarchy?
or are we looking at handling this in a different way for vscode ? Like having individual cleanup as code actions?
Any from the following list could be supported though :
Might be best to prioritize the more interesting ones.
They could probably be added to the "Source Action" menu with just a few lines of code. In order to get them as code actions (quick assists), the cleanup would need to have some helper method to have it apply on an individual ASTNode as opposed to on the entire CompilationUnit, but that should be possible.
Reacted by Gokhun, dlicois, xiaoxiyao, Aylon Carrijo and mpet
Hello. I've tried integrating Eclipse CleanUp into Spotless (diffplug/spotless#1587) but there is still quite a long way to go. I feel some effort would be shared with the one in vscode-java.
Concurrently, you may wish to have a look into Cleanthat which offers a various list of similar CleanUp rules (Mutators).
The should apply to any project type (Maven, Gradle, Eclipse, Unmanaged, etc.) . You have a few options to perform this :
The setting java.cleanup.actions controls which options will be checked/applied. java.saveActions.cleanup (true or false) control whether it happens automatically any time the active editor is saved. It should act as true by default. It is also bound to the keybinding ctrl+shift+alt+s so it may be applied manually (or even mapped to another key binding from the keyboard shortcut menu).
We don't currently do this, but has been suggested in #1820, #1107, #2598. I don't see it as too difficult. We've just prioritized the editing experience rather than bulk project operations.
Activity
xtianus79 commentedon May 1, 2021
@jdneo and @testforstephen is there any update on this a year later?
chriscasola commentedon Aug 11, 2021
I am interested in this feature as well - any update? Or pointers on how to contribute?
jcolladosp commentedon Sep 6, 2021
Hi guys, do you know if there's any update on this?
Thanks
gayanper commentedon Sep 23, 2022
Anything stopping this enhancement? I see most of cleanup implementation doesn’t have ui component dependencies. Could we move those in jdt ui like we have done for type hierarchy?
or are we looking at handling this in a different way for vscode ? Like having individual cleanup as code actions?
@testforstephen @jdneo @rgrunber
testforstephen commentedon Feb 13, 2023
Assign to @rgrunber since his team is working on this area recently.
rgrunber commentedon Feb 13, 2023
We started doing this through the new setting
java.cleanup.actionsOnSave(through https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/cleanup/CleanUpRegistry.java in JDT-LS). Currently supported ones are https://github.com/redhat-developer/vscode-java/blob/master/document/_java.learnMoreAboutCleanUps.md#java-clean-ups .Any from the following list could be supported though :

Might be best to prioritize the more interesting ones.
They could probably be added to the "Source Action" menu with just a few lines of code. In order to get them as code actions (quick assists), the cleanup would need to have some helper method to have it apply on an individual
ASTNodeas opposed to on the entireCompilationUnit, but that should be possible.blacelle commentedon Apr 6, 2023
Hello. I've tried integrating Eclipse CleanUp into Spotless (diffplug/spotless#1587) but there is still quite a long way to go. I feel some effort would be shared with the one in
vscode-java.Concurrently, you may wish to have a look into Cleanthat which offers a various list of similar CleanUp rules (Mutators).
mpet commentedon Feb 12, 2025
@rgrunber is there any progress on this.
I tried in settings.json
"java.cleanup.actions": [ { "qualifyMembers": true, "qualifyStaticMembers": true } ]or
"java.cleanup.actions": [
{
"qualifyMembers": "true", "qualifyStaticMembers": "true"
}
]
Both in both cases vscode complains with
Incorrect type. Expected "string".
Value is not accepted. Valid values: "qualifyMembers", "qualifyStaticMembers", "addOverride", "addDeprecated", "stringConcatToTextBlock", "invertEquals", "addFinalModifier", "instanceofPatternMatch", "lambdaExpressionFromAnonymousClass", "lambdaExpression", "switchExpression", "tryWithResource", "renameFileToType", "organizeImports", "renameUnusedLocalVariables".(1)
Any ideas?
//mike
rgrunber commentedon Feb 13, 2025
Try
"java.cleanup.actions": [ "qualifyMembers", "qualifyStaticMembers" ]. You don't need to set them astrue. Just them being listed enables them.mpet commentedon Feb 13, 2025
@rgrunber vscode accepts it. In which context can I use this?
And how to perform the check?
Is it possible to run rule and let IDE make changes on the code?
br,
//mike
rgrunber commentedon Feb 13, 2025
The should apply to any project type (Maven, Gradle, Eclipse, Unmanaged, etc.) . You have a few options to perform this :
The setting
java.cleanup.actionscontrols which options will be checked/applied.java.saveActions.cleanup(trueorfalse) control whether it happens automatically any time the active editor is saved. It should act astrueby default. It is also bound to the keybinding ctrl+shift+alt+s so it may be applied manually (or even mapped to another key binding from the keyboard shortcut menu).mpet commentedon Feb 13, 2025
@rgrunber so it is not possible to run these on the complete project?
rgrunber commentedon Feb 13, 2025
We don't currently do this, but has been suggested in #1820, #1107, #2598. I don't see it as too difficult. We've just prioritized the editing experience rather than bulk project operations.