How to find usages of inherited constructor

I would like to find all usages of a constructor in inherited classes.  Alternatively, I want to find all instances in which a class that inherits from a given class is instantiated.  Is this possible?

Find Usages Advanced on the base class constructor does not seem to have any options for showing derived usages.  Find Usages Advanced on the base class itself has a “Derived types” option, but it only shows the class declarations, not usages.

0
3 comments

Hi Sy

I've attached a screenshot with sample code. 

This can be achieved by using Find Usages on a constructor A(int a, int b)  and then enabling Group by Usage Type in the tool window. The derived types are placed under the Invocation group.

 

 

 

0

Hi,

For some reason “Group by Usage Type” lists the inherited classes' constructor definitions as invocations; but it doesn't show the actual invocations of these constructors e.g. new B(1, 2).  The base class is abstract, if that makes any difference.

I'm using 2024.3 Build #RD-243.21565.191

0

Hello,

I am afraid there is no such a feature to search what you want at once.

You can search for all the instantiations of desired classes using textual search (Find in Files, Ctrl+Shift+F) with regexp like new\s+(C1|C2)\( where C1 and C2 are class names derived from base.

Or you can use “Navigate → Derived symbols” to get the list of derived symbols, then, search for its usages one by one.

Hope that helps. 

Have a nice day!

0

Please sign in to leave a comment.