IntelliJ IDEA: how to find all instance creation of a class?
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.
Solution 1:
Using Structural Search (Edit -> Find -> Search Structurally):
- 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!
Solution 2:
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