Prevent Eclipse from (re)moving import comments

I've seen a few bug reports similar to this one, but I was wondering if there was a definitive answer to this other than disabling Ctrl+Shift+O.

When you organize imports, all line comments get pushed to the bottom.

Is there any way to either fix this so line comments travel with the import, or to change (or re-code) the functionality of organize imports?

EDIT: Or, on the flip side, is there a way to get eclipse to organize imports automatically when the project is refreshed?

To solve the XY problem: I have some Java that is pre-processed into separate projects, and some of the code has unused+unresolved imports that the pre-processing can't easily (efficiently) detect/remove. The projects are refreshed after the code is added to them.

This ends up producing several thousand errors for unresolved imports. Yes, I can go through each project and do organize imports for each source folder, but I'd much rather have things done automatically if at all possible.

Upvotes: 0

Views: 187

Answers (1)

Bananeweizen
Bananeweizen

Reputation: 22070

If you are doing that project splitting by means of a self developed Eclipse plugin, then it might be an alternative to also generate the necessary settings for the "Clean up" action in the generated projects settings (E.g. configure the Clean up action for one of your projects and then have a look at .settings/org.eclipse.jdt.ui.prefs). You could then programmatically invoke the Cleanup action doing it similar to what org.eclipse.jdt.internal.ui.actions.AllCleanUpsAction does.

Benefit: If you do it this way, you not only can organize the imports, but can also apply all kinds of other automatic formattings.

Upvotes: 2

Related Questions