Skip to content

Commit

Permalink
Add plus to Flag classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Jul 28, 2023
1 parent 6c29dc3 commit a99c0cc
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public abstract class dev/kord/common/entity/ActivityFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/common/entity/ActivityFlag;)Ldev/kord/common/entity/ActivityFlags;
public final fun plus (Ldev/kord/common/entity/ActivityFlags;)Ldev/kord/common/entity/ActivityFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/common/entity/ActivityFlag;
public static fun values ()[Ldev/kord/common/entity/ActivityFlag;
Expand Down Expand Up @@ -638,6 +640,8 @@ public abstract class dev/kord/common/entity/ApplicationFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/common/entity/ApplicationFlag;)Ldev/kord/common/entity/ApplicationFlags;
public final fun plus (Ldev/kord/common/entity/ApplicationFlags;)Ldev/kord/common/entity/ApplicationFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/common/entity/ApplicationFlag;
public static fun values ()[Ldev/kord/common/entity/ApplicationFlag;
Expand Down Expand Up @@ -6727,6 +6731,8 @@ public abstract class dev/kord/common/entity/GuildMemberFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/common/entity/GuildMemberFlag;)Ldev/kord/common/entity/GuildMemberFlags;
public final fun plus (Ldev/kord/common/entity/GuildMemberFlags;)Ldev/kord/common/entity/GuildMemberFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/common/entity/GuildMemberFlag;
public static fun values ()[Ldev/kord/common/entity/GuildMemberFlag;
Expand Down Expand Up @@ -7298,6 +7304,8 @@ public abstract class dev/kord/common/entity/MessageFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/common/entity/MessageFlag;)Ldev/kord/common/entity/MessageFlags;
public final fun plus (Ldev/kord/common/entity/MessageFlags;)Ldev/kord/common/entity/MessageFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/common/entity/MessageFlag;
public static fun values ()[Ldev/kord/common/entity/MessageFlag;
Expand Down Expand Up @@ -7804,6 +7812,8 @@ public abstract class dev/kord/common/entity/Permission {
public final fun equals (Ljava/lang/Object;)Z
public final fun getCode ()Ldev/kord/common/DiscordBitSet;
public final fun hashCode ()I
public final fun plus (Ldev/kord/common/entity/Permission;)Ldev/kord/common/entity/Permissions;
public final fun plus (Ldev/kord/common/entity/Permissions;)Ldev/kord/common/entity/Permissions;
public final fun toString ()Ljava/lang/String;
}

Expand Down Expand Up @@ -8396,6 +8406,8 @@ public abstract class dev/kord/common/entity/SystemChannelFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/common/entity/SystemChannelFlag;)Ldev/kord/common/entity/SystemChannelFlags;
public final fun plus (Ldev/kord/common/entity/SystemChannelFlags;)Ldev/kord/common/entity/SystemChannelFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/common/entity/SystemChannelFlag;
public static fun values ()[Ldev/kord/common/entity/SystemChannelFlag;
Expand Down Expand Up @@ -8559,6 +8571,8 @@ public abstract class dev/kord/common/entity/UserFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/common/entity/UserFlag;)Ldev/kord/common/entity/UserFlags;
public final fun plus (Ldev/kord/common/entity/UserFlags;)Ldev/kord/common/entity/UserFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/common/entity/UserFlag;
public static fun values ()[Ldev/kord/common/entity/UserFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ public sealed class ActivityFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: ActivityFlag): ActivityFlags =
ActivityFlags(this.code or flag.code)

public operator fun plus(flags: ActivityFlags): ActivityFlags =
ActivityFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is ActivityFlag && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ public sealed class ApplicationFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: ApplicationFlag): ApplicationFlags =
ApplicationFlags(this.code or flag.code)

public operator fun plus(flags: ApplicationFlags): ApplicationFlags =
ApplicationFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is ApplicationFlag && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public sealed class GuildMemberFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: GuildMemberFlag): GuildMemberFlags =
GuildMemberFlags(this.code or flag.code)

