I know, this feature is not new. It's with us from around version 3.2 of Eclipse. However, I was not familiar with it and I like it very much, hence, I'm sharing. I like it so much, I think it will make my "Top 10 Eclipse Tricks" (which is a list I should make). This one is for Java developers using Eclipse. I'm sure other IDEs have parallel tools.
A few months ago I wrote a post about Java interfaces. I dwelled over the fact that using interfaces makes it harder to trace the code with static tools. When a class invokes a method through an interface, it can be very difficult (or even impossible) to determine which implementing method is invoked.
Here's the common symptom: you're reading your code and you see a method being invoked, you hit F3 (stands for Navigate->Open Declaration) or use the favorite Ctrl/Command key shortcuts that turns the method names to links. In the normal case, you would now navigate to the method declaration. If the method was invoked through an interface you will get the declaration in the interface, not an actual implementation. Now comes the time-consuming process of looking for the implementing classes of the given interface (use F4 to open the type hierarchy for the interface) and fishing for the method implementation.
Here's the solution: instead of hitting F3, hit Ctrl-T (Command-T on Mac). This is equivalent to choosing Navigate -> Quick Type Hierarchy. What happens next is pure magic:
- Eclipse searches for all the implementors of the interface.
- Among those implementors, it will search for those who implement the selected method
- It will pop-up a small tool-tip like box that shows the relevant implementors hierarchy. In this hierarchy, the interfaces and classes that don't implement the method are grayed out or not shown.
- You can now select a class. It even provide a quick-type selection: start typing the name and it will focus on the matching class.
- You navigate to the method implementation in the selected class.
Here's how it looks like.
The "Quick Type Hierarchy" feature works in other contexts as well. Here's some examples:
- When you're on a class or interface - it will show the hierarchy.
- If you're on field, it will show where the field is defined in the hierarchy
Check it out, it's a very useful feature.