Hi, does anyone know how to reference a Java stati...
# compiler
j
Hi, does anyone know how to reference a Java static method in IR? I tried
IrPluginContext#referenceFunctions(FqName)
but the list keeps coming back empty
this works:
Copy code
private val funPrintln = pluginContext.referenceFunctions(FqName("kotlin.io.println"))
however referencing a static (that is in the kotlin compile dependencies) does not
Copy code
private val funPrintln = pluginContext.referenceFunctions(FqName("path.Class.staticMethod"))
y
maybe try
Copy code
moduleFragment.descriptor.resolveTopLevelClass(FqName("path.Class"), NoLookupLocation.FROM_BACKEND)?.let{
      pluginContext.symbolTable.referenceClass(it).owner.functions.filter { it.name.identifier == "staticMethodName" }.first()
    }
not sure if it'll work or not but it's worth a try
j
thanks i'll try it in a bit!
s
I would also try to just reference class by fqName and find function inside it, but no clue if it works with java
j
reference by class and finding functions worked!
👍 1
Copy code
private val androidLog = pluginContext.referenceClass(FqName("android.util.Log"))
        private val androidDebug = androidLog?.owner?.functions?.first {
            it.name == Name.identifier("d")
        }?.symbol
thank you both
s
Yep, my suspicion is that the function lookup works only for top level functions, so if it is wrapped in class, you have to look for it instead
👍 1