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

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

问题描述

在Eclipse中,使用Java编写并按 Ctrl + Shift + O 自动导入所有类。有没有办法在IntelliJ上执行此操作?



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



注意右侧的完全限定名称。当我选择一个我想要的,并按回车,IDEA将自动添加import语句。如果我正在输入构造函数的名称,它的工作方式相同。对于静态方法,您甚至可以直接输入所需的方法。在下面的截图中,没有导入StringUtils类。





或者,键入类名,然后点击 Alt + 输入 + 输入< kbd>到显示意图操作和快速修复,然后选择导入选项。



虽然我从未使用过,认为 Eclipse代码格式化程序第三方插件将会做什么你要。它列出了模拟Eclipse的导入优化功能。有关详细信息,请参阅说明。但是最后,我怀疑你会发现内置的IDEA功能在你使用它们的范例后工作得很好。一般来说,IDEA使用以意图发展的概念。所以我打开我的开发工作来添加一个import语句,只需键入我想要的类(我的意图),IDEA会为我自动添加类的import语句。


In Eclipse, while coding in Java and press Ctrl + Shift + O auto import all the Classes automatically. Is any way to do this on IntelliJ?

I searched an equivalent shortcut in google, StackOverflow, IntelliJ 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.

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

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