Question

abstract class Base {}

class A extends Base
class B extends Base

How do I find all places in the code that create Base? (that is, have either new A() or new B())

UPDATE
To make it clear, the above is just and example. I'm interested in a way of searching for object creation of any class, including 3rd party classes that I don't control.

Was it helpful?

Solution

Using Structural Search (Edit -> Find -> Search Structurally or Ctrl+Shift+S):

  • Create a template: new $Type$($P$)
  • Edit Type variable: type Base in the text field, check 'Apply constraint within type hierarchy', check 'This variable is target of the search'
  • Edit P variable: type .* in the text field, set Minimum count to 0, check Unlimited under Maximum count.

Voila!

OTHER TIPS

IttayD if I have understood correctly your latest update, what I normally do (IntelliJ 9.0.4) if I have a similar need to yours is Right click on class name and do "Find Usages" and this will list results in the form of usage categories,

  • Variable declaration
  • New Instance creation, to name a few.

As far as I'm aware I do not think there is a specific option/selection choice to fulfill such a usage search check. Thanks

enter image description here

You can create empty default constructor of Base and press Ctrl+Alt+H (Hierarchy Callers). Then you'll see all creations of A and B in as a tree.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top