I have this code base which is rather big ( +/- 500k lines). I'm looking in it to find all the method calls that use a single parameter and that parameter is a specific type.
This means, I want to be able to find method calls like the following:
public class Foo { }
public class Bar { }
public class Doer{
public void doSomethingFoo(Foo foo) { }
public void doSomethingObject(Object object) { }
}
public class Usage {
Doer doer = new Doer();
public doSomething() {
Foo anObject = new Foo();
Bar bar = new Bar();
doer.doSomethingFoo(anObject);
doer.doSomethingObject(anObject);
doer.doSomethingObject(bar);
}
}
Since both doer.doSomethingFoo(anObject)
and doer.doSomethingObject(anObject)
are called, both those statements should be returned by the search. Similarly, doer.doSomethingObject(bar)
is not returned. Of course, I don't know that doer
exists.
I'm trying to use the Structural Search of IntelliJ to do so. I've used the following template $Instance$.$Method$($Parameter$)
, with the following parameters:
$Instance$ -> Text/regexp = .*
$Method$ -> Text/regexp = .*
$Parameter$ -> Text/regexp = Foo
Minimum count = 1 // Minimum one Foo parameter
Maximum count = 1 // Maximum one Foo parameter
This returns everything that has a parameter named foo
(case-insensitive, apparently). So I'm probably doing something wrong here. But what? How can I get all calls to any method where the only param is of type Foo
?
Press Ctrl+Alt+Shift+F7 to open the Find Usages dialog. In the Find Usages dialog, in the Scope field, select a scope for your search. For example, you can search for usages only in Open Files or only Project Test Files.
In IDEA, clicks on the method name, press CTRL + Q to show the method signature on a pop up. Alternatively, press CTRL + P to show the available parameters.
Use Navigate (View in older versions) | File Structure Popup ( Ctrl + F12 on Windows, ⌘ + F12 on OS X). Start typing method/symbol name to either narrow down the list or highlight the desired element. Press Enter to navigate to the selected element.
Build a call hierarchy Open a file in the editor and place the caret at the declaration or usage of the desired method or a field. Alternatively, select the desired method or the field in the Project tool window. From the main menu, select Navigate | Call Hierarchy or press Ctrl+Alt+H .
You are almost there. All you need to do now is set the Expression type (regexp)
of $Parameter$ to Foo
and leave Text/regexp
blank. Additionally you may want to enable the Apply constraint within type hierarchy
checkbox, to find subclasses of Foo too.
Note that you can leave the Text/regexp
of all variables blank. This is equivalent to .*
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With