2

I have a large number of errors in my project because I recently used mac terminal to rename some items.

Therefore it is now requiring me to individually go into each class and import a class.

I am using Eclipse, does it have the ability to do this for me?

Through Eclipse I manually go the class, right click > click import.

Can this be done automatically for 100+ classes in need of the exact same import?

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
kay
  • 451
  • 1
  • 3
  • 13
  • Were you importing that specific class from those files, and the name of that class has changed? – Paulie Mar 29 '18 at 10:09
  • No i was renaming a getter to hashmap.get("key", new Inventory()), where Inventory is the class I now need to import a thousand times – kay Mar 29 '18 at 10:16
  • Try ctrl + shift + o in each class, if you do not have backup of project Or try eclipse quick fix. – Prabhav Mar 29 '18 at 10:17
  • I do have backup, but this is the only option I have in renaming certain items. I need a way to automatically import a class in all classes that need it – kay Mar 29 '18 at 10:19
  • Eclipse will need some human intervention to select the right class which you want to use. So you have no option. crtl +shift + o can reduce time – Prabhav Mar 29 '18 at 10:23
  • https://stackoverflow.com/questions/31211842/any-way-or-shortcut-to-auto-import-the-classes-in-intellij-idea-like-in-eclips – Prabhav Mar 29 '18 at 10:30
  • do you still have the old import line in the files? if so, you can search and replace it with the correct one. and in the future: do a proper refactoring of the name – Neuron Mar 29 '18 at 14:03

1 Answers1

0

Solution 1:

  • Go to every class

  • Press ctrl +shift + o

  • select suitable class

Solution 2:

  • Right click on problems console

  • select quick fix

  • Select suitable class.

Prabhav
  • 447
  • 3
  • 17
  • So there is NO way that an IDE can do this for me? Or any tool? Because its the same class needing to be imported over all the files, not different ones. I know there is a "fix X problems with same solution" which fixes all similar errors in 1 class, can this be done for a whole project? – kay Mar 29 '18 at 10:45
  • In this case, you can write a Script which will iterate through all java files and find text "public class" and insert import statement before that. – Prabhav Mar 29 '18 at 10:55
  • Yeah but I would need code that checks if there is an error in the class, not where "public class" exists. I guess I could check where the new method exists and then write under public class, but I wouldn't know how to write an iterator like that – kay Mar 29 '18 at 10:58
  • You can simply check whether import statement for your class exists in java file if not then add after package name. I do not think there may be such tool Because this is a unique problem. – Prabhav Mar 29 '18 at 11:02