jlleitschuh
11/28/2017, 5:24 PMclass NamedDomainObjectContainerScope<T : Any>(
private val container: NamedDomainObjectContainer<T>) : NamedDomainObjectContainer<T> by container {
operator fun String.invoke(configuration: T.() -> Unit): T =
this().apply(configuration)
/**
* @see [NamedDomainObjectContainer.maybeCreate]
*/
inline
operator fun <reified U : T> String.invoke(configuration: U.() -> Unit): U =
this(U::class).apply(configuration)
}
Use case:
I want to be able to do this:
container { // `this` is type `NamedDomainObjectContainerScope<Task>`
"allice" { /* Type Task in this scope*/ }
"bob"<ExtendedTaskType> { /* Type ExtendedTaskType in this scope*/ }
}
My more general problem is that I'm trying to add reified
overloads for all of these methods in the Gradle Kotlin DSL:
https://github.com/gradle/kotlin-dsl/blob/6a3c51a65e8423aa33432b816996360cd32e7906/provider/src/main/kotlin/org/gradle/kotlin/dsl/NamedDomainObjectContainerExtensions.ktAndreas Sinz
11/28/2017, 5:31 PMjlleitschuh
11/28/2017, 5:32 PMAndreas Sinz
11/28/2017, 5:34 PMjlleitschuh
11/28/2017, 5:35 PM