7

TL;DR: Is there a preference setting for Eclipse Juno for "leave static imports the hell alone"?

Nearly all of our developers who are using Eclipse have Organize Imports in the list of their Save Actions. Which is fine, and quite useful.

The trouble is with static imports. Our project needs to have its static imports managed carefully, so we'd strongly prefer to have them listed explicitly:

import static thing.foo;
import static thing.bar;
import static thing.baz;

Unfortunately, depending on the threshold number in Organize Imports "Number of static imports needed for .*", this block occasionally gets collapsed into

import static thing.*;

Cranking the threshold up to a large number leaves the list of statics alone... as long as the Eclipse editor thinks that there's a reference to that static present. Then we get scenarios like this, to pick the simplest example:

  1. Developer makes a typo in code completely unrelated to the statically imported symbols, presses Save, tries to build.
  2. Eclipse gets a parse error.
  3. Developer fixes part of broken code, presses Save.
  4. Eclipse no longer has its list of static references because of failed build, so the Save Actions helpfully removes the "unused" static imports.
  5. Developer finishes fixes, presses Save, tries to build.
  6. Eclipse gets new errors due to all these now-unknown symbols.
  7. Developer rages at Eclipse, blows off steam complaining to other developers.

Go through the cycle enough times over the months, and eventually we arrive at step 8, Senior developer gives up hacking at Eclipse's code and posts on SO.

There are SO questions like this one which mention the problem as an aside, but nothing else.

Is there some magic combination of preferences or build settings that tells Eclipse to keep doing its thing for normal imports, but just stop flailing around at managing the static imports?

Community
  • 1
  • 1
Ti Strga
  • 1,353
  • 18
  • 40
  • 3
    8. Developer switches to IntelliJ. – bmargulies Jan 24 '14 at 18:25
  • 8. write your own organize imports save action that ignores static imports. – SpaceTrucker Jan 24 '14 at 18:33
  • Preferences -> Java -> Editor -> Content Assist -> Favorites helps you to correct this error. But this still requires manual correction. If you have that much of static imports, I would consider this to be a code smell. – SpaceTrucker Jan 24 '14 at 18:36
  • @SpaceTrucker It's not that we have very many imports, sometimes only 2 or 3 (but sometimes more). The problem is that Eclipse removes them given the least provocation, and then we have to put them all back in by hand, every time. As for the other, nobody here has time to write our own Eclipse plugins to fix Eclipse bugs. – Ti Strga Jan 24 '14 at 18:39
  • @bmargulies heh, maybe so. Right now, our senior developers don't use IDEs, precisely *because* of things like this. Maybe the latest IDEA release will be shiny enough to convince them to chang! – Ti Strga Jan 24 '14 at 18:42

0 Answers0