Is there a way to influence/process the KotlinPoet...
# squarelibraries
v
Is there a way to influence/process the KotlinPoet output text after it has been generated and before it is written to the output directory? I would like to plugin some formatter on the generated code before it is written to disk but I cannot immediately find a clean way to do it.
e
You can generate the files then reformat the generated files. You don’t need to plug in anything at generation time. That said, this is the API that KP uses to output code
Copy code
public fun writeTo(out: Appendable) { ... }
You can always implement a delegating Appendable that pre formats the code.
b
What’s the goal of formatting it?
v
I was exploring the options to see if we can nicely format the generated code using ktlint because part of the generated code (and it's a lot of files) are going to end up in the source tree and published in the repository. We currently have ktlint as an additional build step in the repository but it would be nice if we can do it one-shot all from the same parser/generator binary for endusers that use the generator by itself outside of our repo.
the Appendable is likely the easiest way to do it, although then we will have to do a little duplication of the mkdirs/createFile code. which isn't that much work, but I wanted to check if it could be plugged in easily.