Skip to content

Feature Request: Support Eclipse "Source Clean Up" actions #1626

Open

Description

@ghokun

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.

Screenshot_2020-09-18_11-00-04

Like format settings, clean up settings could be set up with an xml file.

{
    "java.format.settings.url": "...",
    "java.cleanup.settings.url" : "..."
}

Also, I would like to contribute to this issue, if someone points me to the right direction.

mentioned in #1379

Activity

  1. xtianus79 commented on May 1, 2021

    @xtianus79

    @jdneo and @testforstephen is there any update on this a year later?

  2. chriscasola commented on Aug 11, 2021

    @chriscasola

    I am interested in this feature as well - any update? Or pointers on how to contribute?

  3. jcolladosp commented on Sep 6, 2021

    @jcolladosp

    Hi guys, do you know if there's any update on this?
    Thanks

  4. gayanper commented on Sep 23, 2022

    @gayanper
    Contributor

    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

  5. testforstephen commented on Feb 13, 2023

    @testforstephen
    Collaborator

    Assign to @rgrunber since his team is working on this area recently.

  6. rgrunber commented on Feb 13, 2023

    @rgrunber
    Member

    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 :
    AbstractCleanupCore

    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.

  7. blacelle commented on Apr 6, 2023

    @blacelle

    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).

  8. mpet commented on Feb 12, 2025

    @mpet

    @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

  9. rgrunber commented on Feb 13, 2025

    @rgrunber
    Member

    Try "java.cleanup.actions": [ "qualifyMembers", "qualifyStaticMembers" ]. You don't need to set them as true. Just them being listed enables them.

  10. mpet commented on Feb 13, 2025

    @mpet

    @rgrunber vscode accepts it. In which context can I use this?

    • whole java project
    • maven module
    • java package
    • java file

    And how to perform the check?
    Is it possible to run rule and let IDE make changes on the code?

    br,

    //mike

  11. rgrunber commented on Feb 13, 2025

    @rgrunber
    Member

    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).

  12. mpet commented on Feb 13, 2025

    @mpet

    @rgrunber so it is not possible to run these on the complete project?

  13. rgrunber commented on Feb 13, 2025

    @rgrunber
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions