Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350282

Summary: More advanced C++ search
Product: [Tools] CDT Reporter: Jonathan Watt <jwatt>
Component: cdt-source-navAssignee: Project Inbox <cdt-source-nav-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: enhancement    
Priority: P3 CC: aegges, cdtdoug, malaperle, yevshif, zeratul976
Version: 8.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Jonathan Watt CLA 2011-06-24 11:35:40 EDT
Mozilla has been on-and-off working on a webapp tool called DXR that enables pretty advanced C++ searches. For example, to find all subclasses of BaseClass, you can search for:

  derived:BaseClass

Or to search for all overrides of BaseClass::Method, you can search for:

  derived:BaseClass::Method

Or to search for all callers of BaseClass::Method and its overrides, you can search for:

  callers:BaseClass::Method

The latter two are *particularly* useful when the Method name is a common one used on various unrelated classes (GetX/GetY/Paint in Mozilla source, for example).

DXR can be found at http://dxr.mozilla.org/ although that's about a year or so out of date and currently seems to be broken. It still gives an idea of the queries that are available though.

At any rate, given that that site is broken at the moment, it got me to thinking that actually this functionality would be more useful directly in the IDE. I'm sure lots of other people would find it really cool and useful too.
Comment 1 Jonathan Watt CLA 2011-06-24 13:34:25 EDT
dxr.mozilla.org just got fixed, so queries like derived:nsDisplayItem::Paint now work again:

http://dxr.mozilla.org/search.cgi?tree=mozilla-central&amp;derived=nsDisplayItem%3A%3APaint

I'd still be interested in seeing this type of smart search in Eclipse though. :)
Comment 2 Markus Schorn CLA 2011-06-29 10:24:16 EDT
Note, that you can enter qualified names in the C++ search. So you can search for all callers of 'BaseClass::Method'.

To find the subclasses/overriders of a class/method you can use the type-hierarchy, or the quick type-hierarchy.

I am not convinced, that we need another way of obtaining the same information.
Comment 3 Jonathan Watt CLA 2012-05-23 10:40:13 EDT
I don't seem to be able to find a way to find the overrides of a method in Eclipse. Selecting "Open Type Hierarchy" or "Quick Type Hierarchy" from the context menu for the declaration of a virtual method seems to create a type hierarchy for the class, not a hierarchy of the overrides. (This is Juno nightly.) Certainly, if I double click on any of the results, I'm taken to the class declaration, and commonly these sub-classes do not actually override the method of interest.
Comment 4 Jonathan Watt CLA 2012-05-23 10:41:40 EDT
Even for the subclasses that do happen to override the method in question, I'm taken to the first line of the declaration of the class, not the definition of its override as I'd like.
Comment 5 Marc-André Laperle CLA 2012-05-23 12:35:30 EDT
(In reply to comment #4)
> Even for the subclasses that do happen to override the method in question, I'm
> taken to the first line of the declaration of the class, not the definition of
> its override as I'd like.

Can you provide some sample code? It works for me, I use "Quick Type Hierarchy" all the time and it takes me to the method definition, not the class. I'm using 8.1.0.201205221005 which I think is Juno RC1.
Comment 6 Jonathan Watt CLA 2012-05-23 12:40:45 EDT
Not easily. I'm using the draft instructions here:

https://developer.mozilla.org/en/Eclipse_CDT

So this is with the Mozilla source, which Eclipse otherwise seems to handle relatively well if you have enough RAM.
Comment 7 Jonathan Watt CLA 2012-05-23 13:40:08 EDT
I just did a software update to latest nightly Juno, and now it seems to mostly work (it's a bit buggy, but that may be down to indexer bugs in general). Both the quick and normal type hierarchy mechanisms seem a bit clunky for finding overrides though. I basically would like to be able to get a list of the overrides, search results style. I then want to be able to quickly double click on each result in turn to quickly look at each definition. Unfortunately both the quick and normal type hierarchy mechanisms involve expanding trees searching for results. The quick hierarchy method also requires doing this again and again as you go through the results one at a time, whereas the normal method also require you to select a class with an override and scroll the method name into view in the right hand pane and double click that (it would be helpful to have this auto scroll, but it would still be clunky). So I think it would still be nice to be able to have a list of the overrides that you can double click on as described.
Comment 8 Axel Mueller CLA 2014-09-30 08:21:39 EDT
(In reply to Jonathan Watt from comment #7)
> I just did a software update to latest nightly Juno, and now it seems to
> mostly work (it's a bit buggy, but that may be down to indexer bugs in
> general). Both the quick and normal type hierarchy mechanisms seem a bit
> clunky for finding overrides though. I basically would like to be able to
> get a list of the overrides, search results style. I then want to be able to
> quickly double click on each result in turn to quickly look at each
> definition. Unfortunately both the quick and normal type hierarchy
> mechanisms involve expanding trees searching for results. The quick
> hierarchy method also requires doing this again and again as you go through
> the results one at a time, whereas the normal method also require you to
> select a class with an override and scroll the method name into view in the
> right hand pane and double click that (it would be helpful to have this auto
> scroll, but it would still be clunky). So I think it would still be nice to
> be able to have a list of the overrides that you can double click on as
> described.
I just noticed that is indeed possible to get such a list of overridden classes 
You have to select the base class method in the editor and then open the Quick Type Hierarchy with Ctrl-T. Then you will get a list of subclasses that override this method.

I was looking a long time for this feature and today I wanted to add my comment here and then did a Google search how the JDT plugin does handle this and found the solution :-)
Comment 9 Nathan Ridge CLA 2018-12-17 00:34:09 EST
Something I just discovered today: in the regular Type Hierarchy view, if the operation was invoked from a method, those classes in the hierarchy which declare that method (and only those) have their icons decorated with a small arrow. So, this is another way to quickly identify classes in the hierarchy which implement / override a virtual method.