Tuesday 30 October 2012

Eclipse Tips - Navigation

Eclipse is a really powerful tool but it's really easy to miss some of the most powerful features. I was therefore interested to come across the following link on /r/java: My Top 10 Tips on how to be more productive with the Eclipse IDE.

I liked these tips but I think there are some other important ones which are worth pointing out.

Navigation Tips

Eclipse has some fantastic functionality to enable fast navigation to find whatever you are looking for.

1) Open Type (Ctrl-Shift-T)

The Open Type window is the right way to open Java classes. If you find yourself looking for classes by manually looking around in the Package Explorer you are almost certainly wasting your own time unless you have no idea what the class you are looking for is called.

Open Type supports wildcards (e.g. H*Map matches HashMap) and camelcase (e.g. LHM matches LinkedHashMap).


2) Open Resource (Ctrl-Shift-R)

The Open Resource window is the right way to open any file which isn't a Java class e.g. a properties file or an xml file etc.

Open Resources works very similarly to Open Types with support for wildcards and camelcase. However there is also support for specifying Folder Prefixes (e.g. */ui/*.html matches all html files within a folder called ui).


3) Quick Open (Ctrl-O within a Java file)

Quick Open is the right way to jump to particular elements within a Java file. If you use the Outline View you are wasting your time as you are forced to visually search for what you are looking for.

Quick Open supports wildcards and camel case (as of Eclipse Juno).


Other Tips

There are three more tips which I think are particularly worth noting.

4) Quick Access (Ctrl-3)

Eclipse functionality is exposed through a large number of Views, the menus include a huge number of Commands and there are lots of Preferences which control all of this. Finding all of these elements is extremely tricky.

Quick Access supports wildcards and can be used to load any of these elements. This is by far the fastest way to open things like Views.


5) Local History

Have you ever made a series of changes to a file and then wished that you could go back to a previous version? It's easy if you are using a version control system and have checked in a previous version but what if you didn't?

Eclipse has got a feature to help you out. The Local History feature keeps track of a limited number of previous versions of every file which you save through Eclipse. To revert to one of these previous versions you just have to use the correct menu. Right click the file within Package Explorer and select Replace/Compare With -> Local History...


6) Eclipse Help

It is absolutely worth noting that the Eclipse Help is really excellent. For example, try looking at the “Open Type” or “Open Resource” articles for full details of the pattern matching which you can do.