-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider adding Filer convenience methods back #105
Comments
I investigated a bit so let me share about it here.
|
Do you have any clue about how to write KotlinPoet generated classes to filer without using the not yet available KotlinPoet api method |
Call toString(), write that as your file contents.
…On Fri, Jul 21, 2017, 2:05 PM Jorge Castillo ***@***.***> wrote:
Do you have any clue about how to write KotlinPoet generated classes to
filer without using the not yet available KotlinPoet api method
writeTo(filer) for it @hotchemi <https://github.com/hotchemi>?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#105 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEYexRlYhhOkRQV43iSpSDFynv3U8ks5sQOhSgaJpZM4Nupmb>
.
|
@JorgeCastilloPrz might be an off topic for this issue but right now we do as below and it works...the reason of |
Im gonna add here another valid executable code sample. It's a repo I'm contributing to where we are also generating Kotlin files and compile time using KotlinPoet API and being able to referentiate those files from production code with no compile time errors: https://github.com/kategory/implicits-processor. Interesting point here: I am just taking the
|
This is what worked for me (inspired by the kotlin-examples processor). In the process method... Get the target generated directory for kapt: val kaptKotlinGeneratedDir = processingEnv.options["kapt.kotlin.generated"] ?:
run {
processingEnv.messager.printMessage(
ERROR,
"Can't find the target directory for generated Kotlin files."
)
return false
} Create your file object: val kotlinFile = KotlinFile.builder("com.example", "KotlinClass.kt")
.addType(TypeSpec.classBuilder("KotlinClass").build())
.build() Write the file: File(
"$kaptKotlinGeneratedDir/${kotlinFile.packageName.replace(".", "/")}",
kotlinFile.fileName
).apply {
parentFile.mkdirs()
writeText(kotlinFile.toString())
} |
Definitely want this now that Kapt is adding support for gradle's incremental kapt support and using the same filer APIs https://github.com/JetBrains/kotlin/pull/2179/files#diff-f5958ff916f88658e65a723fb591467dR142 I can take a swing at this this weekend |
Awesome, please do! |
kapt compiles kt files generated from processors per comments on #93
The text was updated successfully, but these errors were encountered: