Alexander Ioffe
06/14/2024, 5:16 AMmyExpr
in a local scope:
fun foo() { ... }
fun myLocalScope() {
fun foo() { ... }
myExpr
}
I want to get a list of all the foo
functions that can be called in that scope. I've tried every variation of IrPluginContext.referenceFunctions that I can think of but nothing seems to be working.dmitriy.novozhilov
06/14/2024, 7:58 AMdmitriy.novozhilov
06/14/2024, 7:59 AMdmitriy.novozhilov
06/14/2024, 8:06 AMAlexander Ioffe
06/14/2024, 8:19 AMfoo
inside the myLocalScope function above. How do I do that?dmitriy.novozhilov
06/14/2024, 8:20 AMAlexander Ioffe
06/14/2024, 8:21 AMdmitriy.novozhilov
06/14/2024, 8:22 AMdmitriy.novozhilov
06/14/2024, 8:23 AMAlexander Ioffe
06/14/2024, 8:28 AMAlexander Ioffe
06/14/2024, 8:34 AMdmitriy.novozhilov
06/14/2024, 8:45 AMfun findFunctions(expression: IrExpression): List<IrSimpleFunction> {
val functions = mutableListOf<IrSimpleFunction>()
val visitor = object : IrVisitorVoid {
override fun visitElement(element: IrElement) {
element.acceptChildrenVoid(this)
}
override fun visitSimpleFunction(function: IrSimpleFunction) {
if (function.name.asString() == "foo") {
functions += function
}
visitElement(function)
}
}
expression.parent.acceptVoid(visitor)
// or expression.containingFile.acceptVoid(visitor)
// or expression.containingFile.parent.acceptVoid(visitor)
return functions
}
dmitriy.novozhilov
06/14/2024, 8:46 AMIs there a way to traverse all existing extension functions defined on some symbol irregardless of package?You can traverse all source functions in module using approach I showed to collect all functions from sources For functions in dependencies there is no way, you can find them only if you know CallableId