All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tracer.util.createFile.kt Maven / Gradle / Ivy

There is a newer version: 1.8.0-1.0.2
Show newest version
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