Can eclipse be configured to automatically fix missing Imports?

前端 未结 6 646
北海茫月
北海茫月 2020-12-08 02:18

Because they didn\'t make it easy enough already ;)

相关标签:
6条回答
  • 2020-12-08 02:54

    I think you are looking for Ctrl + Shift + O

    You can also set up Eclipse to automatically organize imports on save:

    Preferences > Java > Editor > Save Actions

    0 讨论(0)
  • 2020-12-08 02:58

    Ctrl + Shift + O (Cmd + Shift + O for mac) - Organize all imports
    Ctrl + Shift + M (Cmd + Shift + M for mac) - Import one by one (you need cursor on the red marker)

    0 讨论(0)
  • 2020-12-08 02:59

    I found this site: http://eclipseone.wordpress.com/2010/03/10/navigate-and-fix-errors-amp-warnings-in-a-class-with-eclipse-keyboard-shortcuts/

    It recommends using ctr/cmd + 1 to use the keyboard, this is much better than having to use the mouse, but I'm still looking for a "Just do the right thing most of the time" automatic solution.

    0 讨论(0)
  • 2020-12-08 03:02

    @Fabian's answer is correct if the class to be imported is already on the classpath for the java project or plugin.

    I'm not aware of a way to get Require-Bundle headers added(in the case of eclipse plugins) or package imports(in the case of osgi bundles) added automatically by Eclipse.

    What this means is that you can get what you want as long as you restrict the classes you add to those already on the classpath. However, if you try to start using a class that isn't already on your path, the organize imports aren't going to be able to help you.

    0 讨论(0)
  • 2020-12-08 03:11

    Eclipse: Automatically fix missing imports

    1. macOS

    a) Organize all imports

    Command + Shift + O

    b) Add import for a specific line

    Command + Shift + M

    2. Windows

    a) Organize all imports

    Control (Ctrl) + Shift + O

    b) Add import for a specific line

    Control (Ctrl) + Shift + M

    0 讨论(0)
  • 2020-12-08 03:16

    From Eclipse Menu, Select Source-->Organize Imports. This will remove all unused imports from that Java file.

    0 讨论(0)
提交回复
热议问题