Is there a way in IntelliJ to search for the use of a method and filter it by specific arguments passed to the method?

I have a method in my Service class that performs a sleep mode update for any domain object:

update(Object obj) 

He called from many classes in my project for different objects. I would like to find all the ways to use this method when it requires a specific domain object. That is, call calls a call that updates my Title object:

 serviceClass.update(Title title) 

I use IntelliJ as my IDE, and I wonder if there is a way to find all of these usages. Does anyone have an IDEA how to do this?

Thanks a lot in advance, Ronnie

+4
source share
2 answers

I tried this with a small sample project and was able to achieve the desired behavior using the Structural Search and Replace Function with the modified method calls template:

enter image description here

$MethodCall$ Text restrictions , Text / regular expression must be set to update , so methods with other names are ignored. $Parameter$ Number of instances . The minimum counter must be set to 1 to ignore method calls without any parameters.

Results:

results

+5
source

If you are interested in call chains that provide specific input to this method, try the command Analyze-> Data Flow to Here.

This allows you to see which values ​​are passed through which call chains. And, for example, where zero values ​​may appear.

Pretty powerful feature, really.

0
source

Source: https://habr.com/ru/post/1440750/


All Articles