diff --git a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt index dbb6c20d56b..58088b148a9 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt @@ -39,17 +39,19 @@ interface AdditionalGradleProperties { object EmptyList : DefaultValues("emptyList()") } -fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()->Unit)->Unit) { +fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() -> Unit) -> Unit) { val apiSrcDir = File("libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin") val srcDir = File("libraries/tools/kotlin-gradle-plugin/src/main/kotlin") // common interface val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions") - val commonOptions = gradleOptions() + val commonOptions = gradleOptions() val additionalOptions = gradleOptions() - withPrinterToFile(File(apiSrcDir, commonInterfaceFqName)) { - generateInterface(commonInterfaceFqName, - commonOptions + additionalOptions) + withPrinterToFile(file(apiSrcDir, commonInterfaceFqName)) { + generateInterface( + commonInterfaceFqName, + commonOptions + additionalOptions + ) } println("### Attributes common for JVM, JS, and JS DCE\n") @@ -57,10 +59,12 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() val commonCompilerInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions") val commonCompilerOptions = gradleOptions() - withPrinterToFile(File(apiSrcDir, commonCompilerInterfaceFqName)) { - generateInterface(commonCompilerInterfaceFqName, - commonCompilerOptions, - parentType = commonInterfaceFqName) + withPrinterToFile(file(apiSrcDir, commonCompilerInterfaceFqName)) { + generateInterface( + commonCompilerInterfaceFqName, + commonCompilerOptions, + parentType = commonInterfaceFqName + ) } println("\n### Attributes common for JVM and JS\n") @@ -69,20 +73,24 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() // generate jvm interface val jvmInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions") val jvmOptions = gradleOptions() - withPrinterToFile(File(srcDir, jvmInterfaceFqName)) { - generateInterface(jvmInterfaceFqName, - jvmOptions, - parentType = commonCompilerInterfaceFqName) + withPrinterToFile(file(srcDir, jvmInterfaceFqName)) { + generateInterface( + jvmInterfaceFqName, + jvmOptions, + parentType = commonCompilerInterfaceFqName + ) } // generate jvm impl val k2JvmCompilerArgumentsFqName = FqName(K2JVMCompilerArguments::class.qualifiedName!!) val jvmImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsBase") - withPrinterToFile(File(srcDir, jvmImplFqName)) { - generateImpl(jvmImplFqName, - jvmInterfaceFqName, - k2JvmCompilerArgumentsFqName, - commonOptions + commonCompilerOptions + jvmOptions) + withPrinterToFile(file(srcDir, jvmImplFqName)) { + generateImpl( + jvmImplFqName, + jvmInterfaceFqName, + k2JvmCompilerArgumentsFqName, + commonOptions + commonCompilerOptions + jvmOptions + ) } println("\n### Attributes specific for JVM\n") @@ -91,19 +99,23 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() // generate js interface val jsInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions") val jsOptions = gradleOptions() - withPrinterToFile(File(srcDir, jsInterfaceFqName)) { - generateInterface(jsInterfaceFqName, - jsOptions, - parentType = commonCompilerInterfaceFqName) + withPrinterToFile(file(srcDir, jsInterfaceFqName)) { + generateInterface( + jsInterfaceFqName, + jsOptions, + parentType = commonCompilerInterfaceFqName + ) } val k2JsCompilerArgumentsFqName = FqName(K2JSCompilerArguments::class.qualifiedName!!) val jsImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsBase") - withPrinterToFile(File(srcDir, jsImplFqName)) { - generateImpl(jsImplFqName, - jsInterfaceFqName, - k2JsCompilerArgumentsFqName, - commonOptions + commonCompilerOptions + jsOptions) + withPrinterToFile(file(srcDir, jsImplFqName)) { + generateImpl( + jsImplFqName, + jsInterfaceFqName, + k2JsCompilerArgumentsFqName, + commonOptions + commonCompilerOptions + jsOptions + ) } println("\n### Attributes specific for JS\n") @@ -112,43 +124,51 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() // generate JS DCE interface and implementation val jsDceInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptions") val jsDceOptions = gradleOptions() - withPrinterToFile(File(srcDir, jsDceInterfaceFqName)) { - generateInterface(jsDceInterfaceFqName, - jsDceOptions, - parentType = commonInterfaceFqName) + withPrinterToFile(file(srcDir, jsDceInterfaceFqName)) { + generateInterface( + jsDceInterfaceFqName, + jsDceOptions, + parentType = commonInterfaceFqName + ) } val k2JsDceArgumentsFqName = FqName(K2JSDceArguments::class.qualifiedName!!) val jsDceImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptionsBase") - withPrinterToFile(File(srcDir, jsDceImplFqName)) { - generateImpl(jsDceImplFqName, - jsDceInterfaceFqName, - k2JsDceArgumentsFqName, - commonOptions + jsDceOptions) + withPrinterToFile(file(srcDir, jsDceImplFqName)) { + generateImpl( + jsDceImplFqName, + jsDceInterfaceFqName, + k2JsDceArgumentsFqName, + commonOptions + jsDceOptions + ) } // generate multiplatform common interface and implementation val multiplatformCommonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonOptions") val multiplatformCommonOptions = gradleOptions() - withPrinterToFile(File(srcDir, multiplatformCommonInterfaceFqName)) { - generateInterface(multiplatformCommonInterfaceFqName, - multiplatformCommonOptions, - parentType = commonCompilerInterfaceFqName) + withPrinterToFile(file(srcDir, multiplatformCommonInterfaceFqName)) { + generateInterface( + multiplatformCommonInterfaceFqName, + multiplatformCommonOptions, + parentType = commonCompilerInterfaceFqName + ) } val k2metadataCompilerArgumentsFqName = FqName(K2MetadataCompilerArguments::class.qualifiedName!!) val multiplatformCommonImplFqName = FqName(multiplatformCommonInterfaceFqName.asString() + "Base") - withPrinterToFile(File(srcDir, multiplatformCommonImplFqName)) { - generateImpl(multiplatformCommonImplFqName, - multiplatformCommonInterfaceFqName, - k2metadataCompilerArgumentsFqName, - commonOptions + commonCompilerOptions + multiplatformCommonOptions) + withPrinterToFile(file(srcDir, multiplatformCommonImplFqName)) { + generateImpl( + multiplatformCommonImplFqName, + multiplatformCommonInterfaceFqName, + k2metadataCompilerArgumentsFqName, + commonOptions + commonCompilerOptions + multiplatformCommonOptions + ) } } fun main() { - fun getPrinter(file: File, fn: Printer.()->Unit) { + fun getPrinter(file: File, fn: Printer.() -> Unit) { if (!file.exists()) { file.parentFile.mkdirs() file.createNewFile() @@ -170,9 +190,9 @@ private inline fun List>.filterToBeDeleted() } private inline fun gradleOptions(): List> = - T::class.declaredMemberProperties.filter { it.findAnnotation() != null }.filterToBeDeleted().sortedBy { it.name } + T::class.declaredMemberProperties.filter { it.findAnnotation() != null }.filterToBeDeleted().sortedBy { it.name } -private fun File(baseDir: File, fqName: FqName): File { +private fun file(baseDir: File, fqName: FqName): File { val fileRelativePath = fqName.asString().replace(".", "/") + ".kt" return File(baseDir, fileRelativePath) } @@ -190,10 +210,10 @@ private fun Printer.generateInterface(type: FqName, properties: List> + type: FqName, + parentType: FqName, + argsType: FqName, + properties: List> ) { generateDeclaration("internal abstract class", type, afterType = ": $parentType") { fun KProperty1<*, *>.backingField(): String = "${this.name}Field" @@ -241,10 +261,10 @@ private fun Printer.generateImpl( } private fun Printer.generateDeclaration( - modifiers: String, - type: FqName, - afterType: String? = null, - generateBody: Printer.()->Unit + modifiers: String, + type: FqName, + afterType: String? = null, + generateBody: Printer.() -> Unit ) { println("// DO NOT EDIT MANUALLY!") println("// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt") @@ -288,7 +308,7 @@ private fun Printer.generateDoc(property: KProperty1<*, *>) { println(" */") } -private inline fun Printer.withIndent(fn: Printer.()->Unit) { +private inline fun Printer.withIndent(fn: Printer.() -> Unit) { pushIndent() fn() popIndent() @@ -315,10 +335,10 @@ private fun generateMarkdown(properties: List>) { } private val KProperty1<*, *>.gradleValues: DefaultValues - get() = findAnnotation()!!.value.objectInstance!! + get() = findAnnotation()!!.value.objectInstance!! private val KProperty1<*, *>.gradleDefaultValue: String - get() = gradleValues.defaultValue + get() = gradleValues.defaultValue private val KProperty1<*, *>.gradleBackingFieldVisibility: KVisibility get() { @@ -330,17 +350,17 @@ private val KProperty1<*, *>.gradleBackingFieldVisibility: KVisibility } private val KProperty1<*, *>.gradleReturnType: String - get() { - // Set nullability based on Gradle default value - var type = returnType.withNullability(false).toString().substringBeforeLast("!") - if (gradleDefaultValue == "null") { - type += "?" - } - return type + get() { + // Set nullability based on Gradle default value + var type = returnType.withNullability(false).toString().substringBeforeLast("!") + if (gradleDefaultValue == "null") { + type += "?" } + return type + } private inline fun KAnnotatedElement.findAnnotation(): T? = - annotations.filterIsInstance().firstOrNull() + annotations.filterIsInstance().firstOrNull() object DeprecatedOptionAnnotator { fun generateOptionAnnotation(annotation: DeprecatedOption): String { diff --git a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateKotlinGradleOptionsTest.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateKotlinGradleOptionsTest.kt index 610bba5225a..3bb739a5178 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateKotlinGradleOptionsTest.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateKotlinGradleOptionsTest.kt @@ -14,6 +14,7 @@ * limitations under the License. */ +@file:Suppress("PackageDirectoryMismatch") package org.jetbrains.kotlin.generators.arguments.test import junit.framework.TestCase @@ -26,7 +27,7 @@ import java.io.PrintStream class GenerateKotlinGradleOptionsTest : TestCase() { fun testKotlinGradleOptionsAreUpToDate() { - fun getPrinter(file: File, fn: Printer.()->Unit) { + fun getPrinter(file: File, fn: Printer.() -> Unit) { val bytesOut = ByteArrayOutputStream() PrintStream(bytesOut).use {