0

I have a requirement to refactor nearly 5000 java classes in such a way that, its import statements need to be modified. Doing it manually by opening in Eclipse will take months time. So we need to automate it.

I have a piece of code to remove all the import statements from the class file, now I need to add the fresh imports by some way. Please share your thoughts and inputs.

I do have a new set of jars, from which classes will be used to organize the imports.

I have conflicts with multiple class files. Like classes with same name is there in different Utility packages. So user intervention is required most of the cases so that I can select the appropriate classes which need to be imported.

Let me know if there is any other way than the above one :)

goosebump
  • 96
  • 1
  • 2
  • 13
  • In eclipse theres a shortcut Ctrl + Shift + O to add the imports, right? If you do it programmatically how would you know which class to import? – Sweeper Aug 05 '15 at 06:49
  • Since user interaction is required eclipse's organize import is not effective:(. And I can handle the user interaction through an "if else" code if there is any program for organize imports. – goosebump Aug 05 '15 at 06:54
  • possible duplicate of [Can you organize imports for an entire project in eclipse with a keystroke?](http://stackoverflow.com/questions/403569/can-you-organize-imports-for-an-entire-project-in-eclipse-with-a-keystroke) – Lesmana Aug 05 '15 at 07:07
  • whats problem with ctrl+shift+o ? – VedantK Aug 05 '15 at 08:04
  • I have conflicts with multiple class files. Like classes with same name is there in different Utility packages. So user intervention is required most of the cases. – goosebump Aug 05 '15 at 08:40

1 Answers1

0

As Sweeper says, you can right-click on the source-folder, tipically src/main/java, and then Source > Organize Imports. This will remove the unused imports and add the ones required. User interaction is going to be needed, because if several classes were to conflict, you will have to choose the one you want.

carcaret
  • 3,238
  • 2
  • 19
  • 37