views:

66

answers:

2

Is there a way to tell IntelliJ never to use wildcard imports? Under 'Settings > Code Style > Imports', I can see that you can specify the 'class count' prior to IntelliJ using wildcard imports. However, if I never want to use wildcard imports can I turn this functionality off?

I have tried putting -1 or leaving the field blank but that just tells IntelliJ to always use wildcard imports. Obviously a not-so-nice solution would be to put a ridiculously high number so that you never encounter wildcard imports but I was hoping there was a nicer way to just turn it off.

A: 

Why would you want to disable this functionality? I can see why they've not permitted it to be disabled - however, setting it ridiculously high as you suggest seems a reasonable workaround if you need to do this.

Will A
Because I don't want to use wildcard imports for clarity reasons and why import an entire package when you're only using one class in that package? - here's some more info if you like: http://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad
digiarnie
Fair reference - the jury does seem to be out on that one, although there's an obvious vote skew to the anti- * imports post. :)
Will A
Each to their own :)
digiarnie
They do permit it to be disabled. And it need not be ridiculously high, unless you consider 10 to be a ridiculous number.
duffymo
+2  A: 

It's obvious why you'd want to disable this: to force IntelliJ to include each and every import individually. It makes it easier for people to figure out exactly where classes you're using come from.

Click on the Settings "wrench" icon on the toolbar, open "Imports" under "Code Style", and check the "Use single class import" selection. You can also completely remove entries under "Packages to use import with *", or specify a threshold value that only uses the "*" when the individual classes from a package exceeds that threshold.

duffymo
Prior to me putting the high number for the threshold, I had the settings set up like you said already but it still put in the wild card imports (i.e. I had "use single class import" checked and removed all packages in the "packages to use import with *"...
digiarnie
Working for me. Let me see what else I might have set. Version 9.0.3 for me.
duffymo
What value do you have as the threshold for class count before * is used? I'm on 9.0.1 - might have to do an upgrade.
digiarnie
No, the upgrade won't be necessary. It always worked for me back to version 5. I have "10" as the class count to use with import '*'
duffymo
So if you do 11 imports of classes from the same package the wild card import doesn't kick in? As a test, I have my threshold set to 2. If I import something from org.hibernate let's say, it will put the import correctly (fully qualified). As soon as I import something else from org.hibernate it will stick in the wild card import, which kind of tells me either my version of intellij doesn't behave like yours or the only solution is to put a high threshold so I never run into this issue
digiarnie