tieskedh / KotlinPoetDSL

A DSL for KotlinPoet
https://kotlinpoetdsl.devhaan.nl
MIT License
27 stars 0 forks source link

attachTo and attach #21

Closed tieskedh closed 5 years ago

tieskedh commented 6 years ago

Merging the modifiers is strange. Therefor, drop all the functions that accept a Spec, (except from accept).

Add instead extension-function attach and attachTo. attachTo will have 2 parameters, a mendatory Acceptor, where the spec will be attached to and a builder-function, to modify the spec. attach will be the same, but it replaces the mendatory acceptor with the Acceptor.

buildClazz{
    clazz("Hi"){
        someFunSpec.attach()
        someOtherFunSpec.attach{
            replaceModifiers(KModifier.OPEN, KModifier.OPEN)            
        }
    }
}

This will give the user themselves the choice to add the function with Spec and how to implement them. Functions like that should be documented as well.

(attachTo could be added later, when KotlinPoetDSL tries to be more composable)