Optimize Imports when copying from filesystem or eclipse
已回答
Let's assume I copy code from the filesystem or directly from eclipse.
The current package name is 'com.my.eclipse.project' I copy everything beneath that package and in IntelliJ I paste it into 'com.my.intellij.project'. After doing that I get several compile errors because the Imports are broken (they still point to 'com.my.eclipse.project'. What can I do to fix these Imports. As a long time eclipse user I tried to optimize the Imports in IntelliJ but that didn't work.
I need help.
I think this feature is there and I just don't know where to find it...
请先登录再写评论。
You can copy the files into the folder corresponding to com.my.eclipse.project package and then use Refactor | Move on the classes to move them into com.my.intellij.project package. IntelliJ IDEA will update all the imports and package statements automatically.
Hey Serge,
well you're right that would work.
But that isn't really intuitiv. I would expect my IDE to do this for me.
I would love to see this in IntelliJ because this is one of the last things that I miss after switching over from eclipse.
You can also try running Analyze | Inspect Code with the wrong package statement inspection and apply the quick fix to change the package statement. But this will not fix the imports as there is no easy way to automate it. Replace in Path may help, but as suggested before, Refactor | Move is much more appropriate and natural.