Skip to content

Fix all imports in single quick fix action #490

Closed

Description

@gitorko

capture1

Is there an option to fix all imports in single action similar to netbeans?

Quick fix supports this one line at a time. However would be nice if all imports got fixed in single go. When we copy code from other places resolving the imports one line at a time is time consuming.

Activity

  1. fbricon commented on Apr 4, 2018

    @fbricon
    Collaborator

    There's an "Organize imports" command (Alt+Shift+o)

  2. fbricon commented on Apr 4, 2018

    @fbricon
    Collaborator

    Closing as duplicate of #56.

    You can also organize imports as a save action.

  3. gitorko commented on Apr 6, 2018

    @gitorko
    Author

    @fbricon
    Organize import will only organize imports if you have them. If i copy code and i want the imports to be added automatically in netbeans I run cntr+shift+I which brings up a prompt to import all the classes. screenshot mentioned above. So i dont have to type those imports by hand or one line at a time. I was referring to that feature.

    Organize imports works just fine. This feature request is not the same.

  4. fbricon commented on Apr 6, 2018

    @fbricon
    Collaborator

    no, "Organize Imports" will add missing imports as long as there are matching types on the classpath AND they're unambiguous.

    eg.

    • Serializable -> java.io.Serializable -> import added
    • Collection -> java.util.Collection or org.hibernate.Collection? -> nothing added

    At the moment, there's no UI to handle ambiguous imports, but the rest is all there

  5. gitorko commented on Apr 6, 2018

    @gitorko
    Author

    @fbricon
    Ok gave that a try, it works. all unambigous imports are added.

    I was earlier doing organize imports via the quick fix helper so wasnt seeing quick fix when there were no imports. Once i did Alt+Shift+O or right click and Organize Imports it adds those import statements automatically. Thanks.

  6. ZaLiTHkA commented on Jun 28, 2018

    @ZaLiTHkA

    just out of curiosity, is it possible to perform the "Organise Imports" action on multiple files?

    I've been tasked with refactoring a ton of projects from Ant to Maven, so I have a rather large number of import x statements to update at the moment.. so I'm wondering of this action could help me here?

  7. fbricon commented on Jun 28, 2018

    @fbricon
    Collaborator

    I don't think it's enabled at the moment but we designed the server to support it. We just need to ensure the action is available from the explorer. Please open a separate issue

  8. ZaLiTHkA commented on Jun 28, 2018

    @ZaLiTHkA

    awesome, will do, thanks for the info. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions