You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@polygene.apache.org by Paul Merlin <pa...@apache.org> on 2017/04/24 06:12:28 UTC

Polygene and Kotlin

Gang,

I played a little bit with Polygene and Kotlin:

val application = Energy4Java().newApplication(
     ApplicationAssembler { factory ->
         factory.newApplicationAssembly("Application 1") {
             mode = Application.Mode.development
             version = "1"
             setMetaInfo(Object())
             val layer1 = layer("Layer 1") {
                 module("Module 1/A") {
                     values(Some::class) {
                         withTypes(Some::class)
                         forMixin(Some::class).declareDefaults {
                             foo().set("bar")
                         }
                     }
                 }
             }
             val layer2 = layer("Layer 2") {
                 module("Module 2/A") {
                     services(Some::class) {
                         instantiateOnStartup()
                     }
                 }
             }
             layer2.uses(layer1)
         }
     })
application.activate()
application.passivate()

To get to the code above I added a few Kotlin extensions methods to the 
bootstrap api:
https://kotlinlang.org/docs/reference/extensions.html

I'll push some library/lang-kotlin later, but it looks promising 
already.



Re: Polygene and Kotlin

Posted by Paul Merlin <pa...@apache.org>.
Le 2017-04-24 08:28, Niclas Hedhman a �crit�:
> Cool. I guess the IDE was guiding a lot to get that right...

Yep, a lot.
Everything is strongly typed and you get nice contextual autocomplete 
and all that.

One annoying thing with the bootstrap API is the difference between 
KClass<?> and Class<?>.
Need to add a lot of extension methods.

I did not manage yet to provide Kotlin properties for our properties & 
associations.
This would get us to e.g.:

forMixin(Some::class).declareDefaults {
     foo = "bar"
}

And the same in application code.
But I'm not even sure it's possible with current Kotlin features.
We'll see.



> On Mon, Apr 24, 2017 at 2:12 PM, Paul Merlin <pa...@apache.org> 
> wrote:
> 
>> Gang,
>> 
>> I played a little bit with Polygene and Kotlin:
>> 
>> val application = Energy4Java().newApplication(
>>     ApplicationAssembler { factory ->
>>         factory.newApplicationAssembly("Application 1") {
>>             mode = Application.Mode.development
>>             version = "1"
>>             setMetaInfo(Object())
>>             val layer1 = layer("Layer 1") {
>>                 module("Module 1/A") {
>>                     values(Some::class) {
>>                         withTypes(Some::class)
>>                         forMixin(Some::class).declareDefaults {
>>                             foo().set("bar")
>>                         }
>>                     }
>>                 }
>>             }
>>             val layer2 = layer("Layer 2") {
>>                 module("Module 2/A") {
>>                     services(Some::class) {
>>                         instantiateOnStartup()
>>                     }
>>                 }
>>             }
>>             layer2.uses(layer1)
>>         }
>>     })
>> application.activate()
>> application.passivate()
>> 
>> To get to the code above I added a few Kotlin extensions methods to 
>> the
>> bootstrap api:
>> https://kotlinlang.org/docs/reference/extensions.html
>> 
>> I'll push some library/lang-kotlin later, but it looks promising 
>> already.
>> 
>> 
>> 



Re: Polygene and Kotlin

Posted by Niclas Hedhman <ni...@hedhman.org>.
Cool. I guess the IDE was guiding a lot to get that right...

On Mon, Apr 24, 2017 at 2:12 PM, Paul Merlin <pa...@apache.org> wrote:

> Gang,
>
> I played a little bit with Polygene and Kotlin:
>
> val application = Energy4Java().newApplication(
>     ApplicationAssembler { factory ->
>         factory.newApplicationAssembly("Application 1") {
>             mode = Application.Mode.development
>             version = "1"
>             setMetaInfo(Object())
>             val layer1 = layer("Layer 1") {
>                 module("Module 1/A") {
>                     values(Some::class) {
>                         withTypes(Some::class)
>                         forMixin(Some::class).declareDefaults {
>                             foo().set("bar")
>                         }
>                     }
>                 }
>             }
>             val layer2 = layer("Layer 2") {
>                 module("Module 2/A") {
>                     services(Some::class) {
>                         instantiateOnStartup()
>                     }
>                 }
>             }
>             layer2.uses(layer1)
>         }
>     })
> application.activate()
> application.passivate()
>
> To get to the code above I added a few Kotlin extensions methods to the
> bootstrap api:
> https://kotlinlang.org/docs/reference/extensions.html
>
> I'll push some library/lang-kotlin later, but it looks promising already.
>
>
>


-- 
Niclas Hedhman, Software Developer
http://polygene.apache.org - New Energy for Java