Hi,

I have looked at Scala support lately because I have implemented the
same TraitMixin (class that do all magic) for Kotlin[1] language.
I have extended TraitMixin to support @This injection and private
mixins. Currently looking at @State injection. All was possible
without adding Fragment SPI, but adding such spi could allow nicer
syntax ( at least for Kotlin ).

Here is example how it look in Kotlin:
[1]  www.jetbrains.com/kotlin

trait TestEntity: EntityComposite, Commands, Events, Data {
}

// interface + mixin
trait Commands {

    // [This] is supported lazy via getEvents() implemented by TraitMixin
    protected var events: Events
        [`This`] private set
        [`This`] get

    // [Service] is supported lazy, implemented by TraitMixin
    [Service]
    fun testService(): TestService;

    fun updateFoo(newValue: String)
    {
        // Call "injected" service
        val repeated = testService().repeat(newValue);
        events.updatedFoo(repeated)
    }
}

trait Data {
    [UseDefaults]
    fun  foo(): Property<String>
}

[Mixins( javaClass<SupportMixin>() )]
trait Events
{
    fun updatedFoo(newValue: String)
}

trait Nameable {
    [UseDefaults]
    fun name(): Property<String>
}

abstract class SupportMixin: Events {

    // here [This} is also lazy via getNameable() as Kotlin generates
get/set methiods
    // Nameable is private mixin and here is line from TraitMixin
    // return ((CompositeInstance)Proxy.getInvocationHandler(
composite )).newProxy( method.getReturnType() );
    [`This`]
    private var nameable: Nameable? = null

    [`This`]
    private var data: Data? = null

    override fun updatedFoo(newValue: String)
    {
        // Kotlin support for null-safety requires !! notation
        data!!.foo().set( newValue)
    }
}


- Tibor

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to