简体   繁体   English

如何以不区分大小写的顺序对 Eclipse 中的导入语句进行排序?

[英]How to sort import statements in Eclipse in case insensitive order?

Eclipse sorts import statements within the import groups using lexicographical order, which is case sensitive. Eclipse 使用区分大小写的字典顺序对导入组中的导入语句进行排序。

For example:例如:

import com.company.something.DBException;
import com.company.something.DatabaseHandler;

Is it possible to change that automatic sorting to be case insensitive.是否可以将自动排序更改为不区分大小写。 In the above example, I'd like the order to be:在上面的例子中,我希望顺序是:

import com.company.something.DatabaseHandler;
import com.company.something.DBException;

I found a way to do it: first, there in the Window > Preferences > Java > Code Style > Organize Imports option, delete all the entries that indicate specific packages order:我找到了一种方法:首先,在Window > Preferences > Java > Code Style > Organize Imports选项中,删除所有指示特定包顺序的条目:

删除自定义包条目

And then enter one single entry with only a * character.然后输入一个只有*字符的条目。

添加*单项

Apparently, this indicates you don't want to specify any custom order and then Eclipse decides the order method, which by default seems to be lexicographical.显然,这表明您不想指定任何自定义顺序,然后 Eclipse 决定顺序方法,默认情况下似乎是字典顺序的。

That's it.而已。 Next time you execute the Source > Organize Imports command or the CTRL + SIFT + O shortcut, the order will be lexicographical.下次执行Source > Organize Imports命令或CTRL + SIFT + O快捷键时,顺序将按字典顺序排列。

The import organisation behaviour in Eclipse can be controlled in Preferences -> Java -> Code Style -> Organize Imports . Eclipse 中的导入组织行为可以在Preferences -> Java -> Code Style -> Organize Imports中控制。 Unfortunately, there does not appear to be a way of changing the order the way you like.不幸的是,似乎没有办法按照您喜欢的方式更改顺序。

The AnyEdit Eclipse plugin adds various editing tools to the context menu - including case-insensitive sorting of lines of text. AnyEdit Eclipse 插件将各种编辑工具添加到上下文菜单 - 包括不区分大小写的文本行排序。 Select your imports, right click, choose Sort, case-insensitive.选择您的导入,右键单击,选择排序,不区分大小写。

Not sure how you would automate it, but it's got to be better than manual.不确定如何使它自动化,但它必须比手动更好。

"Current version works with Eclipse from 3.8 to 4.6 and requires Java = 1.7, but older AnyEdit versions for Eclipse 2.1 up to 3.7 may be downloaded from the homepage too." “当前版本适用于 3.8 到 4.6 的 Eclipse,需要 Java = 1.7,但也可以从主页下载适用于 Eclipse 2.1 到 3.7 的旧 AnyEdit 版本。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PagingAndSortingRepository 如何排序不区分大小写? - PagingAndSortingRepository how to sort case insensitive? 使用命令CASE_INSENSITIVE_ORDER按键对TreeMap进行排序 - Sort TreeMap by key using order CASE_INSENSITIVE_ORDER 如何在 Linux 系统上按字典顺序(不区分大小写)对文件\目录树进行排序 - How to sort file\directory tree in lexicographic order (case-insensitive) on Linux system 如何以字母数字顺序对番石榴多图(键和值)进行排序(不区分大小写) - How to sort the guava multimap(both key and value) in alphanumeric order(case insensitive) lucene 不区分大小写的排序搜索 - lucene case Insensitive sort search 如何使用Spring Data Rest对不区分大小写的数据进行排序? - How can I Sort data Case insensitive with Spring Data Rest? CursorLoader-SQL中的排序不区分大小写 - CursorLoader - order by in SQL is case insensitive 如何在不区分大小写的字母顺序的Android上创建文件列表? - How to create a file list on Android with alphabetical case insensitive order? 如何以相反的顺序排列字符串集合,并且必须不区分大小写 - How to arrange the string collection in reverse order and it must be case insensitive 澄清-Eclipse中的导入语句 - Clarification - Import statements in Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM