Skip to content

Commit 84b0a0d

Browse files
Add compliance tests for common patterns (discord-jda#2746)
* Add compliance test for rest action annotations * Add compliance test for future annotations * Add compliance test for nullability annotations
1 parent 426a320 commit 84b0a0d

File tree

115 files changed

+485
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+485
-12
lines changed

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ dependencies {
163163
testImplementation(libs.assertj)
164164
testImplementation(libs.commons.lang3)
165165
testImplementation(libs.logback.classic)
166+
testImplementation(libs.archunit)
166167
}
167168

168169

settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencyResolutionManagement {
2424
library("reflections", "org.reflections", "reflections" ).version("0.10.2")
2525
library("slf4j", "org.slf4j", "slf4j-api" ).version("2.0.13")
2626
library("tink", "com.google.crypto.tink", "tink" ).version("1.14.1")
27+
library("archunit", "com.tngtech.archunit", "archunit" ).version("1.3.0")
2728
}
2829
}
2930
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.dv8tion.jda.annotations;
18+
19+
import java.lang.annotation.*;
20+
21+
@Documented
22+
@Retention(RetentionPolicy.RUNTIME)
23+
@Target({ElementType.METHOD})
24+
public @interface UnknownNullability
25+
{
26+
}

src/main/java/net/dv8tion/jda/api/JDA.java

+3
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,13 @@ public int getShardTotal()
186186
*
187187
* @return A String representing the information used to build this shard.
188188
*/
189+
@Nonnull
189190
public String getShardString()
190191
{
191192
return "[" + shardId + " / " + shardTotal + "]";
192193
}
193194

