Mass import optimization

I love Intellij but ONE thing drives me crazy. Lately I've been doing major refactoring and doing large search/replace operations on my code. Of course, this can result in imports not being valid anymore. I can't figure out any way to add the proper imports en masse. I have to open each file one by one and add the imports by hand (waiting for the import popups). This can take FOREVER. Is there any way to do this faster?

Thanks in advance,

Curtis

7 comments
Comment actions Permalink

Settings | Editor | Auto Imports - Add unambiguous imports on the fly

You will still have to open each file, but IDEA usually will fill in the majority of the imports on its own.

0
Comment actions Permalink

Yes, thank you, I have that set. Still can take a long time.

0
Comment actions Permalink

On Fri, 10 Jun 2011 02:11:57 MSD, Curtis Stanford
<no_reply@jetbrains.com> wrote, quoted or indirectly quoted someone
who said :

>I love Intellij but ONE thing drives me crazy. Lately I've been doing major refactoring and doing large search/replace operations on my code. Of course, this can result in imports not being valid anymore. I can't figure out any way to add the proper imports en masse

The code reformatter has an option to tidy (correct) the imports. The
problem with it is it tosses imports unless there are references to
them.  You need compiled code to be use all the references are
present.

One technique I use to get around that is to create a giant global set
of imports. Paste them in, and let Reformat prune out what is not
needed. Reformat can be run on multiple modules at once.
--
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who
understands computers don't work without regular backups.

0
Comment actions Permalink

Nice  suggestion, thanks!

0
Comment actions Permalink

Hi Curtis,

There are 'rename' and 'move' refactorings that take care of all of the aspects, including imports adjustments. Am I right understanding that you didn't use them but performed raw text search/replace instead?

Denis

0
Comment actions Permalink

That's right. I try to use the refactorings as much as I can but it doesn't work in all situations. For example, if I add a new class or method and want to change the users of the old class to use the new class (the old class is still around).

0
Comment actions Permalink

For that particular case, have a look at Refactor -> Migrate...

That's right. I try to use the refactorings as much as I can but it
doesn't work in all situations. For example, if I add a new class or
method and want to change the users of the old class to use the new
class (the old class is still around).

---
Original message URL:
http://devnet.jetbrains.net/message/5306176#5306176



0

Please sign in to leave a comment.