Embed all static imports in eclipse

I cleared some code and happened after com.example.StringHelperthat contained 6 or 7 public staticmethods (for example concatStrings(String...), but there were no member fields). There were several classes, subclass this class, so that they can cause concatStrings(str1, str2)no prefix it with the following class: StringHelper.concatStrings(str1, str2).

I didn’t want them to subclass the class for this very reason, so I broke the bunch. I inserted the following static import at the beginning of any file, subclassing it after deletion extends StringHelper:

import static com.example.StringHelper.*;

Eclipse has simplified this in specific imports for the methods used only.

Question : Is there an easy way to get Eclipse to "embed" this static import? Can I make it remove the actual static import and prefix for each call using StringHelper.instead?

Note This is a simplified, far-fetched example, so please do not complain about why we need StringHelper.

+3
source share
4 answers

This will be done:

  • Highlight one call to concatStrings (). Remember to include parentheses in the selection. Select the Refactor / Extract method, name it foo. Be sure to check "Replace 47 additional occurrences of statements using the method"
  • foo "StringHelper". prefix concatStrings
  • Refactor/Inline, foo , , .
+4

, , . , . ctrl-1 , , .

+1
Preferences -> Java -> Code Style -> Organize Imports

, .

0

> Java > a > :

" . *" 1.

0

Source: https://habr.com/ru/post/1775729/


All Articles