Eclipse 优化导入以包含静态导入 [英] Eclipse Optimize Imports to Include Static Imports
问题描述
有没有办法让 Eclipse 自动查找静态导入?例如,现在我终于升级到 Junit 4,我希望能够写:
Is there anyway to get Eclipse to automatically look for static imports? For example, now that I've finally upgraded to Junit 4, I'd like to be able to write:
assertEquals(expectedValue, actualValue);
点击 Ctrl + Shift + O 并让 Eclipse 添加:
hit Ctrl + Shift + O and have Eclipse add:
import static org.junit.Assert.assertEquals;
也许我要求太多了.
推荐答案
我正在使用 Eclipse Europa,它也有收藏夹"首选项部分:
I'm using Eclipse Europa, which also has the Favorite preference section:
窗口 > 首选项 > Java > 编辑器 > 内容辅助 > 收藏夹
Window > Preferences > Java > Editor > Content Assist > Favorites
在我的中,我有以下条目(添加时,使用新类型"并省略 .*
):
In mine, I have the following entries (when adding, use "New Type" and omit the .*
):
org.hamcrest.Matchers.*
org.hamcrest.CoreMatchers.*
org.junit.*
org.junit.Assert.*
org.junit.Assume.*
org.junit.matchers.JUnitMatchers.*
除了第三个之外,其他都是静态导入.通过将这些作为收藏夹,如果我输入assertT
"并点击 Ctrl+Space,Eclipse 将提供 assertThat
作为建议,如果我选择它,它会将正确的静态导入添加到文件中.
All but the third of those are static imports. By having those as favorites, if I type "assertT
" and hit Ctrl+Space, Eclipse offers up assertThat
as a suggestion, and if I pick it, it will add the proper static import to the file.
这篇关于Eclipse 优化导入以包含静态导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!