tracer.util.createFile.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ksp-util Show documentation
Show all versions of ksp-util Show documentation
"Remember to use with my sample which hasn't come out yet."
package tracer.util
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
// 1.0.7 or +
@Synchronized
// use 'synchronized' because codeGenerator contains a non-concurrent map.
// todo: undo 'synchronized' after authoritative fix.
/**
* Integrates [CodeGenerator.createNewFile] and [CodeGenerator.createNewFileByPath] with nullable [packageName],
* and simplifies with [content].
*/
public fun CodeGenerator.createFile(
packageName: String?,
fileName: String,
dependencies: Dependencies,
content: String,
extensionName: String = "kt",
) {
when (packageName) {
null -> createNewFileByPath(dependencies, fileName, extensionName)
else -> createNewFile(dependencies, packageName, fileName, extensionName)
}.run {
write(content.toByteArray())
close()
}
}
// 1.0.6
// @Synchronized
// use 'synchronized' because codeGenerator contains a non-concurrent map.
// todo: undo 'synchronized' after authoritative fix.
// public fun CodeGenerator.createFile(
// packageName: String,
// fileName: String,
// dependencies: Dependencies,
// content: String,
// extensionName: String = "kt",
// ) {
// createNewFile(
// dependencies, packageName, fileName, extensionName
// ).run {
// write(content.toByteArray())
// close()
// }
// }
© 2015 - 2025 Weber Informatics LLC | Privacy Policy