Switch @GradleOption params to enum classes.
This should improve developers UX when using this annotation.
This commit is contained in:
committed by
Space Team
parent
f308f33f9f
commit
45213e1468
+20
-24
@@ -20,36 +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
|
||||
* @param value should be one of [DefaultValue] enum values
|
||||
* @param gradleInputType should be one of [GradleInputTypes] enum values
|
||||
*/
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class GradleOption(
|
||||
val value: Int,
|
||||
val gradleInputType: String,
|
||||
val value: DefaultValue,
|
||||
val gradleInputType: GradleInputTypes,
|
||||
val shouldGenerateDeprecatedKotlinOptions: Boolean = false
|
||||
)
|
||||
|
||||
// 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 DefaultValue {
|
||||
BOOLEAN_FALSE_DEFAULT,
|
||||
BOOLEAN_TRUE_DEFAULT,
|
||||
STRING_NULL_DEFAULT,
|
||||
EMPTY_STRING_LIST_DEFAULT,
|
||||
LANGUAGE_VERSIONS,
|
||||
API_VERSIONS,
|
||||
JVM_TARGET_VERSIONS,
|
||||
JS_ECMA_VERSIONS,
|
||||
JS_MODULE_KINDS,
|
||||
JS_SOURCE_MAP_CONTENT_MODES,
|
||||
JS_MAIN,
|
||||
JS_SOURCE_MAP_NAMES_POLICY,
|
||||
}
|
||||
|
||||
// Enum class here is not possible due to bug in K2 compiler:
|
||||
// https://youtrack.jetbrains.com/issue/KT-54079
|
||||
object GradleInputTypes {
|
||||
const val INPUT = "org.gradle.api.tasks.Input"
|
||||
const val INTERNAL = "org.gradle.api.tasks.Internal"
|
||||
enum class GradleInputTypes(val gradleType: String) {
|
||||
INPUT("org.gradle.api.tasks.Input"),
|
||||
INTERNAL("org.gradle.api.tasks.Internal")
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.cli.common.arguments.*
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import kotlin.reflect.KAnnotatedElement
|
||||
@@ -557,7 +558,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")
|
||||
}
|
||||
@@ -615,7 +616,7 @@ private fun Printer.generatePropertyProvider(
|
||||
modifiers: String = ""
|
||||
) {
|
||||
if (property.gradleDefaultValue == "null" &&
|
||||
property.gradleInputType == GradleInputTypes.INPUT
|
||||
property.gradleInputTypeAsEnum == GradleInputTypes.INPUT
|
||||
) {
|
||||
println("@get:org.gradle.api.tasks.Optional")
|
||||
}
|
||||
@@ -746,7 +747,6 @@ private val KProperty1<*, *>.gradleValues: DefaultValues
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -793,14 +793,17 @@ private val KProperty1<*, *>.gradleLazyReturnTypeInstantiator: String
|
||||
}
|
||||
}
|
||||
|
||||
private val KProperty1<*, *>.gradleInputType: String get() =
|
||||
findAnnotation<GradleOption>()!!.gradleInputType
|
||||
private val KProperty1<*, *>.gradleInputTypeAsEnum: GradleInputTypes
|
||||
get() = findAnnotation<GradleOption>()!!.gradleInputType
|
||||
|
||||
private val KProperty1<*, *>.gradleInputType: String
|
||||
get() = findAnnotation<GradleOption>()!!.gradleInputType.gradleType
|
||||
|
||||
private val KProperty1<*, *>.generateDeprecatedKotlinOption: Boolean
|
||||
get() = findAnnotation<GradleOption>()!!.shouldGenerateDeprecatedKotlinOptions
|
||||
|
||||
private inline fun <reified T> KAnnotatedElement.findAnnotation(): T? =
|
||||
annotations.filterIsInstance<T>().firstOrNull()
|
||||
annotations.firstIsInstanceOrNull()
|
||||
|
||||
object DeprecatedOptionAnnotator {
|
||||
fun generateOptionAnnotation(annotation: GradleDeprecatedOption): String {
|
||||
|
||||
Reference in New Issue
Block a user