These are chat archives for JetBrains/kotlin

11th
Jun 2017
Michael
@mkulak
Jun 11 2017 11:54

I want to generate simple data class with KotlinPoet:
data class User(val id: Int)

I do it like that:

   val builder = KotlinFile.builder("", "Foo")
    val classBuilder = TypeSpec.classBuilder("User").addModifiers(KModifier.DATA)
    val ctor = FunSpec.constructorBuilder()
    ctor.addParameter("id", Int::class)
    classBuilder.primaryConstructor(ctor.build())
    builder.addType(classBuilder.build())
    builder.build().writeTo(System.out)

Can't find way to add valmodifier to constructor parameter.