Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep import * for specific package when organizing imports in Eclipse

Tags:

eclipse

For some imports, I may want to keep a * import even I am currently using only 1-2 classes/methods. For example, I may want to import org.mockito.Mockito.* even I am currently using only a few of them, because when my test grows, I will need to use more static method under Mockito. However Organize Imports function in Eclipse always break down my import to import individual methods (which is the preferred behavior in most case).

Is there a way to let me control such behavior in package basis? i.e. I want to keep importing * for some packages (or disabling auto-break-down feature), but for other packages, I would want to use Eclipse's default behavior (deciding * base on number of classes/methods used)

like image 401
Adrian Shum Avatar asked Aug 28 '15 01:08

Adrian Shum


1 Answers

You can't change the policy for individual imported packages or classes, but you can set the overall threshold lower so that Organize Imports won't convert the wildcard import to individual ones. Go to Preferences > Java > Code Style > Organize Imports and then edit the Number of static imports needed... value to something small, like 2.

enter image description here

With it set to a small number, you can manually add a wildcard import and as long as the class uses at least the threshold number of methods, Eclipse will leave it alone.

like image 135
E-Riz Avatar answered Oct 21 '22 06:10

E-Riz