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
-2
@@ -281,12 +281,10 @@ private class MappingExtensions(
|
|||||||
modality = ps.modality.kmModality
|
modality = ps.modality.kmModality
|
||||||
kind = MemberKind.DECLARATION
|
kind = MemberKind.DECLARATION
|
||||||
hasAnnotations = ps.annotations.isNotEmpty()
|
hasAnnotations = ps.annotations.isNotEmpty()
|
||||||
hasGetter = true
|
|
||||||
when (ps.kind) {
|
when (ps.kind) {
|
||||||
is PropertyStub.Kind.Val -> {}
|
is PropertyStub.Kind.Val -> {}
|
||||||
is PropertyStub.Kind.Var -> {
|
is PropertyStub.Kind.Var -> {
|
||||||
isVar = true
|
isVar = true
|
||||||
hasGetter = true
|
|
||||||
}
|
}
|
||||||
is PropertyStub.Kind.Constant -> {
|
is PropertyStub.Kind.Constant -> {
|
||||||
isConst = true
|
isConst = true
|
||||||
|
|||||||
@@ -290,17 +290,21 @@ public var KmProperty.kind: MemberKind by memberKindDelegate(KmProperty::flags)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that the corresponding property is `var`.
|
* 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))
|
public var KmProperty.isVar: Boolean by propertyBooleanFlag(Flag(ProtoFlags.IS_VAR))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that the corresponding property has a getter.
|
* 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))
|
public var KmProperty.hasGetter: Boolean by propertyBooleanFlag(Flag(ProtoFlags.HAS_GETTER))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that the corresponding property has a setter.
|
* 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))
|
public var KmProperty.hasSetter: Boolean by propertyBooleanFlag(Flag(ProtoFlags.HAS_SETTER))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,8 +7,11 @@
|
|||||||
|
|
||||||
package kotlinx.metadata
|
package kotlinx.metadata
|
||||||
|
|
||||||
|
import kotlinx.metadata.internal.Flag
|
||||||
import kotlinx.metadata.internal.extensions.*
|
import kotlinx.metadata.internal.extensions.*
|
||||||
import kotlinx.metadata.internal.getDefaultPropertyAccessorFlags
|
import kotlinx.metadata.internal.getDefaultPropertyAccessorFlags
|
||||||
|
import kotlinx.metadata.internal.propertyBooleanFlag
|
||||||
|
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||||
import kotlin.contracts.ExperimentalContracts
|
import kotlin.contracts.ExperimentalContracts
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -499,23 +502,29 @@ public class KmProperty @Deprecated(flagsCtorDeprecated) constructor(
|
|||||||
|
|
||||||
public constructor(name: String) : this(0, name, 0, 0)
|
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 of the getter of this property.
|
||||||
* Attributes can be retrieved with extension properties, such as [KmPropertyAccessorAttributes.visibility] or [KmPropertyAccessorAttributes.isNotDefault].
|
* 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.
|
* 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 of the setter of this property.
|
||||||
* Attributes can be retrieved with extension properties, such as [KmPropertyAccessorAttributes.visibility] or [KmPropertyAccessorAttributes.isNotDefault].
|
* 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.
|
* 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) {
|
set(new) {
|
||||||
this.hasSetter = new != null
|
this._hasSetter = new != null
|
||||||
field = new
|
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.
|
* This behavior is for compatibility only and will be removed in future versions.
|
||||||
*/
|
*/
|
||||||
@Deprecated("$flagAccessPrefix KmProperty.setter, such as KmProperty.setter.isNotDefault")
|
@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
|
get() = setter?.flags ?: field
|
||||||
set(value) {
|
set(value) {
|
||||||
setter?.flags = value
|
setter?.flags = value
|
||||||
|
|||||||
@@ -165,8 +165,8 @@ public fun WriteContext.writeProperty(kmProperty: KmProperty): ProtoBuf.Property
|
|||||||
t.flags = kmProperty.flags
|
t.flags = kmProperty.flags
|
||||||
}
|
}
|
||||||
// TODO: do not write getterFlags/setterFlags if not needed
|
// TODO: do not write getterFlags/setterFlags if not needed
|
||||||
if (kmProperty.hasGetter) t.getterFlags = kmProperty.getterFlags
|
t.getterFlags = kmProperty.getter.flags
|
||||||
if (kmProperty.hasSetter) t.setterFlags = kmProperty.setterFlags
|
if (kmProperty.setter != null) t.setterFlags = kmProperty.setter!!.flags
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,11 +99,9 @@ private fun visitProperty(
|
|||||||
sb.append(" /* = ... */")
|
sb.append(" /* = ... */")
|
||||||
}
|
}
|
||||||
sb.appendLine()
|
sb.appendLine()
|
||||||
if (property.hasGetter) {
|
sb.append(" ")
|
||||||
sb.append(" ")
|
sb.appendPropertyAccessorModifiers(property.getter)
|
||||||
sb.appendPropertyAccessorModifiers(property.getter)
|
sb.appendLine("get")
|
||||||
sb.appendLine("get")
|
|
||||||
}
|
|
||||||
val setter = property.setter
|
val setter = property.setter
|
||||||
if (setter != null) {
|
if (setter != null) {
|
||||||
sb.append(" ")
|
sb.append(" ")
|
||||||
|
|||||||
@@ -123,9 +123,6 @@ object CirDeserializers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun propertyGetter(source: KmProperty, typeResolver: CirTypeResolver): CirPropertyGetter? {
|
private fun propertyGetter(source: KmProperty, typeResolver: CirTypeResolver): CirPropertyGetter? {
|
||||||
if (!source.hasGetter)
|
|
||||||
return null
|
|
||||||
|
|
||||||
val isDefault = !source.getter.isNotDefault
|
val isDefault = !source.getter.isNotDefault
|
||||||
val annotations = annotations(source.getter.hasAnnotations, typeResolver, source::getterAnnotations)
|
val annotations = annotations(source.getter.hasAnnotations, typeResolver, source::getterAnnotations)
|
||||||
|
|
||||||
@@ -140,9 +137,6 @@ object CirDeserializers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun propertySetter(source: KmProperty, typeResolver: CirTypeResolver): CirPropertySetter? {
|
private fun propertySetter(source: KmProperty, typeResolver: CirTypeResolver): CirPropertySetter? {
|
||||||
if (!source.hasSetter)
|
|
||||||
return null
|
|
||||||
|
|
||||||
val setter = source.setter ?: return null
|
val setter = source.setter ?: return null
|
||||||
|
|
||||||
return CirPropertySetter.createInterned(
|
return CirPropertySetter.createInterned(
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ internal fun KmProperty.modifiersFrom(cp: CirProperty, isExpect: Boolean) {
|
|||||||
visibility = cp.kmVisibility
|
visibility = cp.kmVisibility
|
||||||
modality = cp.kmModality
|
modality = cp.kmModality
|
||||||
kind = cp.kind.kmMemberKind
|
kind = cp.kind.kmMemberKind
|
||||||
hasGetter = cp.getter != null
|
|
||||||
hasSetter = cp.setter != null
|
|
||||||
isDelegated = cp.isDelegate
|
isDelegated = cp.isDelegate
|
||||||
this.isExpect = isExpect
|
this.isExpect = isExpect
|
||||||
isVar = cp.isVar
|
isVar = cp.isVar
|
||||||
|
|||||||
Reference in New Issue
Block a user