Reputation: 5402
I was cleaning up some code and happened upon com.example.StringHelper
that contained 6 or 7 public static
methods (for example concatStrings(String...)
, but no member fields. There were a number of classes subclassing this class just so they could call concatStrings(str1, str2)
without prefixing it with the class like so: StringHelper.concatStrings(str1, str2)
.
I didn't want them subclassing a class just for that reason, so I broke a bunch off. I pasted the following static import into the top of any file subclassing it after removing the extends StringHelper
:
import static com.example.StringHelper.*;
Eclipse simplified this into specific imports for only the methods being used.
Question: Is there a simple way to have Eclipse "inline" these static imports? Can I get it to remove the actual static import and prefix every call with StringHelper.
instead?
Note This is a simplified contrived example, so please don't complain about why we need a StringHelper in the first place.
Upvotes: 3
Views: 2362
Reputation: 1
Preferences > Java > Code Style > Organize Imports:
"Number of static imports needed for .*" set this to 1.
Upvotes: 0
Reputation: 1013
This will do it:
Upvotes: 4
Reputation: 22435
Preferences -> Java -> Code Style -> Organize Imports
There you can configure how many imports will be required to group them.
Upvotes: 0
Reputation: 51860
Don't know if there's an automatic way, but I think it can help in a manual way. Delete the import, then click on each line with an error on it. Press ctrl-1 for 'quick fix' and choose the quick fix that prefixes the package name rather than add an import.
Upvotes: 1