Paolo Rotolo
12/06/2023, 12:11 PM@Test
(org.junit.Test)
- Check if there are coroutine launches outside runTest block
- Collect all the functions of the same codebase called in (f) and perform the same check on them and so on.
I’m new to PSI APIs and I didn’t find a lot of documentation online, but I’m very curious to learn more. I think I’ve got the first two steps in my draft PR, but I’ve no idea which API to use to retrieve all the function calls in the scope of the @Test
function that could launch a coroutine internally.
I’ve also explored the inverse path: visiting all the functions using Visitor’s visitNamedFunction
and finding if there’s a @Test
function parent, but it would be a less optimized solution I guess?gammax
12/07/2023, 12:18 PMI’m new to PSI APIs and I didn’t find a lot of documentation onlineThat’s sadly true for all the PSI related questions 😞
gammax
12/07/2023, 12:19 PMPaolo Rotolo
12/07/2023, 1:33 PMPaolo Rotolo
12/10/2023, 3:37 PMfunction.collectDescendantsOfType<KtExpression>().mapNotNull {
it.getResolvedCall(bindingContext)
?.resultingDescriptor
?.source
?.getPsi() as? KtNamedFunction
}
Will update the PR soonAtul Gupta
12/12/2023, 9:04 PMexpression.anyDescendantOfType<KtExpression>(::shouldTraverseInside) { descendant ->
descendant.hasSuspendCalls()
}.ifTrue { report(expression) }
You can refer SuspendFunSwallowedCancellation
which finds the call to runCatching
then checks each child function for possible violations