Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

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.

1 Answer

0 votes
by (46k points)

I'm applying Eclipse Europa, which also has the Favorite decision section:

Window > Preferences > Java > Editor > Content Assist > Favorites

I have the subsequent entries (when combining, use "New Type" and omit the .*):

org.hamcrest.Matchers.*

org.hamcrest.CoreMatchers.*

org.junit.*

org.junit.Assert.*

org.junit.Assume.*

org.junit.matchers.JUnitMatcher.*

All but the third of these are static imports. By holding those as favorites, if I type "assertT" and hit Ctrl+Space, Eclipse allows up assertThat as a recommendation, and if I choose it, it will add the precise static import to the file.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 7, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...