195+
@Nonnull
194196
@Override
195197
public String toString()
196198
{
@@ -282,6 +284,7 @@ public boolean equals(Object o)
282284
* @see #getGatewayPing()
283285
*/
284286
@Nonnull
287+
@CheckReturnValue
285288
default RestAction<Long> getRestPing()
286289
{
287290
AtomicLong time = new AtomicLong();

src/main/java/net/dv8tion/jda/api/OnlineStatus.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package net.dv8tion.jda.api;
1717

18+
import javax.annotation.Nonnull;
19+
1820
/**
1921
* Represents the online presence of a {@link net.dv8tion.jda.api.entities.Member Member}.
2022
*/
@@ -63,6 +65,7 @@ public enum OnlineStatus
6365
*
6466
* @see <a href="https://discord.com/developers/docs/topics/gateway#presence-update">PRESENCE_UPDATE</a>
6567
*/
68+
@Nonnull
6669
public String getKey()
6770
{
6871
return key;
@@ -77,7 +80,8 @@ public String getKey()
7780
*
7881
* @return The matching {@link net.dv8tion.jda.api.OnlineStatus OnlineStatus}. If there is no match, returns {@link net.dv8tion.jda.api.OnlineStatus#UNKNOWN UNKNOWN}.
7982
*/
80-
public static OnlineStatus fromKey(String key)
83+
@Nonnull
84+
public static OnlineStatus fromKey(@Nonnull String key)
8185
{
8286
for (OnlineStatus onlineStatus : values())
8387
{

src/main/java/net/dv8tion/jda/api/audit/ActionType.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
2323
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
2424

25+
import javax.annotation.Nonnull;
26+
2527
/**
2628
* ActionTypes for {@link net.dv8tion.jda.api.audit.AuditLogEntry AuditLogEntry} instances
2729
* <br>Found via {@link net.dv8tion.jda.api.audit.AuditLogEntry#getType() AuditLogEntry.getType()}
@@ -684,11 +686,13 @@ public int getKey()
684686
*
685687
* @return {@link net.dv8tion.jda.api.audit.TargetType TargetType}
686688
*/
689+
@Nonnull
687690
public TargetType getTargetType()
688691
{
689692
return target;
690693
}
691694

695+
@Nonnull
692696
public static ActionType from(int key)
693697
{
694698
for (ActionType type : values())

src/main/java/net/dv8tion/jda/api/audit/AuditLogKey.java

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import net.dv8tion.jda.api.entities.sticker.GuildSticker;
3434
import net.dv8tion.jda.internal.utils.EntityString;
3535

36+
import javax.annotation.Nonnull;
37+
3638
/**
3739
* Enum of possible/expected keys that can be provided
3840
* to {@link AuditLogEntry#getChangeByKey(AuditLogKey) AuditLogEntry.getChangeByKey(AuditLogEntry.AuditLogKey}.
@@ -686,11 +688,13 @@ public enum AuditLogKey
686688
this.key = key;
687689
}
688690

691+
@Nonnull
689692
public String getKey()
690693
{
691694
return key;
692695
}
693696

697+
@Nonnull
694698
@Override
695699
public String toString()
696700
{

src/main/java/net/dv8tion/jda/api/audit/AuditLogOption.java

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import net.dv8tion.jda.internal.utils.EntityString;
2020

21+
import javax.annotation.Nonnull;
22+
2123
/**
2224
* Enum constants for possible options
2325
* <br>Providing detailed description of possible occasions and expected types.
@@ -139,6 +141,7 @@ public enum AuditLogOption
139141
*
140142
* @return Key for this option
141143
*/
144+
@Nonnull
142145
public String getKey()
143146
{
144147
return key;

src/main/java/net/dv8tion/jda/api/entities/ClientType.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public enum ClientType
4747
*
4848
* @return The raw key
4949
*/
50+
@Nonnull
5051
public String getKey()
5152
{
5253
return key;

src/main/java/net/dv8tion/jda/api/entities/Entitlement.java

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ default String getApplicationId()
7979
*
8080
* @return The id of the user that purchased the {@link Entitlement Entitlement}
8181
*/
82+
@Nonnull
8283
default String getUserId()
8384
{
8485
return Long.toUnsignedString(getUserIdLong());

src/main/java/net/dv8tion/jda/api/entities/Guild.java

+6
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,7 @@ default RestAction<RichCustomEmoji> retrieveEmoji(@Nonnull CustomEmoji emoji)
23222322
* @return The Manager of this Guild
23232323
*/
23242324
@Nonnull
2325+
@CheckReturnValue
23252326
GuildManager getManager();
23262327

23272328
/**
@@ -2827,6 +2828,7 @@ default Task<List<Member>> findMembersWithRoles(@Nonnull Role... roles)
28272828
* @see #unloadMember(long)
28282829
*/
28292830
@Nonnull
2831+
@CheckReturnValue
28302832
default CacheRestAction<Member> retrieveMember(@Nonnull UserSnowflake user)
28312833
{
28322834
Checks.notNull(user, "User");
@@ -2862,6 +2864,7 @@ default CacheRestAction<Member> retrieveMember(@Nonnull UserSnowflake user)
28622864
* @see #retrieveMemberById(long)
28632865
*/
28642866
@Nonnull
2867+
@CheckReturnValue
28652868
default CacheRestAction<Member> retrieveOwner()
28662869
{
28672870
return retrieveMemberById(getOwnerIdLong());
@@ -2898,6 +2901,7 @@ default CacheRestAction<Member> retrieveOwner()
28982901
* @see #unloadMember(long)
28992902
*/
29002903
@Nonnull
2904+
@CheckReturnValue
29012905
default CacheRestAction<Member> retrieveMemberById(@Nonnull String id)
29022906
{
29032907
return retrieveMemberById(MiscUtil.parseSnowflake(id));
@@ -2929,6 +2933,7 @@ default CacheRestAction<Member> retrieveMemberById(@Nonnull String id)
29292933
* @see #unloadMember(long)
29302934
*/
29312935
@Nonnull
2936+
@CheckReturnValue
29322937
CacheRestAction<Member> retrieveMemberById(long id);
29332938

29342939
/**
@@ -3950,6 +3955,7 @@ default AuditableRestAction<Void> timeoutFor(@Nonnull UserSnowflake user, @Nonnu
39503955
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
39513956
*/
39523957
@Nonnull
3958+
@CheckReturnValue
39533959
AuditableRestAction<Void> removeTimeout(@Nonnull UserSnowflake user);
39543960

39553961
/**

src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.dv8tion.jda.internal.entities.GuildWelcomeScreenImpl;
2727
import net.dv8tion.jda.internal.utils.Checks;
2828

29+
import javax.annotation.CheckReturnValue;
2930
import javax.annotation.Nonnull;
3031
import javax.annotation.Nullable;
3132
import java.util.List;
@@ -66,6 +67,7 @@ public interface GuildWelcomeScreen
6667
* @see Guild#modifyWelcomeScreen()
6768
*/
6869
@Nonnull
70+
@CheckReturnValue
6971
GuildWelcomeScreenManager getManager();
7072

7173
/**

src/main/java/net/dv8tion/jda/api/entities/Invite.java

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public interface Invite
6565
* <br>The Invite object
6666
*/
6767
@Nonnull
68+
@CheckReturnValue
6869
static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String code)
6970
{
7071
return resolve(api, code, false);
@@ -91,6 +92,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
9192
* <br>The Invite object
9293
*/
9394
@Nonnull
95+
@CheckReturnValue
9496
static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String code, final boolean withCounts)
9597
{
9698
return InviteImpl.resolve(api, code, withCounts);

src/main/java/net/dv8tion/jda/api/entities/Message.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2382,8 +2382,9 @@ default MessageCreateAction forwardTo(@Nonnull MessageChannel channel)
23822382
*
23832383
* @return A specific {@link ThreadChannelAction} that may be used to configure the new ThreadChannel before its creation.
23842384
*/
2385+
@Nonnull
23852386
@CheckReturnValue
2386-
ThreadChannelAction createThreadChannel(String name);
2387+
ThreadChannelAction createThreadChannel(@Nonnull String name);
23872388

23882389
/**
23892390
* Mention constants, useful for use with {@link java.util.regex.Pattern Patterns}

src/main/java/net/dv8tion/jda/api/entities/MessageReference.java

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import net.dv8tion.jda.internal.requests.RestActionImpl;
3030
import net.dv8tion.jda.internal.utils.Checks;
3131

32+
import javax.annotation.CheckReturnValue;
3233
import javax.annotation.Nonnull;
3334
import javax.annotation.Nullable;
3435

@@ -102,6 +103,7 @@ public MessageReference(int type, long messageId, long channelId, long guildId,
102103
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Message}
103104
*/
104105
@Nonnull
106+
@CheckReturnValue
105107
public RestAction<Message> resolve()
106108
{
107109
return resolve(true);
@@ -146,6 +148,7 @@ public RestAction<Message> resolve()
146148
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Message}
147149
*/
148150
@Nonnull
151+
@CheckReturnValue
149152
public RestAction<Message> resolve(boolean update)
150153
{
151154
checkPermission(Permission.VIEW_CHANNEL);

src/main/java/net/dv8tion/jda/api/entities/PermissionOverride.java

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public interface PermissionOverride extends ISnowflake
182182
* @return The PermissionOverrideAction of this override.
183183
*/
184184
@Nonnull
185+
@CheckReturnValue
185186
PermissionOverrideAction getManager();
186187

187188
/**

src/main/java/net/dv8tion/jda/api/entities/RichPresence.java

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public interface RichPresence extends Activity
8484
* @see ActivityFlag
8585
* @see ActivityFlag#getFlags(int)
8686
*/
87+
@Nonnull
8788
EnumSet<ActivityFlag> getFlagSet();
8889

8990
/**

src/main/java/net/dv8tion/jda/api/entities/Role.java

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ default RoleAction createCopy()
238238
* @return The RoleManager of this Role
239239
*/
240240
@Nonnull
241+
@CheckReturnValue
241242
RoleManager getManager();
242243

243244
/**

src/main/java/net/dv8tion/jda/api/entities/ScheduledEvent.java

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ default JDA getJDA()
305305
* @return The ScheduledEventManager of this event
306306
*/
307307
@Nonnull
308+
@CheckReturnValue
308309
ScheduledEventManager getManager();
309310

310311
/**

src/main/java/net/dv8tion/jda/api/entities/SelfUser.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.dv8tion.jda.api.JDA;
1919
import net.dv8tion.jda.api.managers.AccountManager;
2020

21+
import javax.annotation.CheckReturnValue;
2122
import javax.annotation.Nonnull;
2223

2324
/**
@@ -84,5 +85,6 @@ default String getApplicationId()
8485
* @return An AccountManager instance for the current account
8586
*/
8687
@Nonnull
88+
@CheckReturnValue
8789
AccountManager getManager();
8890
}

src/main/java/net/dv8tion/jda/api/entities/Webhook.java

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public interface Webhook extends ISnowflake, WebhookClient<Message>
297297
* @return The {@link WebhookManager WebhookManager} for this Webhook
298298
*/
299299
@Nonnull
300+
@CheckReturnValue
300301
WebhookManager getManager();
301302

302303
/**

src/main/java/net/dv8tion/jda/api/entities/automod/AutoModRule.java

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.dv8tion.jda.api.managers.AutoModRuleManager;
2727
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
2828

29+
import javax.annotation.CheckReturnValue;
2930
import javax.annotation.Nonnull;
3031
import java.util.EnumSet;
3132
import java.util.List;
@@ -225,6 +226,7 @@ default String getCreatorId()
225226
* @return The manager instance
226227
*/
227228
@Nonnull
229+
@CheckReturnValue
228230
default AutoModRuleManager getManager()
229231
{
230232
return getGuild().modifyAutoModRuleById(getId());
@@ -239,6 +241,7 @@ default AutoModRuleManager getManager()
239241
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link Void}
240242
*/
241243
@Nonnull
244+
@CheckReturnValue
242245
default AuditableRestAction<Void> delete()
243246
{
244247
return getGuild().deleteAutoModRuleById(getId());

src/main/java/net/dv8tion/jda/api/entities/channel/attribute/ICategorizableChannel.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
2121
import net.dv8tion.jda.api.managers.channel.attribute.ICategorizableChannelManager;
2222

23+
import javax.annotation.CheckReturnValue;
2324
import javax.annotation.Nonnull;
2425
import javax.annotation.Nullable;
2526

@@ -35,6 +36,7 @@ public interface ICategorizableChannel extends GuildChannel, IPermissionContaine
3536
{
3637
@Override
3738
@Nonnull
39+
@CheckReturnValue
3840
ICategorizableChannelManager<?, ?> getManager();
3941

4042
/**

src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPermissionContainer.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public interface IPermissionContainer extends GuildChannel
4040
{
4141
@Override
4242
@Nonnull
43+
@CheckReturnValue
4344
IPermissionContainerManager<?, ?> getManager();
4445

4546
/**

0 commit comments

Comments
 (0)