Java 禁用 IntelliJ 加星标(包)导入?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3587071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 02:12:42  来源:igfitidea点击:

Disable IntelliJ Starred (Package) Imports?

javaautocompleteintellij-idea

提问by Iain Samuel McLean Elder

I'm a migrating Eclipse IDE user and am learning my way round IntelliJ IDEA 9.

我是一名正在迁移的 Eclipse IDE 用户,并且正在学习如何绕过 IntelliJ IDEA 9。

By default Eclipse IDE won't use a starred import until you import 99 classes from the same package, so it practically never happens.

默认情况下,Eclipse IDE 在您从同一个包中导入 99 个类之前不会使用带星号的导入,因此它实际上从未发生过。

But IntelliJ IDEA seems only too keen to do it, and I can't work out how to disable it.

但是 IntelliJ IDEA 似乎太热衷于这样做了,我不知道如何禁用它。

For example, after typing JListthen ALT+ ENTERto auto-import, the whole javax.swingpackage is imported instead of just the class I specify.

例如,在键入JListthen ALT+ENTER以自动导入后,将导入整个javax.swing包,而不仅仅是我指定的类。

I tried excluding javax.swingfrom the auto-completion, but that just stops anySwing classes from being suggested, which is counter-productive.

我尝试javax.swing从自动完成中排除,但这只会阻止建议任何Swing 类,这会适得其反。

采纳答案by Colin Hebert

You can set this setting here.

您可以在此处设置此设置。

In IDEA 14+ the sequence is:

IDEA 14+ 中,序列是:

Settings> Editor> Code Style> Java> Imports> Class count to use import with '*'

Settings> Editor> Code Style> Java> Imports>Class count to use import with '*'

In older version of IDEA:

在旧版本的 IDEA 中:

Settings-> Java-> Code Style-> Imports-> Class count to use import with '*'

Settings-> Java-> Code Style-> Imports->Class count to use import with '*'

The feature can not be disabled. You need to set it to a high value, e.g. 99.

该功能无法禁用。您需要将其设置为一个较高的值,例如 99。

In 2016.1.1 version You should also remove the lines under Packages to Use Import with '*', e.g. import javax.*;

在 2016.1.1 版本中,您还应该删除 下的行Packages to Use Import with '*',例如import javax.*;

回答by ROMANIA_engineer

IntelliJ IDEA:

智能想法:

  • 14& 15& 16 EAP

    File > Settings... > Editor > Code Style > Java > Imports> in Generalarea add a big number for Class count to use import with '*':/ Names count to use static import with '*':

    File >Settings... >Editor >Code Style >Java >Imports >General >Class count to use import with '*'

  • 14& 15& 16 EAP

    File > Settings... > Editor > Code Style > Java > Imports> 在General区域中为Class count to use import with '*':/添加一个大数字Names count to use static import with '*':

    File >Settings... >Editor >Code Style >Java >Imports >General >Class count to use import with '*'

IntelliJ IDEA:

智能想法:

  • 12& 13

    File > Settings... > Code Style > Java > Imports> in Generalarea add a big number for Class count to use import with '*':File >Settings... >Code Style >Java >Imports >General >Class count to use import with '*'

    P.S.: Javais after Code Stylein the path.

  • 12& 13

    File > Settings... > Code Style > Java > Imports> 在General区域中添加一个大数字Class count to use import with '*':文件 >设置... >代码样式 >Java >导入 >常规 >类计数以使用带有 '*' 的导入

    PS:Java是经过Code Style的路径。

回答by user3573712

And you also have to remove package names from the "Packages to use import with *" list box just below the "Class count to use import with " text boxes. Swing and AWT are there by default I think. I still was having import javax.swing.; added even though I had the class count set to 999. I used the minus sign button to remove Swing and Awt from the box and then it worked.

并且您还必须从“使用*导入的包”列表框中删除包名称,该列表框位于“使用导入的类计数”文本框下方我认为 Swing 和 AWT 是默认存在的。我仍然在导入 javax.swing。; 添加了即使我将班级计数设置为 999。我使用减号按钮从框中删除 Swing 和 Awt,然后它起作用了。