Skip to content

Commit

Permalink
Compatibility for SystemChannelFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Aug 21, 2023
1 parent f6bbd68 commit 916ce0c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
14 changes: 12 additions & 2 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -8549,6 +8549,8 @@ public final class dev/kord/common/entity/SystemChannelFlagKt {

public final class dev/kord/common/entity/SystemChannelFlags {
public static final field Companion Ldev/kord/common/entity/SystemChannelFlags$Companion;
public static final field NewCompanion Ldev/kord/common/entity/SystemChannelFlags$NewCompanion;
public fun <init> (I)V
public final fun component1 ()I
public final fun contains (Ldev/kord/common/entity/SystemChannelFlag;)Z
public final fun contains (Ldev/kord/common/entity/SystemChannelFlags;)Z
Expand All @@ -8571,14 +8573,22 @@ public final class dev/kord/common/entity/SystemChannelFlags$Builder {
public fun <init> (I)V
public synthetic fun <init> (IILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun build ()Ldev/kord/common/entity/SystemChannelFlags;
public final fun flags ()Ldev/kord/common/entity/SystemChannelFlags;
public final fun unaryMinus (Ldev/kord/common/entity/SystemChannelFlag;)V
public final fun unaryMinus (Ldev/kord/common/entity/SystemChannelFlags;)V
public final fun unaryPlus (Ldev/kord/common/entity/SystemChannelFlag;)V
public final fun unaryPlus (Ldev/kord/common/entity/SystemChannelFlags;)V
}

public final class dev/kord/common/entity/SystemChannelFlags$Companion {
public final class dev/kord/common/entity/SystemChannelFlags$Companion : kotlinx/serialization/KSerializer {
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/SystemChannelFlags;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/SystemChannelFlags;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class dev/kord/common/entity/SystemChannelFlags$NewCompanion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

Expand Down
4 changes: 3 additions & 1 deletion common/src/commonMain/kotlin/entity/DiscordGuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@
],
)

/*
@file:Generate(
INT_FLAGS, name = "SystemChannelFlag", valueName = "code", wasEnum = true, collectionWasDataClass = true,
INT_FLAGS, name = "SystemChannelFlag", valueName = "code",
docUrl = "https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags",
entries = [
Entry("SuppressJoinNotifications", shift = 0, kDoc = "Suppress member join notifications."),
Expand All @@ -168,6 +169,7 @@
),
],
)
*/

package dev.kord.common.entity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

Expand Down Expand Up @@ -47,14 +46,14 @@ public sealed class SystemChannelFlag(
* [flag].
*/
public operator fun plus(flag: SystemChannelFlag): SystemChannelFlags =
SystemChannelFlags(this.code or flag.code)
SystemChannelFlags(this.code or flag.code, null)

/**
* Returns an instance of [SystemChannelFlags] that has all bits set that are set in `this` and
* [flags].
*/
public operator fun plus(flags: SystemChannelFlags): SystemChannelFlags =
SystemChannelFlags(this.code or flags.code)
SystemChannelFlags(this.code or flags.code, null)

final override fun equals(other: Any?): Boolean = this === other ||
(other is SystemChannelFlag && this.shift == other.shift)
Expand Down Expand Up @@ -343,7 +342,18 @@ public class SystemChannelFlags internal constructor(
* The raw code used by Discord.
*/
public val code: Int,
@Suppress("UNUSED_PARAMETER") unused: Nothing?,
) {
// TODO uncomment annotation in DiscordGuild.kt and delete this file when this constructor is removed after
// deprecation cycle
@Deprecated(
"Don't construct an instance of 'SystemChannelFlags' from a raw code. Use the factory functions described in " +
"the documentation instead.",
ReplaceWith("SystemChannelFlags.Builder(code).build()", "dev.kord.common.entity.SystemChannelFlags"),
DeprecationLevel.WARNING,
)
public constructor(code: Int) : this(code, null)

/**
* A [Set] of all [SystemChannelFlag]s contained in this instance of [SystemChannelFlags].
*/
Expand Down Expand Up @@ -375,28 +385,28 @@ public class SystemChannelFlags internal constructor(
* [flag].
*/
public operator fun plus(flag: SystemChannelFlag): SystemChannelFlags =
SystemChannelFlags(this.code or flag.code)
SystemChannelFlags(this.code or flag.code, null)

/**
* Returns an instance of [SystemChannelFlags] that has all bits set that are set in `this` and
* [flags].
*/
public operator fun plus(flags: SystemChannelFlags): SystemChannelFlags =
SystemChannelFlags(this.code or flags.code)
SystemChannelFlags(this.code or flags.code, null)

/**
* Returns an instance of [SystemChannelFlags] that has all bits set that are set in `this`
* except the bits that are set in [flag].
*/
public operator fun minus(flag: SystemChannelFlag): SystemChannelFlags =
SystemChannelFlags(this.code and flag.code.inv())
SystemChannelFlags(this.code and flag.code.inv(), null)

/**
* Returns an instance of [SystemChannelFlags] that has all bits set that are set in `this`
* except the bits that are set in [flags].
*/
public operator fun minus(flags: SystemChannelFlags): SystemChannelFlags =
SystemChannelFlags(this.code and flags.code.inv())
SystemChannelFlags(this.code and flags.code.inv(), null)

/**
* Returns a copy of this instance of [SystemChannelFlags] modified with [builder].
Expand Down Expand Up @@ -428,7 +438,7 @@ public class SystemChannelFlags internal constructor(
@Suppress(names = arrayOf("DeprecatedCallableAddReplaceWith"))
@Deprecated(message =
"SystemChannelFlags is no longer a data class. Deprecated without a replacement.")
public fun copy(code: Int = this.code): SystemChannelFlags = SystemChannelFlags(code)
public fun copy(code: Int = this.code): SystemChannelFlags = SystemChannelFlags(code, null)

public class Builder(
private var code: Int = 0,
Expand Down Expand Up @@ -465,16 +475,7 @@ public class SystemChannelFlags internal constructor(
* Returns an instance of [SystemChannelFlags] that has all bits set that are currently set
* in this [Builder].
*/
public fun build(): SystemChannelFlags = SystemChannelFlags(code)

/**
* @suppress
*/
@Deprecated(
message = "Renamed to 'build'",
replaceWith = ReplaceWith(expression = "this.build()", imports = arrayOf()),
)
public fun flags(): SystemChannelFlags = build()
public fun build(): SystemChannelFlags = SystemChannelFlags(code, null)
}

internal object Serializer : KSerializer<SystemChannelFlags> {
Expand All @@ -489,7 +490,27 @@ public class SystemChannelFlags internal constructor(
}

override fun deserialize(decoder: Decoder): SystemChannelFlags =
SystemChannelFlags(decoder.decodeSerializableValue(delegate))
SystemChannelFlags(decoder.decodeSerializableValue(delegate), null)
}

public companion object NewCompanion {
@Suppress("DEPRECATION")
@Deprecated(
"Renamed to 'NewCompanion', which no longer implements 'KSerializer<SystemChannelFlags>'.",
ReplaceWith("SystemChannelFlags.serializer()", imports = ["dev.kord.common.entity.SystemChannelFlags"]),
DeprecationLevel.WARNING,
)
@JvmField
public val Companion: Companion = Companion()
}

@Deprecated(
"Renamed to 'NewCompanion', which no longer implements 'KSerializer<SystemChannelFlags>'.",
ReplaceWith("SystemChannelFlags.serializer()", imports = ["dev.kord.common.entity.SystemChannelFlags"]),
DeprecationLevel.WARNING,
)
public class Companion internal constructor() : KSerializer<SystemChannelFlags> by Serializer {
public fun serializer(): KSerializer<SystemChannelFlags> = this
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/commonTest/kotlin/json/GuildTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GuildTest {
vanityUrlCode shouldBe "discord-testers"
premiumTier shouldBe PremiumTier.Three
premiumSubscriptionCount shouldBe 33
systemChannelFlags shouldBe SystemChannelFlags(0)
systemChannelFlags shouldBe SystemChannelFlags()
preferredLocale shouldBe "en-US"
rulesChannelId shouldBe "441688182833020939"
publicUpdatesChannelId shouldBe "281283303326089216"
Expand Down

0 comments on commit 916ce0c

Please sign in to comment.