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

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

Open
ghokun opened this issue Sep 18, 2020 · 13 comments
Open

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

ghokun opened this issue Sep 18, 2020 · 13 comments

Comments

@ghokun
Copy link
Contributor

ghokun commented Sep 18, 2020

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

@xtianus79
Copy link

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

@chriscasola
Copy link

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

@jcolladosp
Copy link

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

@gayanper
Copy link
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

@testforstephen
Copy link
Collaborator

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

@rgrunber
Copy link
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.

@blacelle
Copy link

blacelle commented 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
Copy link

mpet commented 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
Copy link
Member

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

@mpet
Copy link

mpet commented Feb 13, 2025

@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

@rgrunber
Copy link
Member

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

@mpet
Copy link

mpet commented Feb 13, 2025

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

@rgrunber
Copy link
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
Projects
None yet
Development

No branches or pull requests

9 participants