Eclipse Optimize Imports to Include Static Imports

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);

hit Ctrl + Shift + O and have Eclipse add:

import static org.junit.Assert.assertEquals;

Maybe I'm asking too much.


I'm using Eclipse Europa, which also has the Favorite preference section:

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.*

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.


如果突出显示方法Assert.assertEquals(val1, val2)并按Ctrl + Shift + M(添加导入),它会将其添加为静态导入,至少在Eclipse 3.4中。


Eclipse 3.4 has a Favourites section under Window->Preferences->Java->Editor->Content Assist

If you use org.junit.Assert a lot, you might find some value to adding it there.

链接地址: http://www.djcxy.com/p/49352.html

上一篇: Android studio中的代码格式化快捷方式

下一篇: Eclipse优化导入以包含静态导入