Enumerate the extension properties defined in a package

I’m writing an HTML templating language in Kotlin.

My templating engine will need to resolve property expressions, such as obj.myProperty, by looking up "myProperty" not just among the members defined in obj’s class and superclasses, but also among extension properties defined in a list of user-specified Kotlin packages.

For instance, if my interpreter is evaluating x.absoluteValue and x turns out to be an Int, I have the following pieces of information:

  • object KClass: Int::class
  • property name: "absoluteValue"
  • list of packages the user asked to search over: kotlin.math , etc.

What API can I use to get a list of all the top-level extension properties defined in a given package, say kotlin.math, as a list of reflected items, such as a List<KProperty<*>>? At template compile time (which is Kotlin runtime) I will go through that list of extensions and look for one named "absoluteValue" compatible with an Int receiver.

I know I can manually define a list of extension properties, such as listOf(Int::absoluteValue, ...) after importing them, but I would like my users to specify a list of packages, not single properties.