Removal of unwanted imports

Kindly advise on the best way of removing unwanted imports from code which are brought about by mvn after making a PR without closing the PR and repeating the work?

@jwnasambu @gcliff @dkayiwa

Assume you are using eclipse IDE you can try any of the following methods if you haven’t tried out.

  1. Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and select “remove unused imports.” It will remove that import statement from Java file the unfortunate part is it can’t remove multiple unused imports.

  2. To remove multiple imports in a single click use the "Organize Imports which is a feature of Eclipse IDE to remove multiple or all unused imports statement. on your Menu, Select Source–> Organize Imports. This will remove all unused imports from that Java file.

  3. To remove all unused import statement from Java file is Ctrl + Shift + O, which is a shortcut of organized import in Eclipse, and you can say Eclipse shortcut to remove all unused import statement from the Java file.

1 Like

@jwnasambu thanks, really helpful. @gracebish if you are using Intellij then go to Settings > Editor > General >Auto Import and check the Optimize imports on the fly checkbox or you can use Ctrl + Shift + O.

@jwnasambu @medhavi The feedback i get is

Problem while organize imports: openmrs-api/src/main/java/org/openmrs/ contains ambiguous references. User interaction required. Please advise.

1 Like

@gracebish have you tried Ctrl + Shift + O? because this shortcut also

  • organize existing imports
  • remove unneeded imports
  • add new required imports
  • add unambiguous imports on the fly

@jwnasambu what do you feel?

@gracebish does this help?

1 Like

@herbert24 it has caused more robust problems than those that were existing before

Okay, @gracebish can you share what you see after entering Ctrl + Shift + O and before it?

@medhavi could you check TRUNK-5115-new-7:Replace use of conditional logging with slf4j parame… by gracebish · Pull Request #3645 · openmrs/openmrs-core · GitHub?

@gracebish I can see that you are having trouble in importing and somehow an extra line is added each time. I feel import settings are causing this problem, Can you check the setting once as explained here under Configure Java Import Order. You can also run mvn clean install, as Maven plugin will re-order imports for you.

@medhavi my IDE is well configured

1 Like

How is Unnecessary imports should be removed

Does it help?

okay, I think we are definitely missing something important .

@jwnasambu @herbert24 @dkayiwa @ibacher @sharif @gcliff can you look into it?

@gracebish which IDE are you using?

@dkayiwa I am using eclipse