spring-fu icon indicating copy to clipboard operation
spring-fu copied to clipboard

Cannot extend Kotlin DSL

Open bmorris591 opened this issue 2 years ago • 1 comments

With reference to https://github.com/spring-projects-experimental/spring-fu/issues/275 and https://github.com/spring-projects-experimental/spring-fu/issues/253

I am trying to create a simple extension to enable using r2bdc-migrate, my starting point it

class R2dbcMigrationDsl(private val init: R2dbcMigrationDsl.() -> Unit) : AbstractDsl() {

    override fun initialize(context: GenericApplicationContext) {
        super.initialize(context)
        init()

        val properties = r2dbcMigrationProperties()

        R2dbcMigrationInitialiser(properties).initialize(context)
    }

    fun r2dbcMigrationProperties(): R2dbcMigrateProperties =
        let { self ->
            R2dbcMigrateProperties().apply {

            }
        }
}

fun R2dbcDsl.migrate(dsl: R2dbcMigrationDsl.() -> Unit = {}) {
    R2dbcMigrationDsl(dsl).initialize(context)
}

I have a compilation error at .initialize(context) because context is internal.

snip/migrate/R2dbcMigrationDsl.kt:29:39
Kotlin: Cannot access 'context': it is internal in 'R2dbcDsl'

I think the context needs to become more visible to allow for DSLs to extend and use the idiom that Kofu uses.

bmorris591 avatar Jul 23 '21 08:07 bmorris591

there is a much larger issue to improve extensibility of Kofu/Jafu https://github.com/spring-projects-experimental/spring-fu/issues/360

Julien-Eyraud avatar Oct 05 '21 14:10 Julien-Eyraud