Information on delegates

When using reflection, it is not clear that it is possible to get information on whether a property is a delegate. In a delegate function or class it is not possible to know the property yet either. What I am trying to achieve is that I want to know the name of the property in the delegate function (not later). While I can use reflection to review all properties in the class, I cannot use that to determine that the current delegate function invocation corresponds to that property.

The use case is for a DSL for database table definitions (GitHub - pdvrieze/kotlinsql: A kotlin library that allows abstracting away sql syntax and provides a typed/typesafe alternative that is still close to the metal., very alpha), where I’d like to do something like:

  object myTable():MutableTable() {
    val firstName by VARCHAR(30)
  }

Where I am is that I have:

  object myTable():MutableTable("myTable") {
    val firstName by VARCHAR("firstName", 30)
  }

The table name is easy (not implemented yet), but I’d like to (optionally) get the name of firstName from the property definition. While the delegator could initialise the values lazily, it would be nicer if the name could be determined immediately. Obviously, it is also possible to have multiple properties referring to the actual same table column, or to use a differentname than the name used in the table.