- Resolving function calls: there is the extension function
org.jetbrains.kotlin.resolve.calls.callUtil#getResolvedCall
defined onKtElement?
. You need to pass it the binding context. - Finding arguments by index
i
- Attention! Getting argument
i
from theKtCallExpression
will not necessarily get you the value you are expecting and may even fail with anIndexOutOfBoundsException
!KtCallExpression
s are not resolved, hence if you get argumenti
from it, it is really thei
th argument in the argument list, not the argument corresponding to thei
th parameter (which is more likely what you want). The usage of named arguments and default parameter values can cause the order and length of the argument list to be unpredictable. - Instead, retrieve the argument value from the resolved call:
ResolvedCall#valueArgumentsByIndex
. This will give you a list ordered by parameter order and filled up with placeholders where the default parameter values are being used. Arguments tovararg
parameters are also handled.- Note: call this method once and store the result if you need to access it multiple times. The method performs the argument resolution every time it is called.
- Attention! Getting argument