Change 'jvmTarget' backing property visibility to internal.
Allows to check if this property was updated by the user or not. ^KT-45611 In Progress ^KT-43095 In Progress
This commit is contained in:
+5
-1
@@ -17,6 +17,10 @@
|
||||
package org.jetbrains.kotlin.cli.common.arguments
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class GradleOption(val value: KClass<out DefaultValues> = DefaultValues::class)
|
||||
annotation class GradleOption(
|
||||
val value: KClass<out DefaultValues> = DefaultValues::class,
|
||||
val backingFieldVisibility: KVisibility = KVisibility.PRIVATE
|
||||
)
|
||||
|
||||
+5
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.cli.common.arguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
companion object {
|
||||
@@ -75,7 +76,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file")
|
||||
var moduleName: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.JvmTargetVersions::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.JvmTargetVersions::class,
|
||||
backingFieldVisibility = KVisibility.INTERNAL
|
||||
)
|
||||
@Argument(
|
||||
value = "-jvm-target",
|
||||
valueDescription = "<version>",
|
||||
|
||||
+13
-1
@@ -22,8 +22,10 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.util.*
|
||||
import kotlin.reflect.KAnnotatedElement
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.KVisibility
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
import kotlin.reflect.full.withNullability
|
||||
|
||||
@@ -203,7 +205,8 @@ private fun Printer.generateImpl(
|
||||
generatePropertyDeclaration(property, modifiers = "override", value = "null")
|
||||
} else {
|
||||
val backingField = property.backingField()
|
||||
println("private var $backingField: $propertyType? = null")
|
||||
val visibilityModified = property.gradleBackingFieldVisibility.name.lowercase(Locale.US)
|
||||
println("$visibilityModified var $backingField: $propertyType? = null")
|
||||
generatePropertyDeclaration(property, modifiers = "override")
|
||||
withIndent {
|
||||
println("get() = $backingField ?: ${property.gradleDefaultValue}")
|
||||
@@ -314,6 +317,15 @@ private val KProperty1<*, *>.gradleValues: DefaultValues
|
||||
private val KProperty1<*, *>.gradleDefaultValue: String
|
||||
get() = gradleValues.defaultValue
|
||||
|
||||
private val KProperty1<*, *>.gradleBackingFieldVisibility: KVisibility
|
||||
get() {
|
||||
val fieldVisibility = findAnnotation<GradleOption>()!!.backingFieldVisibility
|
||||
require(fieldVisibility != KVisibility.PUBLIC) {
|
||||
"Backing field should not have public visibility!"
|
||||
}
|
||||
return fieldVisibility
|
||||
}
|
||||
|
||||
private val KProperty1<*, *>.gradleReturnType: String
|
||||
get() {
|
||||
// Set nullability based on Gradle default value
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ internal abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.K
|
||||
|
||||
override var jdkHome: kotlin.String? = null
|
||||
|
||||
private var jvmTargetField: kotlin.String? = null
|
||||
internal var jvmTargetField: kotlin.String? = null
|
||||
override var jvmTarget: kotlin.String
|
||||
get() = jvmTargetField ?: "1.8"
|
||||
set(value) {
|
||||
|
||||
Reference in New Issue
Block a user