https://kotlinlang.org logo
#getting-started
Title
# getting-started
e

Endre Deak

05/19/2022, 11:00 PM
Not sure where does this question belong to, but I’m looking for some simple alternatives to
Poet
where I have full control on the generated Kotlin source code including removing redundant qualifiers, etc. My google research did not lead me any further than just construct the source as a String and write it to a file.
c

Chris Lee

05/19/2022, 11:08 PM
Poet does a great job at generating Kotlin code. As it’s generated, why does it matter if there are redundant qualifiers?
2
m

Matteo Mirk

05/20/2022, 8:13 AM
I’m with Chris, that library (like JavaPoet) is very good and opting for a string template won’t provide you the same level of flexibility and structuring. The reason why those modifiers are generated is stated in the docs:
Note: In order to maximize portability, KotlinPoet generates code with explicit visibility modifiers. This ensures compatibility with both standard Kotlin projects as well as projects using explicit API mode.
If you really really don’t like them, even if it’s generated code, you can add an additional step in your program and remove them before writing to a file.
e

Endre Deak

05/20/2022, 2:27 PM
Thanks for the answers!
5 Views