Is there an "Add Imports" that works across whole project?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there an "Add Imports" that works across whole project?

Thomas Wolf-7
I see two capabilities - Source->"Fix Imports" for a single file and Inspect&Transform->"Organize Imports" that can be run across the whole project.  But both do more than I want!  I just want to add missing imports across the whole project - I don't want to remove unused ones and don't want the ordering of existing imports to change!

Use case:
I did a project-wide search/replace of the String 
     JOptionPane.showMessageDialog(null,
with
     JOptionPane.showMessageDialog(BaseDialog.getAppFrame(),

So now I have dozens of files that don't compile because they don't have the required import.  I can go to them individually and run "Fix Imports", but that also removes supposedly unused imports (NB isn't always right about imports being unused, so I want to look at those on a case-by-case basis - later!)....and it's just very time consuming.  Even more time consuming is to go to the first error in each file and invoke the gutter hint "Add Import" (which is exactly what I want - but on a project level).  Not exactly sure what all "Organize Imports" does, but it's definitely more than I want.

If you know of anything in NB that does this, please let me know.
tom
Reply | Threaded
Open this post in threaded view
|

Re: Is there an "Add Imports" that works across whole project?

Brett Ryan
Can you highlight the source package node in the project explorer and invoke cmd+shift+F fix imports?

As another option could you use a search/replace instead of your first remove text?

On 19 May 2017, at 06:30, Thomas Wolf <[hidden email]> wrote:

I see two capabilities - Source->"Fix Imports" for a single file and Inspect&Transform->"Organize Imports" that can be run across the whole project.  But both do more than I want!  I just want to add missing imports across the whole project - I don't want to remove unused ones and don't want the ordering of existing imports to change!

Use case:
I did a project-wide search/replace of the String 
     JOptionPane.showMessageDialog(null,
with
     JOptionPane.showMessageDialog(BaseDialog.getAppFrame(),

So now I have dozens of files that don't compile because they don't have the required import.  I can go to them individually and run "Fix Imports", but that also removes supposedly unused imports (NB isn't always right about imports being unused, so I want to look at those on a case-by-case basis - later!)....and it's just very time consuming.  Even more time consuming is to go to the first error in each file and invoke the gutter hint "Add Import" (which is exactly what I want - but on a project level).  Not exactly sure what all "Organize Imports" does, but it's definitely more than I want.

If you know of anything in NB that does this, please let me know.
tom
Reply | Threaded
Open this post in threaded view
|

Re: Is there an "Add Imports" that works across whole project?

Cazzie Williams
In reply to this post by Thomas Wolf-7
unsubscribe me from this list

On Thu, May 18, 2017 at 3:30 PM, Thomas Wolf <[hidden email]> wrote:
I see two capabilities - Source->"Fix Imports" for a single file and Inspect&Transform->"Organize Imports" that can be run across the whole project.  But both do more than I want!  I just want to add missing imports across the whole project - I don't want to remove unused ones and don't want the ordering of existing imports to change!

Use case:
I did a project-wide search/replace of the String 
     JOptionPane.showMessageDialog(null,
with
     JOptionPane.showMessageDialog(BaseDialog.getAppFrame(),

So now I have dozens of files that don't compile because they don't have the required import.  I can go to them individually and run "Fix Imports", but that also removes supposedly unused imports (NB isn't always right about imports being unused, so I want to look at those on a case-by-case basis - later!)....and it's just very time consuming.  Even more time consuming is to go to the first error in each file and invoke the gutter hint "Add Import" (which is exactly what I want - but on a project level).  Not exactly sure what all "Organize Imports" does, but it's definitely more than I want.

If you know of anything in NB that does this, please let me know.
tom

Reply | Threaded
Open this post in threaded view
|

Re: Is there an "Add Imports" that works across whole project?

Thomas Wolf-7
In reply to this post by Brett Ryan
I didn't try cmd-shift-f at he package level.  I gave up when the option was disabled at the project and source root level.  I'll give it a try - thanks!

tom

On May 18, 2017, at 8:46 PM, Brett Ryan <[hidden email]> wrote:

Can you highlight the source package node in the project explorer and invoke cmd+shift+F fix imports?

As another option could you use a search/replace instead of your first remove text?

On 19 May 2017, at 06:30, Thomas Wolf <[hidden email]> wrote:

I see two capabilities - Source->"Fix Imports" for a single file and Inspect&Transform->"Organize Imports" that can be run across the whole project.  But both do more than I want!  I just want to add missing imports across the whole project - I don't want to remove unused ones and don't want the ordering of existing imports to change!

Use case:
I did a project-wide search/replace of the String 
     JOptionPane.showMessageDialog(null,
with
     JOptionPane.showMessageDialog(BaseDialog.getAppFrame(),

So now I have dozens of files that don't compile because they don't have the required import.  I can go to them individually and run "Fix Imports", but that also removes supposedly unused imports (NB isn't always right about imports being unused, so I want to look at those on a case-by-case basis - later!)....and it's just very time consuming.  Even more time consuming is to go to the first error in each file and invoke the gutter hint "Add Import" (which is exactly what I want - but on a project level).  Not exactly sure what all "Organize Imports" does, but it's definitely more than I want.

If you know of anything in NB that does this, please let me know.
tom