Optimize imports on the fly

When is "Optimize imports on the fly" supposed to work? On 2013 it
doesn't seem to trigger on using Alt+Enter to add an import.

Thanks,
Jon

14 comments
Comment actions Permalink

This feature is supposed to remove unused import statements while you are typing.

--
regards,
Alexey Kudravtsev
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


"Jon Steelman" <jon@cc.gatech.edu> wrote in message news:c6k0k7$qll$1@is.intellij.net...

When is "Optimize imports on the fly" supposed to work? On 2013 it
doesn't seem to trigger on using Alt+Enter to add an import.

>

Thanks,
Jon



0
Comment actions Permalink

Alexey,
Given the name, I expected it to also reorder any out-of-order imports.
Apparently the logic doesn't reorder pre-existing out-of-order imports
within an Import Layout package (with subpackages) although it does
reorder existing imports that are not in the appropriate Import Layout
section. This is a bug, right?

Alexey Kudravtsev (JetBrains) wrote:

This feature is supposed to remove unused import statements while you are typing.

0
Comment actions Permalink


Because occasionally typing ctrl-O or ctrl-L was too burdensome? As always, I bow to JetBrains exceptional understanding of just how lazy the average Java developer wants to be.

But seriously, great feature. Yet again, you guys find the little ways to stay ahead of the curve.

--Dave Griffith

0
Comment actions Permalink


BTW, there was one big problem with this feature: It didn't appear on any change lists or product roadmap! If I hadn't read John's post, I would never have known about it.

--Dave Griffith

0
Comment actions Permalink

Dave Griffith wrote:

BTW, there was one big problem with this feature: It didn't appear on any change lists or product roadmap! If I hadn't read John's post, I would never have known about it.


I think it was actually included in some of the later Aurora releases as well.

There was a thread in the plugins newsgroup where someone asked what
additional options IDEA would understand, beyond those already in the .lax
file. One of the replies mentioned the "-Doptimize.imports=true" option,
which would turn on that behaviour. Never tried it myself though.

Vil.
--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0
Comment actions Permalink

On 27-04-2004 17:38, Dave Griffith wrote:

BTW, there was one big problem with this feature: It didn't appear on
any change lists or product roadmap! If I hadn't read John's post, I
would never have known about it.


I think that's what they meant by the entry "Editor: inserting imports
in alphabetical order" in the change list. Specifically it was this SCR
that was fixed:
http://www.intellij.net/tracker/idea/viewSCR?publicId=30608

Bas

0
Comment actions Permalink

Although I don't quite understand your complain, please file an SCR, just in case :)

--
regards,
Alexey Kudravtsev
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


"Jon Steelman" <jon@cc.gatech.edu> wrote in message news:c6lta2$cfk$1@is.intellij.net...

Alexey,
Given the name, I expected it to also reorder any out-of-order imports.
Apparently the logic doesn't reorder pre-existing out-of-order imports
within an Import Layout package (with subpackages) although it does
reorder existing imports that are not in the appropriate Import Layout
section. This is a bug, right?

>

Alexey Kudravtsev (JetBrains) wrote:

This feature is supposed to remove unused import statements while you are typing.



0
Comment actions Permalink

It is SCR #32076. Let me know if that doesn't explain it for you and I
can add more.

Alexey Kudravtsev (JetBrains) wrote:

Although I don't quite understand your complain, please file an SCR, just in case :)

0
Comment actions Permalink

Just added a very explicit example of the problem.

Alexey Kudravtsev (JetBrains) wrote:

Although I don't quite understand your complain, please file an SCR, just in case :)

0
Comment actions Permalink

What does "while you are typing" mean? Does it mean when alt-Enter is pressed?

And does it do 2 things?
1. Remove unused imports.
2. Sorts/orders imports according to "Import" tab of "Code Style" (alphabetically, groups etc.)

0
Comment actions Permalink


Because occasionally typing ctrl-O or ctrl-L was too
burdensome? As always, I bow to JetBrains
exceptional understanding of just how lazy the
average Java developer wants to be.


It's not just about being lazy (although, yes..I am lazy). It's about not having to manage the imports. They are unnecessary in most cases.

So have the tool do it. Just like the tool automatically saves the files, rather then having the lazy developer hit ctrl-s

Mike


0
Comment actions Permalink

I would add that I'm not too sure about having imports removed automatically (if that is the case).

For example, if I temporarily comment out code, then I wouldn't want the relevant imports removed, because then I would have to add them back in when I uncomment the code.

So, while sorting etc. imports is good, I would like the ability to enable this but disable removing imports.

0
Comment actions Permalink

I would add that I'm not too sure about having
imports removed automatically (if that is the
case).

For example, if I temporarily comment out code, then
I wouldn't want the relevant imports removed, because
then I would have to add them back in when I
uncomment the code.

So, while sorting etc. imports is good, I would like
the ability to enable this but disable removing
imports.


But the entire idea is that when you comment them back in again, you don't need to do anything (unless it resolves to multiple items on the classpath)

Perhaps within a given session or file IDEA could remember the old imports to avoid having it query you asking whether or not you want java.awt.List or java.util.List.

Or perhaps the algorithm could be a little smarter and somehow infer from context that you don't want the AWT version.

Mike

0
Comment actions Permalink

For example, if I temporarily comment out code...


I filed this SCR yesterday for a related problem:

http://www.intellij.net/tracker/idea/viewSCR?publicId=32326

0

Please sign in to leave a comment.