I am trying to generate one kotlin class using kotlin poet library which should have one function and one inner static class as given below.
class SampleClass{
class TestClass{
lateinit var id: String
lateinit var name: String
}
fun function1(init: TestClass.() -> Unit) {
val trackPhoneNumberClicked = TestClass().apply(init)
val event = Event.Builder.from(testData.getTestDataById("testdataid")!!)
.apply {
addProperty("id", trackPhoneNumberClicked.id)
addProperty("name", trackPhoneNumberClicked.name)
}
.build()
}
}
I can generate SampleClass and inner class TestClass but I am not able to create function1 with this argument and body.
github like of kotlin poet library. https://github.com/square/kotlinpoet
Can anyone provide any solution for this?
I got the answer that how we can generate
function1(init: TestClass.() -> Unit)
this type of argument in function. We need to use LambdaTypeName class of kotlin poet lib.