在Eclipse中自动导入IntelliJ IDEA中的类的任何方式(或快捷方式)? [英] Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse?

查看:229
本文介绍了在Eclipse中自动导入IntelliJ IDEA中的类的任何方式(或快捷方式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中,用Java编码并按 Ctrl + Shift + O 自动导入所有类。

在NetBeans中,这是通过 Ctrl + Shift + I 完成的。



有没有办法在IntelliJ IDEA中执行此操作?



我搜索了google,StackOverflow,IntelliJ IDEA配置和官方IntelliJ网站中的等效快捷方式



注意右侧的完全限定名称。当我选择我想要的并按Enter键时,IDEA将自动添加import语句。如果我输入构造函数的名称,这也是一样的。对于静态方法,您甚至可以继续键入所需的方法。在下面的屏幕截图中,尚未导入StringUtils类。





或者,键入类名,然后按 Alt + Enter + Enter to显示意图操作和快速修复,然后选择导入选项。



虽然我从未使用它,但我 Eclipse Code Formatter 第三方插件会做什么你要。它列出了模拟Eclipse的导入优化作为功能。有关详细信息,请参阅其说明。但最后,我怀疑一旦你习惯了他们的范例,你会发现内置的IDEA功能正常工作。一般而言,IDEA使用按意图发展的概念。因此,我只是输入我想要的类(我的意图)而不是打断我的开发工作来添加导入语句,而IDEA会自动为我添加类的import语句。


In Eclipse, while coding in Java and press Ctrl + Shift + O auto import all the Classes automatically.
In NetBeans, this is done with Ctrl + Shift + I.

Is any way to do this in IntelliJ IDEA?

I searched an equivalent shortcut in google, StackOverflow, IntelliJ IDEA configuration and in the official IntelliJ website Keyboard Shortcuts You Cannot Miss

解决方案

IntelliJ IDEA does not have an action to add imports. Rather it has the ability to do such as you type. If you enable the "Add unambiguous imports on the fly" in Settings > Editor > General > Auto Import, IntelliJ IDEA will add them as you type without the need for any shortcuts. You can also add classes and packages to exclude from auto importing to make a class you use heavily, that clashes with other classes of the same name, unambiguous.

For classes that are ambiguous (or is you prefer to have the "Add unambiguous imports on the fly" option turned off), just type the name of the class (just the name is OK, no need to fully qualify). Use code completion and select the particular class you want:

Notice the fully qualified names to the right. When I select the one I want and hit enter, IDEA will automatically add the import statement. This works the same if I was typing the name of a constructor. For static methods, you can even just keep typing the method you want. In the following screenshot, no "StringUtils" class is imported yet.

Alternatively, type the class name and then hit Alt+Enter or +Enter to "Show intention actions and quick-fixes" and then select the import option.

Although I've never used it, I think the Eclipse Code Formatter third party plug-in will do what you want. It lists "emulates Eclipse's imports optimizing" as a feature. See its instructions for more information. But in the end, I suspect you'll find the built in IDEA features work fine once you get use to their paradigm. In general, IDEA uses a "develop by intentions" concept. So rather than interrupting my development work to add an import statement, I just type the class I want (my intention) and IDEA automatically adds the import statement for the class for me.

这篇关于在Eclipse中自动导入IntelliJ IDEA中的类的任何方式(或快捷方式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