Structural search interface suspend function call
Solution 1:
That was tricky, but here it is:
You need to use script constraints. The idea is to filter the parent of your whole match. There are many ways to do that, e.g. to distinguish them by their type.
Here is my search:
Template:
$Service$.$method$($args$)
$Service$
variable filter:
Type = you.package.Service
$args$
(optional, though):
Count = [0: +Inf]
And the most important part, the whole template script filter:
__context__.parent.parent.class.name == "org.jetbrains.kotlin.psi.KtNamedFunction"
It's dirty, I know. For some reason I was not able to make it work with instanceof
, but you may tune it.
If you do, you may ask: How do I debug that script?
Here is my advice. Open the IDEA's logs (Help -> Show Log in Explorer). Then use println()
in the script, it will print it's argument to the STDOUT
:
You see, here there were two matches, but the parent of the second one (which os ok as per your request) was of a different type. So, a quick guess and dirty fix here was to compare them. A more cunning way would be to get the name of the wrapping construct and check if it's safeApiCall
or not. I'll leave that to you as an exercise.
Good luck!