Deprecate KmProperty.hasGetter(hasSetter) in favor of KmProperty.getter(setter)
as a follow-up of flag deprecation. #KT-59440
This commit is contained in:
committed by
Space Team
parent
389632ed53
commit
8b821e1feb
@@ -290,17 +290,21 @@ public var KmProperty.kind: MemberKind by memberKindDelegate(KmProperty::flags)
|
||||
|
||||
/**
|
||||
* Indicates that the corresponding property is `var`.
|
||||
*
|
||||
* Note that setting [KmProperty.isVar] to true does not automatically create [KmProperty.setter] and vice versa. This has to be done explicitly.
|
||||
*/
|
||||
public var KmProperty.isVar: Boolean by propertyBooleanFlag(Flag(ProtoFlags.IS_VAR))
|
||||
|
||||
/**
|
||||
* Indicates that the corresponding property has a getter.
|
||||
*/
|
||||
@Deprecated("Kotlin properties always have getters", ReplaceWith("true"), DeprecationLevel.WARNING)
|
||||
public var KmProperty.hasGetter: Boolean by propertyBooleanFlag(Flag(ProtoFlags.HAS_GETTER))
|
||||
|
||||
/**
|
||||
* Indicates that the corresponding property has a setter.
|
||||
*/
|
||||
@Deprecated("Check .setter for nullability instead", ReplaceWith("this.setter != null"), DeprecationLevel.WARNING)
|
||||
public var KmProperty.hasSetter: Boolean by propertyBooleanFlag(Flag(ProtoFlags.HAS_SETTER))
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
package kotlinx.metadata
|
||||
|
||||
import kotlinx.metadata.internal.Flag
|
||||
import kotlinx.metadata.internal.extensions.*
|
||||
import kotlinx.metadata.internal.getDefaultPropertyAccessorFlags
|
||||
import kotlinx.metadata.internal.propertyBooleanFlag
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
|
||||
/**
|
||||
@@ -499,23 +502,29 @@ public class KmProperty @Deprecated(flagsCtorDeprecated) constructor(
|
||||
|
||||
public constructor(name: String) : this(0, name, 0, 0)
|
||||
|
||||
// needed for reading/writing flags back to protobuf as a whole pack
|
||||
private var _hasSetter: Boolean by propertyBooleanFlag(Flag(Flags.HAS_SETTER))
|
||||
private var _hasGetter: Boolean by propertyBooleanFlag(Flag(Flags.HAS_GETTER))
|
||||
|
||||
/**
|
||||
* Attributes of the getter of this property.
|
||||
* Attributes can be retrieved with extension properties, such as [KmPropertyAccessorAttributes.visibility] or [KmPropertyAccessorAttributes.isNotDefault].
|
||||
*
|
||||
* Getter for property is always present, hence return type of this function is non-nullable.
|
||||
*/
|
||||
public val getter: KmPropertyAccessorAttributes = KmPropertyAccessorAttributes(getterFlags)
|
||||
public val getter: KmPropertyAccessorAttributes = KmPropertyAccessorAttributes(getterFlags).also { _hasGetter = true }
|
||||
|
||||
/**
|
||||
* Attributes of the setter of this property.
|
||||
* Attributes can be retrieved with extension properties, such as [KmPropertyAccessorAttributes.visibility] or [KmPropertyAccessorAttributes.isNotDefault].
|
||||
*
|
||||
* Returns null if setter is absent, i.e. [KmProperty.isVar] is false.
|
||||
*
|
||||
* Note that setting [KmProperty.isVar] to true does not automatically create [KmProperty.setter] and vice versa. This has to be done explicitly.
|
||||
*/
|
||||
public var setter: KmPropertyAccessorAttributes? = if (this.hasSetter) KmPropertyAccessorAttributes(setterFlags) else null
|
||||
public var setter: KmPropertyAccessorAttributes? = if (this._hasSetter) KmPropertyAccessorAttributes(setterFlags) else null
|
||||
set(new) {
|
||||
this.hasSetter = new != null
|
||||
this._hasSetter = new != null
|
||||
field = new
|
||||
}
|
||||
|
||||
@@ -547,7 +556,7 @@ public class KmProperty @Deprecated(flagsCtorDeprecated) constructor(
|
||||
* This behavior is for compatibility only and will be removed in future versions.
|
||||
*/
|
||||
@Deprecated("$flagAccessPrefix KmProperty.setter, such as KmProperty.setter.isNotDefault")
|
||||
public var setterFlags: Int = getDefaultPropertyAccessorFlags(flags)
|
||||
public var setterFlags: Int = setterFlags // It's either the correct flags from deserializer, or always 0 in the case of hand-created property
|
||||
get() = setter?.flags ?: field
|
||||
set(value) {
|
||||
setter?.flags = value
|
||||
|
||||
@@ -165,8 +165,8 @@ public fun WriteContext.writeProperty(kmProperty: KmProperty): ProtoBuf.Property
|
||||
t.flags = kmProperty.flags
|
||||
}
|
||||
// TODO: do not write getterFlags/setterFlags if not needed
|
||||
if (kmProperty.hasGetter) t.getterFlags = kmProperty.getterFlags
|
||||
if (kmProperty.hasSetter) t.setterFlags = kmProperty.setterFlags
|
||||
t.getterFlags = kmProperty.getter.flags
|
||||
if (kmProperty.setter != null) t.setterFlags = kmProperty.setter!!.flags
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user