Structural search - method calls for a particular static method
Answered
I'm trying to use Structural Search find all method calls of CompletableFuture.supplyAsync, runAsync etc that do not pass a custom executor. This is where I've reached now:
<searchConfiguration name="$Before$.$MethodCall$($Parameter$, $exec…" uuid="17513432-9de1-3705-8708-4b1302e84a3a" text="$Before$.$MethodCall$($Parameter$, $exec$)" recursive="true" type="JAVA" pattern_context="default">
<constraint name="__context__" within="" contains="" />
<constraint name="Before" nameOfExprType="java\.util\.concurrent\.CompletableFuture" within="" contains="" />
<constraint name="MethodCall" regexp=".+Async" target="true" within="" contains="" />
<constraint name="Parameter" minCount="0" maxCount="2147483647" within="" contains="" />
<constraint name="exec" nameOfExprType="java\.util\.concurrent\.Executor" exprTypeWithinHierarchy="true" negateExprType="true" within="" contains="" />
</searchConfiguration>
The Type filter on the Before does not seem to be working. If I change that to a text filter for CompletableFuture, it works but that is sub-optimal as it won't give the occurrences where the method is imported statically.
Is this because this is a static method and this only works for instance methods?
I found this bug - https://youtrack.jetbrains.com/issue/IDEA-32545/SS-does-not-allow-find-static-method-within-herarchy, which seems to be related but it's marked FIXED.
Please sign in to leave a comment.
> Is this because this is a static method and this only works for instance methods?
Basically yes. The qualifier of an instance method call is an expression, has a value, and therefore has a type. The qualifier of a static method call is a reference to a class, which is not an expression, and has no value and therefore no type. What you need is a Text filter instead of a Type filter, as you have already discovered.
If you want to match statically imported methods, add a `[0,1]` Count filter as well.
Bas