Generate Js runtime diagnostic mode type

^KT-27301 In Progress
This commit is contained in:
Yahor Berdnikau
2022-08-30 14:36:33 +02:00
parent c1ed683ed8
commit 5eebcf8c77
3 changed files with 46 additions and 0 deletions
@@ -38,6 +38,7 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile)
generateJsModuleKind(apiSrcDir, withPrinterToFile)
generateJsSourceMapEmbedMode(apiSrcDir, withPrinterToFile)
generateJsDiagnosticMode(apiSrcDir, withPrinterToFile)
// common interface
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
@@ -103,3 +103,33 @@ internal fun generateJsSourceMapEmbedMode(
}
}
}
internal fun generateJsDiagnosticMode(
apiDir: File,
filePrinter: (targetFile: File, Printer.() -> Unit) -> Unit
) {
val diagnosticModeFqName = FqName("org.jetbrains.kotlin.gradle.dsl.JsDiagnosticMode")
filePrinter(file(apiDir, diagnosticModeFqName)) {
generateDeclaration("enum class", diagnosticModeFqName, afterType = "(val mode: String)") {
val mods = hashMapOf(
K2JsArgumentConstants::RUNTIME_DIAGNOSTIC_EXCEPTION.name to K2JsArgumentConstants.RUNTIME_DIAGNOSTIC_EXCEPTION,
K2JsArgumentConstants::RUNTIME_DIAGNOSTIC_LOG.name to K2JsArgumentConstants.RUNTIME_DIAGNOSTIC_LOG,
)
val lastIndex = mods.size - 1
mods.entries.forEachIndexed { index, mode ->
val lastChar = if (index == lastIndex) ";" else ","
println("${mode.key}(\"${mode.value}\")$lastChar")
}
println()
println("companion object {")
withIndent {
println("fun fromMode(mode: String): JsDiagnosticMode =")
println(" JsDiagnosticMode.values().firstOrNull { it.mode == mode }")
println(" ?: throw IllegalArgumentException(\"Unknown JS diagnostic mode: ${'$'}mode\")")
}
println("}")
}
}
}
@@ -0,0 +1,15 @@
// DO NOT EDIT MANUALLY!
// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt
package org.jetbrains.kotlin.gradle.dsl
@Suppress("DEPRECATION")
enum class JsDiagnosticMode (val mode: String) {
RUNTIME_DIAGNOSTIC_EXCEPTION("exception"),
RUNTIME_DIAGNOSTIC_LOG("log");
companion object {
fun fromMode(mode: String): JsDiagnosticMode =
JsDiagnosticMode.values().firstOrNull { it.mode == mode }
?: throw IllegalArgumentException("Unknown JS diagnostic mode: $mode")
}
}