Why is Eclipse Content Assist not using static imports
Asked Answered
F

3

7

I'm trying to use JUnit and Mockito with content assist for static imports.

My Content Assist favorites lists: org.mockito.Mockito.*

When I use content assist for the mock() method, the method is availble, but the import is just get a regular non-static import. Why is this not working?

Fortitude answered 18/1, 2012 at 15:29 Comment(1)
Interested in knowing this too. Sometimes happens to me with Assert imports too (but not always).Neruda
S
6

Eclipse won't look for static imports unless you tell it to. From the Eclipse Java Content Assist Favorites Preferences help page:

To see the static import proposals, make sure Use static imports is enabled on the Content Assist preference page

Admittedly, on my machine it was enabled by default.

Structural answered 26/1, 2012 at 15:3 Comment(0)
M
1

With the Eclipse of 8 years later (Eclipse 2019-12 (4.14.0)), two things are needed:

  1. Window, Preferences, Java, Editor, Content Assist, make sure that the ckeckbox "Use static imports" is ticked.

  2. ..., Content Assist, Favorites, add (if not already there) the types (e.g. org.apache.commons.lang3.StringUtils) or members (e.g. org.apache.commons.lang3.StringUtils.EMPTY) to the Favorites list, otherwise Content Assist won't propose to static-import those.

Mcshane answered 30/5, 2020 at 9:48 Comment(0)
A
0

I'm just getting started with Eclipse, but ran into this issue with the tutorial. I spend a couple of hours trying to figure out what was wrong, when I invoked the content assist with ctrl+O, rather than using hover. The static members were then displayed correctly.

Arbitress answered 23/5, 2015 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.