question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Eclipse Clean Up

See original GitHub issue

From 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:open
  • Created 5 years ago
  • Reactions:6
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bwRavenclcommented, Dec 17, 2020

+1 from me as well! This would really take Spotless to the next level!

1reaction
fvghcommented, Dec 8, 2018

@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 the format 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found