diff --git a/compiler/cli/cli-common/build.gradle.kts b/compiler/cli/cli-common/build.gradle.kts index 1bf384c94d2..9fd7ae56c88 100644 --- a/compiler/cli/cli-common/build.gradle.kts +++ b/compiler/cli/cli-common/build.gradle.kts @@ -14,7 +14,6 @@ dependencies { compileOnly(intellijCore()) compileOnly(commonDependency("com.google.guava:guava")) compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all")) - compileOnly(project(":kotlin-gradle-compiler-types")) } sourceSets { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index a0a29b22363..79c0e60114c 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -32,7 +32,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { var autoAdvanceLanguageVersion: Boolean by FreezableVar(true) @GradleOption( - value = DefaultValues.LanguageVersions::class, + value = DefaultValue.LANGUAGE_VERSIONS, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -46,7 +46,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { var autoAdvanceApiVersion: Boolean by FreezableVar(true) @GradleOption( - value = DefaultValues.ApiVersions::class, + value = DefaultValue.API_VERSIONS, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -303,7 +303,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { var checkStickyPhaseConditions: Boolean by FreezableVar(false) @GradleOption( - DefaultValues.BooleanFalseDefault::class, + DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument( diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt index aec11efad21..8fa96b273dd 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt @@ -39,21 +39,21 @@ abstract class CommonToolArguments : Freezable(), Serializable { var version: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INTERNAL ) @Argument(value = "-verbose", description = "Enable verbose logging output") var verbose: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INTERNAL ) @Argument(value = "-nowarn", description = "Generate no warnings") var suppressWarnings: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-Werror", description = "Report an error if there are any warnings") diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/GradleOption.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/GradleOption.kt index 78806f5bf6f..5e14865875d 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/GradleOption.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/GradleOption.kt @@ -20,14 +20,32 @@ import kotlin.reflect.KClass import kotlin.reflect.KVisibility /** + * @param value should be one of [DefaultValue] constants * @param gradleInputType should be one of [GradleInputTypes] constants */ @Retention(AnnotationRetention.RUNTIME) annotation class GradleOption( - val value: KClass, + val value: Int, val gradleInputType: String ) +// Enum class here is not possible due to bug in K2 compiler: +// https://youtrack.jetbrains.com/issue/KT-54079 +object DefaultValue { + const val BOOLEAN_FALSE_DEFAULT = 0 + const val BOOLEAN_TRUE_DEFAULT = 1 + const val STRING_NULL_DEFAULT = 2 + const val EMPTY_STRING_LIST_DEFAULT = 3 + const val LANGUAGE_VERSIONS = 4 + const val API_VERSIONS = 5 + const val JVM_TARGET_VERSIONS = 6 + const val JS_ECMA_VERSIONS = 7 + const val JS_MODULE_KINDS = 8 + const val JS_SOURCE_MAP_CONTENT_MODES = 9 + const val JS_MAIN = 10 + const val JS_SOURCE_MAP_NAMES_POLICY = 11 +} + // Enum class here is not possible due to bug in K2 compiler: // https://youtrack.jetbrains.com/issue/KT-54079 object GradleInputTypes { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index df12c87636f..fb89e4e8ab1 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -17,7 +17,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() { } @GradleOption( - value = DefaultValues.StringNullDefault::class, + value = DefaultValue.STRING_NULL_DEFAULT, gradleInputType = GradleInputTypes.INTERNAL // handled by task 'outputFileProperty' ) @GradleDeprecatedOption( @@ -32,14 +32,14 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var outputDir: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.StringNullDefault::class, + value = DefaultValue.STRING_NULL_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-ir-output-name", description = "Base name of generated files") var moduleName: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.BooleanTrueDefault::class, + value = DefaultValue.BOOLEAN_TRUE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-no-stdlib", description = "Don't automatically include the default Kotlin/JS stdlib into compilation dependencies") @@ -60,14 +60,14 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var repositries: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-source-map", description = "Generate source map") var sourceMap: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.StringNullDefault::class, + value = DefaultValue.STRING_NULL_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-source-map-prefix", description = "Add the specified prefix to paths in the source map") @@ -86,7 +86,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() { * When sourceMapEmbedSources are not null and source maps is disabled warning is reported. */ @GradleOption( - value = DefaultValues.JsSourceMapContentModes::class, + value = DefaultValue.JS_SOURCE_MAP_CONTENT_MODES, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -97,7 +97,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var sourceMapEmbedSources: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.JsSourceMapNamesPolicies::class, + value = DefaultValue.JS_SOURCE_MAP_NAMES_POLICY, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -108,14 +108,14 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var sourceMapNamesPolicy: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.BooleanTrueDefault::class, + value = DefaultValue.BOOLEAN_TRUE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-meta-info", description = "Generate .meta.js and .kjsm files with metadata. Use to create a library") var metaInfo: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.JsEcmaVersions::class, + value = DefaultValue.JS_ECMA_VERSIONS, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for specific ECMA version") @@ -129,7 +129,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var irKeep: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.JsModuleKinds::class, + value = DefaultValue.JS_MODULE_KINDS, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -140,7 +140,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var moduleKind: String? by NullableStringFreezableVar(K2JsArgumentConstants.MODULE_PLAIN) @GradleOption( - value = DefaultValues.JsMain::class, + value = DefaultValue.JS_MAIN, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -280,14 +280,14 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var strictImplicitExportType: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.BooleanTrueDefault::class, + value = DefaultValue.BOOLEAN_TRUE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays") var typedArrays: Boolean by FreezableVar(true) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export") diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt index 109bc244f6a..4c6fdbf2d75 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt @@ -14,7 +14,7 @@ class K2JSDceArguments : CommonToolArguments() { } @GradleOption( - value = DefaultValues.StringNullDefault::class, + value = DefaultValue.STRING_NULL_DEFAULT, gradleInputType = GradleInputTypes.INTERNAL // handled by 'destinationDirectory' ) @GradleDeprecatedOption( @@ -43,7 +43,7 @@ class K2JSDceArguments : CommonToolArguments() { var printReachabilityInfo: Boolean by FreezableVar(false) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument( diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index a4dc912ba76..a8db4bd1caf 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -37,7 +37,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var jdkHome: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-no-jdk", description = "Don't automatically include the Java runtime into the classpath") @@ -67,14 +67,14 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var scriptTemplates: Array? by FreezableVar(null) @GradleOption( - value = DefaultValues.StringNullDefault::class, + value = DefaultValue.STRING_NULL_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-module-name", valueDescription = "", description = "Name of the generated .kotlin_module file") var moduleName: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.JvmTargetVersions::class, + value = DefaultValue.JVM_TARGET_VERSIONS, gradleInputType = GradleInputTypes.INPUT ) @Argument( @@ -85,7 +85,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var jvmTarget: String? by NullableStringFreezableVar(null) @GradleOption( - value = DefaultValues.BooleanFalseDefault::class, + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "-java-parameters", description = "Generate metadata for Java 1.8 reflection on method parameters") diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/DefaultValues.kt similarity index 96% rename from compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt rename to generators/tests/org/jetbrains/kotlin/generators/arguments/DefaultValues.kt index 107e48ce028..286668a0ae1 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/DefaultValues.kt @@ -1,10 +1,11 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.cli.common.arguments +package org.jetbrains.kotlin.generators.arguments +import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL import org.jetbrains.kotlin.config.ApiVersion diff --git a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt index 9c4e18a858e..7c727064978 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt @@ -21,7 +21,7 @@ import kotlin.reflect.full.withNullability @Suppress("unused") interface AdditionalGradleProperties { @GradleOption( - value = DefaultValues.EmptyStringListDefault::class, + value = DefaultValue.EMPTY_STRING_LIST_DEFAULT, gradleInputType = GradleInputTypes.INPUT ) @Argument(value = "", description = "A list of additional compiler arguments") @@ -551,7 +551,7 @@ private fun Printer.generateImpl( val defaultValue = it.gradleValues var value = defaultValue.defaultValue if (value != "null" && defaultValue.toArgumentConverter != null) { - value = "$value${defaultValue.toArgumentConverter!!.substringAfter("this")}" + value = "$value${defaultValue.toArgumentConverter.substringAfter("this")}" } println("args.${it.name} = $value") } @@ -726,7 +726,23 @@ private fun generateMarkdown(properties: List>) { } private val KProperty1<*, *>.gradleValues: DefaultValues - get() = findAnnotation()!!.value.objectInstance!! + get() = findAnnotation()!!.value.run { + when (this) { + DefaultValue.BOOLEAN_FALSE_DEFAULT -> DefaultValues.BooleanFalseDefault + DefaultValue.BOOLEAN_TRUE_DEFAULT -> DefaultValues.BooleanTrueDefault + DefaultValue.STRING_NULL_DEFAULT -> DefaultValues.StringNullDefault + DefaultValue.EMPTY_STRING_LIST_DEFAULT -> DefaultValues.EmptyStringListDefault + DefaultValue.JVM_TARGET_VERSIONS -> DefaultValues.JvmTargetVersions + DefaultValue.LANGUAGE_VERSIONS -> DefaultValues.LanguageVersions + DefaultValue.API_VERSIONS -> DefaultValues.ApiVersions + DefaultValue.JS_MAIN -> DefaultValues.JsMain + DefaultValue.JS_ECMA_VERSIONS -> DefaultValues.JsEcmaVersions + DefaultValue.JS_MODULE_KINDS -> DefaultValues.JsModuleKinds + DefaultValue.JS_SOURCE_MAP_CONTENT_MODES -> DefaultValues.JsSourceMapContentModes + DefaultValue.JS_SOURCE_MAP_NAMES_POLICY -> DefaultValues.JsSourceMapNamesPolicies + else -> throw IllegalArgumentException("Unknown GradleOption value type: $this") + } + } private val KProperty1<*, *>.gradleDefaultValue: String get() = gradleValues.defaultValue