[英]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.