Eclipse Optimize Imports to Include Static Imports
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.
Eclipse optimize imports to include static members and methods
Did you have a look at Preferences > Java > Editor > Content Assist > Favorites? You can define candidates for static imports there. Result:
For less used classes you can lower the value of Preferences > Java > Code Style > Organize Imports > Number of static imports needed for .*
but beware that you may get .*
for classes that contain generically named methods such as getInstance
. This in turn may lead to confusion and/or naming conflicts.
Is it possible to change the order of static imports followed by imports in eclipse?
You can configure the order of imports in the Preferences in the 'Java > Code Style > Organize Imports' page. This will allow you to specify the order of static and normal imports (and a lot more if you want).
Related Topics
How to Return JSON Data from Spring Controller Using @Responsebody
In Java, What Are the Boolean "Order of Operations"
Should You Always Code to Interfaces in Java
Spring Configure @Responsebody JSON Format
What's the Default Value of Char
How to Set Java_Home in MAC Permanently
String.Format() to Format Double in Java
Accessing the Last Entry in a Map
How to View Tomcat Log Files in Eclipse
Comparing Time Is Incorrect When Picking 12:00
Maven: How to Change Path to Target Directory from Command Line
Visual Studio Code, Java Extension, How to Add a Jar to Classpath
How to Get Client Information Such as Os and Browser
How to Stop Selenium from Creating Temporary Firefox Profiles Using Web Driver