简体   繁体   中英

How to find where an abstract method is implemented in Eclipse?

I would like to find where an abstract method is implemented, in which class? Is there a link in Eclipse like call hierarchy / open declaration or something like that that shows where the method implemented is?

Quick methods:

  • Hold Ctrl , hover over the method name, and select "Open Implementation".

  • Click on the method name and press Ctrl T .

  • Right-click on the method name → "Quick Type Hierarchy".

For more navigation power, see the post by ADTC .

Great answers here! I found an additional trick to quickly navigate from implementation to implementation.

It is rather strange that Eclipse uses a temporary pop-up to show "Types implementing or defining 'Class.method()'" instead of a permanent view that can be pinned to the sides.

The advantage of this pop-up is, when you click on an implementing type, you are taken directly to the method implementation. The disadvantage of this pop-up is that it closes as soon as you do so, and there is no way to pin it permanently.

The Type Hierarchy shows the same list of implementing types (as they are subclasses of the abstract class). Since it is a view, it can be pinned permanently on the side. However, if you double-click on a type name here, you are taken to the declaration line of the type. You then have to find the implementation of the abstract method yourself.

Except, you don't have to, with the following trick:

  1. Right-click on the abstract method and click Open Type Hierarchy . 1 In the Type Hierarchy view, you will notice the following:
    • All the subtypes of the abstract class type are listed in the primary list (P) . 2
    • All the members of the abstract class are listed in the secondary list (S) . 3
    • The abstract method you right-clicked on is selected in the secondary list. 4

  2. Click on the Lock View and Show Members in Hierarchy button (1) above the secondary list.
    • The selected method and its implementations will be listed in the primary list under each of the subtypes as well as the parent type.

You can now quickly navigate between implementations by clicking or double-clicking on the methods listed in the primary list.

截图显示了所提到的各个部

1 You can also click on the method name and press F4.
2 If they are not listed, click either one of the Show the Type Hierarchy (2) or Show the Subtype Hierarchy (3) buttons above the list.
3 If there's no secondary list, click on the View Menu (4) , choose Layout > [any option other than Hierarchy Only ].
4 If it is not selected, just click on it to select it.

If you Ctrl + mouse hover over a method you can see a popup where you can choose from an array of options and one of them is " Open Implementation ". If you click you will be presented with a list of all implementations.

It can also be used to see the declaration and/or super implementation, so it is pretty useful.

If you have the cursor over the method you can simply press Ctrl + T for the same effect.

If you want to display the results in the " Type Hierarchy " view use the F4 key.

You can use the TypeHierarchy view for this. Here's an example of the type hierarchy view for the Spring framework abstract class FrameworkServlet:

在此输入图像描述

In the left pane you see the class inheritance tree. The 'A' icon next to the class name in the left pane indicates that FrameworkServlet is an abstract class. In the right pane, the highlighted method doService( request, response ) also has the 'A' icon, indicating that this is an abstract method.

Now if we click on the class DispatcherServlet, which is a concrete (not abstract) class, you see this:

在此输入图像描述

In this case, the DispatcherServlet's doService method does not have the 'A' icon and instead has the up triangle, indicating that it overrides a superclass method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM