[reflect] Extend API to get parents/owners

Are there any plans to extend the reflection API with possibility to go from children to parents, e.g. from function to class/package?

I think the biggest limitation of the reflection right now is that KFunction and KProperty only provide information about their “contents”, but not their identity/location. For example, MyClass::foo doesn’t provide a way to get back the MyClass which seems strange to me. Similarly, we can’t get the package of a class (there’s only qualifiedName), we can’t get the outer class from a nested class, etc.

KDeclarationContainer seems like an initial attempt to start adding a generic parent<->children API. By looking into kotlin.jvm.internal it seems we already have most of needed stuff, but they’re internal. We have CallableReference.owner: KDeclarationContainer (also subtypes: FunctionReference and PropertyReference), we have KPackage (actually, KPackageImpl), etc. Are there plans to make some of them public, at least for JVM?

edit:
I understand that KFunction/KProperty are abstract and they don’t have to be members of a class/package. I rather think about exposing e.g. KFunctionReference, similar to current FunctionReference.

1 Like