From ad6b7ee58360bbf6d1a53137a576e46d0bfb2f7a Mon Sep 17 00:00:00 2001 From: Vankka Date: Thu, 13 Jan 2022 19:34:53 +0200 Subject: [PATCH] Add some missing nullability annotations --- .../com/discordsrv/api/discord/api/DiscordAPI.java | 1 + .../api/discord/api/entity/guild/DiscordGuild.java | 6 ++++++ .../discord/api/entity/guild/DiscordGuildMember.java | 4 ++++ .../api/discord/api/entity/guild/DiscordRole.java | 4 ++-- .../api/entity/message/ReceivedDiscordMessage.java | 2 ++ .../entity/message/ReceivedDiscordMessageCluster.java | 5 +++++ .../discordsrv/common/discord/api/DiscordAPIImpl.java | 2 +- .../discord/api/entity/guild/DiscordGuildImpl.java | 11 ++++++----- .../api/entity/guild/DiscordGuildMemberImpl.java | 6 +++--- .../message/ReceivedDiscordMessageClusterImpl.java | 7 ++++--- .../entity/message/ReceivedDiscordMessageImpl.java | 4 ++-- 11 files changed, 36 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/com/discordsrv/api/discord/api/DiscordAPI.java b/api/src/main/java/com/discordsrv/api/discord/api/DiscordAPI.java index 569711b5..d5b40d37 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/DiscordAPI.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/DiscordAPI.java @@ -86,6 +86,7 @@ public interface DiscordAPI { * @param id the id for the Discord user * @return a future that will result in a {@link DiscordUser} for the id or throw a */ + @NotNull CompletableFuture retrieveUserById(long id); /** diff --git a/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuild.java b/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuild.java index aa2224cb..cefededd 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuild.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuild.java @@ -27,6 +27,7 @@ import com.discordsrv.api.DiscordSRVApi; import com.discordsrv.api.discord.api.entity.Snowflake; import com.discordsrv.api.placeholder.annotation.Placeholder; import net.dv8tion.jda.api.entities.Guild; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -42,6 +43,7 @@ public interface DiscordGuild extends Snowflake { * @return the guild's name */ @Placeholder("server_name") + @NotNull String getName(); /** @@ -56,12 +58,14 @@ public interface DiscordGuild extends Snowflake { * @param id the id for the Discord guild member * @return the Discord guild member from the cache */ + @NotNull Optional getMemberById(long id); /** * Gets the members of this server that are in the cache. * @return the Discord server members that are currently cached */ + @NotNull Set getCachedMembers(); /** @@ -69,12 +73,14 @@ public interface DiscordGuild extends Snowflake { * @param id the id for the Discord role * @return the Discord role from the cache */ + @NotNull Optional getRoleById(long id); /** * Gets the roles in this Discord server. * @return an ordered list of the roles in this Discord server */ + @NotNull List getRoles(); /** diff --git a/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuildMember.java b/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuildMember.java index f470b5b5..d4faf025 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuildMember.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordGuildMember.java @@ -43,6 +43,7 @@ public interface DiscordGuildMember extends DiscordUser, Mentionable { * Gets the Discord server this member is from. * @return the Discord server this member is from. */ + @NotNull DiscordGuild getGuild(); /** @@ -56,6 +57,7 @@ public interface DiscordGuildMember extends DiscordUser, Mentionable { * Gets the roles of this Discord server member. * @return the server member's roles in order from highest to lowest, this does not include the "@everyone" role */ + @NotNull List getRoles(); /** @@ -63,6 +65,7 @@ public interface DiscordGuildMember extends DiscordUser, Mentionable { * @return the Discord server member's effective name */ @Placeholder("user_effective_name") + @NotNull default String getEffectiveName() { return getNickname().orElseGet(this::getUsername); } @@ -72,6 +75,7 @@ public interface DiscordGuildMember extends DiscordUser, Mentionable { * @return the user's avatar url in this server */ @Placeholder("user_effective_avatar_url") + @NotNull String getEffectiveServerAvatarUrl(); /** diff --git a/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordRole.java b/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordRole.java index 8e346801..ffdb550b 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordRole.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/entity/guild/DiscordRole.java @@ -45,8 +45,8 @@ public interface DiscordRole extends Snowflake, Mentionable { * Gets the name of the Discord role. * @return the role name */ - @NotNull @Placeholder("role_name") + @NotNull String getName(); /** @@ -62,8 +62,8 @@ public interface DiscordRole extends Snowflake, Mentionable { * @return the color of this role, or {@link #DEFAULT_COLOR} if there is no color set * @see #hasColor() */ - @NotNull @Placeholder("role_color") + @NotNull Color getColor(); /** diff --git a/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessage.java b/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessage.java index 68415b23..9897343d 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessage.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessage.java @@ -45,6 +45,7 @@ public interface ReceivedDiscordMessage extends SendableDiscordMessage, Snowflak * Gets the attachments of this message. * @return this message's attachments */ + @NotNull List getAttachments(); /** @@ -65,6 +66,7 @@ public interface ReceivedDiscordMessage extends SendableDiscordMessage, Snowflak * Gets the channel the message was sent in. * @return the channel the message was sent in */ + @NotNull DiscordMessageChannel getChannel(); /** diff --git a/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessageCluster.java b/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessageCluster.java index 3588c310..a3e9b2e7 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessageCluster.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/entity/message/ReceivedDiscordMessageCluster.java @@ -23,6 +23,8 @@ package com.discordsrv.api.discord.api.entity.message; +import org.jetbrains.annotations.NotNull; + import java.util.List; import java.util.concurrent.CompletableFuture; @@ -35,12 +37,14 @@ public interface ReceivedDiscordMessageCluster { * Gets the messages in this cluster. * @return the messages in this cluster */ + @NotNull List getMessages(); /** * Deletes all the messages from this cluster, one request per message. * @return a future that fails if any of the requests fail. */ + @NotNull CompletableFuture deleteAll(); /** @@ -48,6 +52,7 @@ public interface ReceivedDiscordMessageCluster { * @param newMessage the new content of the messages * @return a future that fails if any of the requests fail. */ + @NotNull CompletableFuture editAll(SendableDiscordMessage newMessage); } diff --git a/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIImpl.java b/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIImpl.java index 4c9cbf7c..ee2831a0 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIImpl.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIImpl.java @@ -371,7 +371,7 @@ public class DiscordAPIImpl implements DiscordAPI { } @Override - public CompletableFuture retrieveUserById(long id) { + public @NotNull CompletableFuture retrieveUserById(long id) { JDA jda = discordSRV.jda().orElse(null); if (jda == null) { return notReady(); diff --git a/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildImpl.java b/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildImpl.java index 44dd1c88..314105e6 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildImpl.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildImpl.java @@ -25,6 +25,7 @@ import com.discordsrv.common.DiscordSRV; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; +import org.jetbrains.annotations.NotNull; import java.util.*; @@ -44,7 +45,7 @@ public class DiscordGuildImpl implements DiscordGuild { } @Override - public String getName() { + public @NotNull String getName() { return guild.getName(); } @@ -54,7 +55,7 @@ public class DiscordGuildImpl implements DiscordGuild { } @Override - public Optional getMemberById(long id) { + public @NotNull Optional getMemberById(long id) { Member member = guild.getMemberById(id); if (member == null) { return Optional.empty(); @@ -64,7 +65,7 @@ public class DiscordGuildImpl implements DiscordGuild { } @Override - public Set getCachedMembers() { + public @NotNull Set getCachedMembers() { Set members = new HashSet<>(); for (Member member : guild.getMembers()) { members.add(new DiscordGuildMemberImpl(discordSRV, member)); @@ -73,7 +74,7 @@ public class DiscordGuildImpl implements DiscordGuild { } @Override - public Optional getRoleById(long id) { + public @NotNull Optional getRoleById(long id) { Role role = guild.getRoleById(id); if (role == null) { return Optional.empty(); @@ -83,7 +84,7 @@ public class DiscordGuildImpl implements DiscordGuild { } @Override - public List getRoles() { + public @NotNull List getRoles() { List roles = new ArrayList<>(); for (Role role : guild.getRoles()) { roles.add(new DiscordRoleImpl(role)); diff --git a/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildMemberImpl.java b/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildMemberImpl.java index 26b8610e..fa85c130 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildMemberImpl.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/entity/guild/DiscordGuildMemberImpl.java @@ -59,7 +59,7 @@ public class DiscordGuildMemberImpl extends DiscordUserImpl implements DiscordGu } @Override - public DiscordGuild getGuild() { + public @NotNull DiscordGuild getGuild() { return guild; } @@ -69,12 +69,12 @@ public class DiscordGuildMemberImpl extends DiscordUserImpl implements DiscordGu } @Override - public List getRoles() { + public @NotNull List getRoles() { return roles; } @Override - public String getEffectiveServerAvatarUrl() { + public @NotNull String getEffectiveServerAvatarUrl() { return member.getEffectiveAvatarUrl(); } diff --git a/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageClusterImpl.java b/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageClusterImpl.java index 46f04e87..5130c8e7 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageClusterImpl.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageClusterImpl.java @@ -21,6 +21,7 @@ package com.discordsrv.common.discord.api.entity.message; import com.discordsrv.api.discord.api.entity.message.ReceivedDiscordMessage; import com.discordsrv.api.discord.api.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.api.entity.message.SendableDiscordMessage; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -35,13 +36,13 @@ public class ReceivedDiscordMessageClusterImpl implements ReceivedDiscordMessage } @Override - public List getMessages() { + public @NotNull List getMessages() { return messages; } @SuppressWarnings("unchecked") @Override - public CompletableFuture deleteAll() { + public @NotNull CompletableFuture deleteAll() { CompletableFuture[] futures = new CompletableFuture[messages.size()]; for (int i = 0; i < messages.size(); i++) { futures[i] = messages.get(i).delete(); @@ -52,7 +53,7 @@ public class ReceivedDiscordMessageClusterImpl implements ReceivedDiscordMessage @SuppressWarnings("unchecked") @Override - public CompletableFuture editAll(SendableDiscordMessage newMessage) { + public @NotNull CompletableFuture editAll(SendableDiscordMessage newMessage) { CompletableFuture[] futures = new CompletableFuture[messages.size()]; for (int i = 0; i < messages.size(); i++) { futures[i] = messages.get(i).edit(newMessage); diff --git a/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageImpl.java b/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageImpl.java index 80c37d74..68f958a3 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageImpl.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/entity/message/ReceivedDiscordMessageImpl.java @@ -218,7 +218,7 @@ public class ReceivedDiscordMessageImpl extends SendableDiscordMessageImpl imple } @Override - public List getAttachments() { + public @NotNull List getAttachments() { return attachments; } @@ -252,7 +252,7 @@ public class ReceivedDiscordMessageImpl extends SendableDiscordMessageImpl imple } @Override - public DiscordMessageChannel getChannel() { + public @NotNull DiscordMessageChannel getChannel() { return channel; }