tags:

views:

26

answers:

3

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

A: 

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.

NorthIsUp
+3  A: 

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

Fabian Steeg
+1  A: 

@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.

James Branigan