有什么方法(或快捷方式)可以像在 Eclipse 中一样在 IntelliJ IDEA 中自动导入类? [英] Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse?

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

问题描述

在 Eclipse 中,在 Java 中编码并按 Ctrl + Shift + O 自动导入所有类.
在 NetBeans 中,这是通过 Ctrl + Shift + I 完成的.

在 IntelliJ IDEA 中有没有办法做到这一点?

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

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

或者,输入班级名称,然后按 Alt+Enter+Enter以显示意图操作和快速修复",然后选择导入选项.

虽然我从未使用过它,但我认为Eclipse Code Formatter 第三方插件可以满足您的需求.它将模拟 Eclipse 的导入优化"列为一项功能.有关详细信息,请参阅其说明.但最后,我怀疑一旦您习惯了它们的范例,您会发现内置的 IDEA 功能可以正常工作.一般来说,IDEA 使用用意图开发"的概念.因此,与其中断我的开发工作来添加导入语句,我只需键入我想要的类(我的意图),IDEA 就会自动为我添加该类的导入语句.

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天全站免登陆