val someDslSet = DefaultDomainObjectSet<Foo>()
someDslSet.all { //SAM conversion of Action<Foo>
[...]
}
When written as expected:
val someDslSet = DefaultDomainObjectSet<Foo>()
someDslSet.all { // Links to _Collections.kt Iterable<T>.all((T)->Boolean): Boolean
[...]
}
Current workaround
val someDslSet = DefaultDomainObjectSet<Foo>()
@Suppress("ObjectLiteralToLambda")
someDslSet.all(object : Action<Foo> {
override fun execute(target: Foo) {
[...]
}
}
Trying to write a gradle plugin in kotlin that uses the kotlin-dsl plugin as part of the project configuration.
This commit in my project represents pretty well the good/bad/ugly of the current SAM conversion solution. https://github.com/trevjonez/android-components-plugin/commit/16ea739737cd1c9b8b817ab0c1cffbe601ed38fb
AndroidLibraryComponentsPlugin.kt had issues with DomainObjectCollection.all(Action<T>)
Whereas LibraryComponentFactory.kt was much improved.
DomainObjectCollection.all() takes an Action<T>. Action<T> is treated by Kotlin as equivalent to the functional type T.() -> Unit, that is, a Kotlin function type with a receiver. Therefore to use it you should use a lambda with receiver, that is without parameters:
domainObjectSet.all {
// `this` is T
}
If you specify a lambda argument, then .all() resolves to _Collections.kt Iterable<T>.all((T)->Boolean): Boolean that takes an argument.
Closing as answered
Most helpful comment
Closing as answered