Skip to content

Commit

Permalink
Add compliance test for rest action annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Oct 5, 2024
1 parent 57f7c0a commit 53782f7
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ dependencies {
testImplementation(libs.assertj)
testImplementation(libs.commons.lang3)
testImplementation(libs.logback.classic)
testImplementation(libs.archunit)
}


Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencyResolutionManagement {
library("reflections", "org.reflections", "reflections" ).version("0.10.2")
library("slf4j", "org.slf4j", "slf4j-api" ).version("2.0.13")
library("tink", "com.google.crypto.tink", "tink" ).version("1.14.1")
library("archunit", "com.tngtech.archunit", "archunit" ).version("1.3.0")
}
}
}
1 change: 1 addition & 0 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public boolean equals(Object o)
* @see #getGatewayPing()
*/
@Nonnull
@CheckReturnValue
default RestAction<Long> getRestPing()
{
AtomicLong time = new AtomicLong();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Invite.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public interface Invite
* <br>The Invite object
*/
@Nonnull
@CheckReturnValue
static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String code)
{
return resolve(api, code, false);
Expand All @@ -91,6 +92,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
* <br>The Invite object
*/
@Nonnull
@CheckReturnValue
static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String code, final boolean withCounts)
{
return InviteImpl.resolve(api, code, withCounts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -102,6 +103,7 @@ public MessageReference(int type, long messageId, long channelId, long guildId,
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Message}
*/
@Nonnull
@CheckReturnValue
public RestAction<Message> resolve()
{
return resolve(true);
Expand Down Expand Up @@ -146,6 +148,7 @@ public RestAction<Message> resolve()
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Message}
*/
@Nonnull
@CheckReturnValue
public RestAction<Message> resolve(boolean update)
{
checkPermission(Permission.VIEW_CHANNEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public Template(final JDAImpl api, final String code, final String name, final S
* <br>The Template object
*/
@Nonnull
@CheckReturnValue
public static RestAction<Template> resolve(final JDA api, final String code)
{
Checks.notEmpty(code, "code");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Set;
Expand Down Expand Up @@ -128,6 +129,7 @@ public Set<String> getCFRays()
}

@Nonnull
@CheckReturnValue
public RestAction<?> getRestAction()
{
return this.request.getRestAction();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/dv8tion/jda/api/managers/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ static boolean isPermissionChecksEnabled()

@Nonnull
@Override
@CheckReturnValue
M setCheck(BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
M timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
@Override
@CheckReturnValue
M deadline(long timestamp);

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.dv8tion.jda.api.requests;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
Expand All @@ -35,24 +36,28 @@ public interface FluentRestAction<T, R extends FluentRestAction<T, R>> extends R
{
@Nonnull
@Override
@CheckReturnValue
R setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
default R addCheck(@Nonnull BooleanSupplier checks)
{
return (R) RestAction.super.addCheck(checks);
}

@Nonnull
@Override
@CheckReturnValue
default R timeout(long timeout, @Nonnull TimeUnit unit)
{
return (R) RestAction.super.timeout(timeout, unit);
}

@Nonnull
@Override
@CheckReturnValue
default R deadline(long timestamp)
{
return (R) RestAction.super.deadline(timestamp);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dv8tion/jda/api/requests/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import okhttp3.RequestBody;
import org.apache.commons.collections4.map.CaseInsensitiveMap;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -204,6 +205,7 @@ public JDAImpl getJDA()
}

@Nonnull
@CheckReturnValue
public RestAction<T> getRestAction()
{
return restAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.pagination.AuditLogPaginationAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -66,20 +67,23 @@ public interface AuditableRestAction<T> extends RestAction<T>
* @see ThreadLocalReason
*/
@Nonnull
@CheckReturnValue
AuditableRestAction<T> reason(@Nullable String reason);

/**
* {@inheritDoc}
*/
@Nonnull
@Override
@CheckReturnValue
AuditableRestAction<T> setCheck(@Nullable BooleanSupplier checks);

/**
* {@inheritDoc}
*/
@Nonnull
@Override
@CheckReturnValue
default AuditableRestAction<T> timeout(long timeout, @Nonnull TimeUnit unit)
{
return (AuditableRestAction<T>) RestAction.super.timeout(timeout, unit);
Expand All @@ -90,6 +94,7 @@ default AuditableRestAction<T> timeout(long timeout, @Nonnull TimeUnit unit)
*/
@Nonnull
@Override
@CheckReturnValue
default AuditableRestAction<T> deadline(long timestamp)
{
return (AuditableRestAction<T>) RestAction.super.deadline(timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,28 @@ public interface CacheRestAction<T> extends RestAction<T>
{
@Nonnull
@Override
@CheckReturnValue
CacheRestAction<T> setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
default CacheRestAction<T> addCheck(@Nonnull BooleanSupplier checks)
{
return (CacheRestAction<T>) RestAction.super.addCheck(checks);
}

@Nonnull
@Override
@CheckReturnValue
default CacheRestAction<T> timeout(long timeout, @Nonnull TimeUnit unit)
{
return (CacheRestAction<T>) RestAction.super.timeout(timeout, unit);
}

@Nonnull
@Override
@CheckReturnValue
default CacheRestAction<T> deadline(long timestamp)
{
return (CacheRestAction<T>) RestAction.super.deadline(timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ public interface CommandCreateAction extends RestAction<Command>, SlashCommandDa
{
@Nonnull
@Override
@CheckReturnValue
CommandCreateAction setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
CommandCreateAction addCheck(@Nonnull BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
CommandCreateAction timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
Expand Down Expand Up @@ -171,5 +174,6 @@ default CommandCreateAction addSubcommandGroups(@Nonnull Collection<? extends Su

@Nonnull
@Override
@CheckReturnValue
CommandCreateAction setNSFW(boolean nsfw);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,22 @@ public interface CommandListUpdateAction extends RestAction<List<Command>>
{
@Nonnull
@Override
@CheckReturnValue
CommandListUpdateAction timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
@Override
@CheckReturnValue
CommandListUpdateAction deadline(long timestamp);

@Nonnull
@Override
@CheckReturnValue
CommandListUpdateAction setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
CommandListUpdateAction addCheck(@Nonnull BooleanSupplier checks);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.dv8tion.jda.api.requests.restaction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
Expand All @@ -35,28 +36,33 @@ public interface FluentAuditableRestAction<T, R extends FluentAuditableRestActio
{
@Nonnull
@Override
@CheckReturnValue
R reason(@Nullable String reason);

@Nonnull
@Override
@CheckReturnValue
R setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
default R addCheck(@Nonnull BooleanSupplier checks)
{
return (R) AuditableRestAction.super.addCheck(checks);
}

@Nonnull
@Override
@CheckReturnValue
default R timeout(long timeout, @Nonnull TimeUnit unit)
{
return (R) AuditableRestAction.super.timeout(timeout, unit);
}

@Nonnull
@Override
@CheckReturnValue
default R deadline(long timestamp)
{
return (R) AuditableRestAction.super.deadline(timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ public interface GuildAction extends RestAction<Void>
{
@Nonnull
@Override
@CheckReturnValue
GuildAction setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
GuildAction timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
@Override
@CheckReturnValue
GuildAction deadline(long timestamp);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ public interface InviteAction extends AuditableRestAction<Invite>
{
@Nonnull
@Override
@CheckReturnValue
InviteAction setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
InviteAction timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
@Override
@CheckReturnValue
InviteAction deadline(long timestamp);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public interface MemberAction extends RestAction<Void>
{
@Nonnull
@Override
@CheckReturnValue
MemberAction setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
MemberAction timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
@Override
@CheckReturnValue
MemberAction deadline(long timestamp);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ public interface PermissionOverrideAction extends AuditableRestAction<Permission
{
@Nonnull
@Override
@CheckReturnValue
PermissionOverrideAction setCheck(@Nullable BooleanSupplier checks);

@Nonnull
@Override
@CheckReturnValue
PermissionOverrideAction timeout(long timeout, @Nonnull TimeUnit unit);

@Nonnull
@Override
@CheckReturnValue
PermissionOverrideAction deadline(long timestamp);

/**
Expand Down
Loading

0 comments on commit 53782f7

Please sign in to comment.