如何让 Netbeans 在自动完成时使用 import 语句而不是完全限定的类名?

2021-12-26 00:00:00 php netbeans


我最近从 PDT 转移到 Netbeans,有些事情我想不通.如何让 IDE 在自动完成类名的文件开头使用use"语句?喜欢:


I've moved from PDT to Netbeans recently, and there is something I can't figure out. How do I get the IDE to use 'use' statements at the beginning of a file on autocompleting class names? Like:

use FooBarBaz;

class Something extends Baz { /* ... */ }

相反,如果我使用自动完成功能,我会得到

Instead, if I use autocompletion I get

class Something extends FooBarBaz { /* ... */ }

我已经检查了代码完成设置,但最有希望的选项(智能)希望我首先编写导入,以便对短类名称使用自动完成功能.PDT 能够将该行写入文件的开头.

I've checked the code completion settings, but the most promising option (smart) wanted me to first write the imports in order to use autocompletion for short class names. PDT was capable writing that line to the beginning of the file.

推荐答案

在较新版本的 Netbeans(即 7.3+)中,您可以按 Ctrl+Shift+I (Alt+Shift+I 不会按预期工作.

In newer versions of Netbeans (i.e. 7.3+), you can press Ctrl+Shift+I (Alt+Shift+I won't work as expected, though).

首先,它会在您的文件中搜索任何智能或完全限定的实例,然后询问您找到的实例应该是什么类型.然后,它将完全限定的 use 语句添加到您的文件顶部,并将源中的现有实例更改为非限定.

First, it searches for any smart or fully qualified instances in your file and then asks you of what types the found ones should be. It then adds fully qualified use statements to the top of your file and changes existing instances in the source to unqualified.

相关文章