[英]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?
Eclipse中是否有一个链接,如调用层次结构 / 开放声明或类似的内容,它显示了实现方法的位置?
Quick methods: 快速方法:
Hold Ctrl , hover over the method name, and select "Open Implementation". 按住Ctrl键 ,将鼠标悬停在方法名称上,然后选择“打开实施”。
Click on the method name and press Ctrl T . 单击方法名称,然后按Ctrl T.
Right-click on the method name → "Quick Type Hierarchy". 右键单击方法名称→“快速类型层次结构”。
For more navigation power, see the post by ADTC . 有关更多导航功能,请参阅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. Eclipse使用临时弹出窗口来显示“实现或定义'Class.method()'的类型”而不是可以固定到侧面的永久视图,这是相当奇怪的。
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: 除此之外,您不必使用以下技巧:
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. 1您也可以单击方法名称并按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. 2如果未列出,请单击列表上方的显示类型层次结构 (2)或显示子类型层次结构 (3)按钮之一。
3 If there's no secondary list, click on the View Menu (4) , choose Layout > [any option other than Hierarchy Only ]. 3如果没有辅助列表,请单击“ 查看”菜单 (4) ,选择“ 布局” > [除“ 仅层次结构”以外的任何选项]。
4 If it is not selected, just click on it to select it. 4如果未选中,只需单击它即可将其选中。
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 ". 如果您将
Ctrl + mouse hover
在某个方法上,则可以看到一个弹出窗口,您可以从中选择一组选项,其中一个是“ 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. 如果将光标放在方法上,只需按
Ctrl + T
获得相同的效果。
If you want to display the results in the " Type Hierarchy " view use the F4
key. 如果要在“ 类型层次结构 ”视图中显示结果,请使用
F4
键。
You can use the TypeHierarchy view for this. 您可以使用TypeHierarchy视图。 Here's an example of the type hierarchy view for the Spring framework abstract class FrameworkServlet:
这是Spring框架抽象类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.
左窗格中类名旁边的“A”图标表示FrameworkServlet是一个抽象类。 In the right pane, the highlighted method doService( request, response ) also has the 'A' icon, indicating that this is an abstract method.
在右侧窗格中,突出显示的方法doService(request,response)也有“A”图标,表示这是一个抽象方法。
Now if we click on the class DispatcherServlet, which is a concrete (not abstract) class, you see this: 现在,如果我们点击DispatcherServlet类,它是一个具体的(非抽象)类,你会看到:
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. 在这种情况下,DispatcherServlet的doService方法没有'A'图标,而是具有up三角形,表示它覆盖了超类方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.