public operator fun plus(flags: GuildMemberFlags): GuildMemberFlags =
GuildMemberFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is GuildMemberFlag && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public sealed class MessageFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: MessageFlag): MessageFlags = MessageFlags(this.code or flag.code)

public operator fun plus(flags: MessageFlags): MessageFlags =
MessageFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is MessageFlag && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public sealed class Permission {
this.code = code
}

public operator fun plus(flag: Permission): Permissions = Permissions(this.code + flag.code)

public operator fun plus(flags: Permissions): Permissions = Permissions(this.code + flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is Permission && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ public sealed class SystemChannelFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: SystemChannelFlag): SystemChannelFlags =
SystemChannelFlags(this.code or flag.code)

public operator fun plus(flags: SystemChannelFlags): SystemChannelFlags =
SystemChannelFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is SystemChannelFlag && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public sealed class UserFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: UserFlag): UserFlags = UserFlags(this.code or flag.code)

public operator fun plus(flags: UserFlags): UserFlags = UserFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is UserFlag && this.code == other.code)

Expand Down
2 changes: 2 additions & 0 deletions gateway/api/gateway.api
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ public abstract class dev/kord/gateway/Intent {
public final fun equals (Ljava/lang/Object;)Z
public final fun getCode ()Ldev/kord/common/DiscordBitSet;
public final fun hashCode ()I
public final fun plus (Ldev/kord/gateway/Intent;)Ldev/kord/gateway/Intents;
public final fun plus (Ldev/kord/gateway/Intents;)Ldev/kord/gateway/Intents;
public final fun toString ()Ljava/lang/String;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public sealed class Intent(
*/
public val code: DiscordBitSet = EmptyBitSet().also { it[shift] = true }

public operator fun plus(flag: Intent): Intents = Intents(this.code + flag.code)

public operator fun plus(flags: Intents): Intents = Intents(this.code + flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is Intent && this.code == other.code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ internal fun BitFlags.generateFileSpec(originatingFile: KSFile) = fileSpecForGen
}
}
}
addFunction("plus") {
addModifiers(PUBLIC, OPERATOR)
addParameter("flag", entityCN)
returns(collectionName)
addStatement(
when (valueType) {
INT -> "return %T(this.code·or·flag.code)"
BIT_SET -> "return %T(this.code·+·flag.code)"
},
collectionName,
)
}
addFunction("plus") {
addModifiers(PUBLIC, OPERATOR)
addParameter("flags", collectionName)
returns(collectionName)
addStatement(
when (valueType) {
INT -> "return %T(this.code·or·flags.code)"
BIT_SET -> "return %T(this.code·+·flags.code)"
},
collectionName,
)
}
addEntityEqualsHashCodeToString()
if (wasEnum) {
addDeprecatedEntityEnumArtifacts()
Expand Down
2 changes: 2 additions & 0 deletions voice/api/voice.api
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ public abstract class dev/kord/voice/SpeakingFlag {
public final fun hashCode ()I
public final fun name ()Ljava/lang/String;
public final fun ordinal ()I
public final fun plus (Ldev/kord/voice/SpeakingFlag;)Ldev/kord/voice/SpeakingFlags;
public final fun plus (Ldev/kord/voice/SpeakingFlags;)Ldev/kord/voice/SpeakingFlags;
public final fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Ldev/kord/voice/SpeakingFlag;
public static fun values ()[Ldev/kord/voice/SpeakingFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ public sealed class SpeakingFlag(
*/
public val code: Int = 1 shl shift

public operator fun plus(flag: SpeakingFlag): SpeakingFlags =
SpeakingFlags(this.code or flag.code)

public operator fun plus(flags: SpeakingFlags): SpeakingFlags =
SpeakingFlags(this.code or flags.code)

final override fun equals(other: Any?): Boolean = this === other ||
(other is SpeakingFlag && this.code == other.code)

Expand Down

0 comments on commit a99c0cc

Please sign in to comment.