Add support for Eclipse Clean Up
See original GitHub issueFrom my understanding Spotless uses org.eclipse.jdt:org.eclipse.jdt.core
to do formatting with Eclipse. Currently this only provides whitespace changes, but Eclipse itself also has Clean Up
which makes code changes. I think this functionality is provided by the org.eclipse.jdt:org.eclipse.jdt.ui
package. Would it be possible to also add this functionality to Spotless?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Clean Ups - Eclipse Help
This extension point allows to add clean ups that can solve problems in a compilation unit. Configuration Markup: <!ELEMENT extension (cleanUp* , ...
Read more >Java code cleanup using eclipse
Select Project and Profile and click “Finish”. Now you know how to clean up your code with the help of Eclipse. I have...
Read more >How to run eclipse in clean mode? what happens if we do so?
Edit the eclipse.ini file located in your Eclipse install directory and insert -clean as the first line. · Or edit the shortcut you...
Read more >Automatically format and cleanup code every time you save
When you enabled the option “Additional actions”, you told Eclipse to do more cleanups. You can see what they are and what you...
Read more >How to make Eclipse clean up & format your code for you
Clean Up itself improves code by adding missing annotations, removing unused imports, declaring variables final if they can be final, etc., but ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 from me as well! This would really take Spotless to the next level!
@HoldYourWaffle You should read the Spotless contribution guide first.
The Eclipse formatter is part of the
_ext
.We obtain the Eclispe JDT parts from MavenCentral. I expect Clean-Up to be part of the JDT core code, so the current setup of the spotless-eclipse-jdt should be sufficient for this task.
I always use Eclipse for coding, but since you don’t need to care about the Eclipse plugins and the OSGI layer, InelliJ should also work fine. Since MavenCentral also provides the Java source bundles for JDT, debugging your code should not be problematic. Please have a look at the existing tests. Try to run them in your IDE and step down to the Eclipse code.
All Spotless Eclipse formatter basically just do the following:
Don’t worry too much about the underlying Eclipse framework. I think the the current SpotlessEclipseFramwork setup should be sufficient. Eclipse uses OSGI and JDT is just a plugin. Since we don’t want the full Eclipse environment, our framework just stubs out most of the Eclipse framework functionality.
So in the end you just have to find the JDT method for the clean-up and how to configure it. Add the configuration to the
EclipseJdtFormatterStepImpl
constructor and an additional call to theformat
method. Please add some unit tests. Most Eclipse formatters look quite similar. This CSS Clean-UP example might give you a hint, what you should look for.Afterwards we can talk about remaining issues (documentation, default configuration, …). As Ned pointed out, not all clean-up functionality can work with Spotless, since Spotless only knows the content of a single file and not the project structure. Hence some configuration option must be suppressed.