🚚 Begin migrating from javax annotations to checker-qual

This commit is contained in:
Alexander Söderberg 2020-09-28 16:40:06 +02:00 committed by Alexander Söderberg
parent e914d04450
commit 9f0c846050
43 changed files with 273 additions and 549 deletions

View file

@ -100,7 +100,7 @@ subprojects {
} }
dependencies { dependencies {
api 'com.google.code.findbugs:jsr305:3.0.2' compileOnly 'org.checkerframework:checker-qual:3.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
} }

View file

@ -35,9 +35,9 @@ import cloud.commandframework.permission.Permission;
import cloud.commandframework.types.tuples.Pair; import cloud.commandframework.types.tuples.Pair;
import cloud.commandframework.types.tuples.Triplet; import cloud.commandframework.types.tuples.Triplet;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -55,11 +55,11 @@ import java.util.function.Function;
*/ */
public class Command<C> { public class Command<C> {
@Nonnull private final Map<CommandArgument<C, ?>, Description> arguments; private final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> arguments;
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler; private final CommandExecutionHandler<C> commandExecutionHandler;
@Nullable private final Class<? extends C> senderType; private final Class<? extends C> senderType;
@Nonnull private final CommandPermission commandPermission; private final CommandPermission commandPermission;
@Nonnull private final CommandMeta commandMeta; private final CommandMeta commandMeta;
/** /**
* Construct a new command * Construct a new command
@ -70,11 +70,11 @@ public class Command<C> {
* @param commandPermission Command permission * @param commandPermission Command permission
* @param commandMeta Command meta instance * @param commandMeta Command meta instance
*/ */
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments, public Command(@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler, @NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
@Nullable final Class<? extends C> senderType, @Nullable final Class<? extends C> senderType,
@Nonnull final CommandPermission commandPermission, @NonNull final CommandPermission commandPermission,
@Nonnull final CommandMeta commandMeta) { @NonNull final CommandMeta commandMeta) {
this.arguments = Objects.requireNonNull(commandArguments, "Command arguments may not be null"); this.arguments = Objects.requireNonNull(commandArguments, "Command arguments may not be null");
if (this.arguments.size() == 0) { if (this.arguments.size() == 0) {
throw new IllegalArgumentException("At least one command argument is required"); throw new IllegalArgumentException("At least one command argument is required");
@ -107,10 +107,10 @@ public class Command<C> {
* @param senderType Required sender type. May be {@code null} * @param senderType Required sender type. May be {@code null}
* @param commandMeta Command meta instance * @param commandMeta Command meta instance
*/ */
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments, public Command(@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler, @NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
@Nullable final Class<? extends C> senderType, @Nullable final Class<? extends C> senderType,
@Nonnull final CommandMeta commandMeta) { @NonNull final CommandMeta commandMeta) {
this(commandArguments, commandExecutionHandler, senderType, Permission.empty(), commandMeta); this(commandArguments, commandExecutionHandler, senderType, Permission.empty(), commandMeta);
} }
@ -122,10 +122,10 @@ public class Command<C> {
* @param commandPermission Command permission * @param commandPermission Command permission
* @param commandMeta Command meta instance * @param commandMeta Command meta instance
*/ */
public Command(@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments, public Command(@NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler, @NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
@Nonnull final CommandPermission commandPermission, @NonNull final CommandPermission commandPermission,
@Nonnull final CommandMeta commandMeta) { @NonNull final CommandMeta commandMeta) {
this(commandArguments, commandExecutionHandler, null, commandPermission, commandMeta); this(commandArguments, commandExecutionHandler, null, commandPermission, commandMeta);
} }
@ -140,12 +140,11 @@ public class Command<C> {
* @param <C> Command sender type * @param <C> Command sender type
* @return Command builder * @return Command builder
*/ */
@Nonnull public static <C> @NonNull Builder<C> newBuilder(@NonNull final String commandName,
public static <C> Builder<C> newBuilder(@Nonnull final String commandName, @NonNull final CommandMeta commandMeta,
@Nonnull final CommandMeta commandMeta, @NonNull final Description description,
@Nonnull final Description description, @NonNull final String... aliases) {
@Nonnull final String... aliases) { final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> map = new LinkedHashMap<>();
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
map.put(StaticArgument.required(commandName, aliases), description); map.put(StaticArgument.required(commandName, aliases), description);
return new Builder<>(null, commandMeta, null, map, return new Builder<>(null, commandMeta, null, map,
new CommandExecutionHandler.NullCommandExecutionHandler<>(), Permission.empty()); new CommandExecutionHandler.NullCommandExecutionHandler<>(), Permission.empty());
@ -161,10 +160,9 @@ public class Command<C> {
* @param <C> Command sender type * @param <C> Command sender type
* @return Command builder * @return Command builder
*/ */
@Nonnull public static <C> @NonNull Builder<C> newBuilder(@NonNull final String commandName,
public static <C> Builder<C> newBuilder(@Nonnull final String commandName, @NonNull final CommandMeta commandMeta,
@Nonnull final CommandMeta commandMeta, @NonNull final String... aliases) {
@Nonnull final String... aliases) {
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>(); final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
map.put(StaticArgument.required(commandName, aliases), Description.empty()); map.put(StaticArgument.required(commandName, aliases), Description.empty());
return new Builder<>(null, commandMeta, null, map, return new Builder<>(null, commandMeta, null, map,
@ -176,8 +174,7 @@ public class Command<C> {
* *
* @return Copy of the command argument array * @return Copy of the command argument array
*/ */
@Nonnull public @NonNull List<CommandArgument<@NonNull C, @NonNull ?>> getArguments() {
public List<CommandArgument<C, ?>> getArguments() {
return new ArrayList<>(this.arguments.keySet()); return new ArrayList<>(this.arguments.keySet());
} }
@ -186,8 +183,7 @@ public class Command<C> {
* *
* @return Command execution handler * @return Command execution handler
*/ */
@Nonnull public CommandExecutionHandler<@NonNull C> getCommandExecutionHandler() {
public CommandExecutionHandler<C> getCommandExecutionHandler() {
return this.commandExecutionHandler; return this.commandExecutionHandler;
} }
@ -196,8 +192,7 @@ public class Command<C> {
* *
* @return Required sender type * @return Required sender type
*/ */
@Nonnull public @NonNull Optional<Class<? extends C>> getSenderType() {
public Optional<Class<? extends C>> getSenderType() {
return Optional.ofNullable(this.senderType); return Optional.ofNullable(this.senderType);
} }
@ -206,8 +201,7 @@ public class Command<C> {
* *
* @return Command permission * @return Command permission
*/ */
@Nonnull public @NonNull CommandPermission getCommandPermission() {
public CommandPermission getCommandPermission() {
return this.commandPermission; return this.commandPermission;
} }
@ -216,8 +210,7 @@ public class Command<C> {
* *
* @return Command meta * @return Command meta
*/ */
@Nonnull public @NonNull CommandMeta getCommandMeta() {
public CommandMeta getCommandMeta() {
return this.commandMeta; return this.commandMeta;
} }
@ -227,8 +220,7 @@ public class Command<C> {
* @param argument Argument * @param argument Argument
* @return Argument description * @return Argument description
*/ */
@Nonnull public @NonNull String getArgumentDescription(@NonNull final CommandArgument<C, ?> argument) {
public String getArgumentDescription(@Nonnull final CommandArgument<C, ?> argument) {
return this.arguments.get(argument).getDescription(); return this.arguments.get(argument).getDescription();
} }
@ -260,19 +252,19 @@ public class Command<C> {
*/ */
public static final class Builder<C> { public static final class Builder<C> {
@Nonnull private final CommandMeta commandMeta; private final CommandMeta commandMeta;
@Nonnull private final Map<CommandArgument<C, ?>, Description> commandArguments; private final Map<CommandArgument<C, ?>, Description> commandArguments;
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler; private final CommandExecutionHandler<C> commandExecutionHandler;
@Nullable private final Class<? extends C> senderType; private final Class<? extends C> senderType;
@Nonnull private final CommandPermission commandPermission; private final CommandPermission commandPermission;
@Nullable private final CommandManager<C> commandManager; private final CommandManager<C> commandManager;
private Builder(@Nullable final CommandManager<C> commandManager, private Builder(@Nullable final CommandManager<C> commandManager,
@Nonnull final CommandMeta commandMeta, @NonNull final CommandMeta commandMeta,
@Nullable final Class<? extends C> senderType, @Nullable final Class<? extends C> senderType,
@Nonnull final Map<CommandArgument<C, ?>, Description> commandArguments, @NonNull final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
@Nonnull final CommandExecutionHandler<C> commandExecutionHandler, @NonNull final CommandExecutionHandler<@NonNull C> commandExecutionHandler,
@Nonnull final CommandPermission commandPermission) { @NonNull final CommandPermission commandPermission) {
this.commandManager = commandManager; this.commandManager = commandManager;
this.senderType = senderType; this.senderType = senderType;
this.commandArguments = Objects.requireNonNull(commandArguments, "Arguments may not be null"); this.commandArguments = Objects.requireNonNull(commandArguments, "Arguments may not be null");
@ -288,8 +280,7 @@ public class Command<C> {
* @param value Meta value * @param value Meta value
* @return New builder instance using the inserted meta key-value pair * @return New builder instance using the inserted meta key-value pair
*/ */
@Nonnull public @NonNull Builder<C> meta(@NonNull final String key, @NonNull final String value) {
public Builder<C> meta(@Nonnull final String key, @Nonnull final String value) {
final CommandMeta commandMeta = SimpleCommandMeta.builder().with(this.commandMeta).with(key, value).build(); final CommandMeta commandMeta = SimpleCommandMeta.builder().with(this.commandMeta).with(key, value).build();
return new Builder<>(this.commandManager, commandMeta, this.senderType, this.commandArguments, return new Builder<>(this.commandManager, commandMeta, this.senderType, this.commandArguments,
this.commandExecutionHandler, this.commandPermission); this.commandExecutionHandler, this.commandPermission);
@ -303,8 +294,7 @@ public class Command<C> {
* @param commandManager Command manager * @param commandManager Command manager
* @return New builder instance using the provided command manager * @return New builder instance using the provided command manager
*/ */
@Nonnull public @NonNull Builder<C> manager(@Nullable final CommandManager<C> commandManager) {
public Builder<C> manager(@Nullable final CommandManager<C> commandManager) {
return new Builder<>(commandManager, this.commandMeta, this.senderType, this.commandArguments, return new Builder<>(commandManager, this.commandMeta, this.senderType, this.commandArguments,
this.commandExecutionHandler, this.commandPermission); this.commandExecutionHandler, this.commandPermission);
} }
@ -316,8 +306,8 @@ public class Command<C> {
* @param aliases Argument aliases * @param aliases Argument aliases
* @return New builder instance with the modified command chain * @return New builder instance with the modified command chain
*/ */
@Nonnull public @NonNull Builder<C> literal(@NonNull final String main,
public Builder<C> literal(@Nonnull final String main, @Nonnull final String... aliases) { @NonNull final String... aliases) {
return this.argument(StaticArgument.required(main, aliases)); return this.argument(StaticArgument.required(main, aliases));
} }
@ -329,10 +319,9 @@ public class Command<C> {
* @param aliases Argument aliases * @param aliases Argument aliases
* @return New builder instance with the modified command chain * @return New builder instance with the modified command chain
*/ */
@Nonnull public @NonNull Builder<C> literal(@NonNull final String main,
public Builder<C> literal(@Nonnull final String main, @NonNull final Description description,
@Nonnull final Description description, @NonNull final String... aliases) {
@Nonnull final String... aliases) {
return this.argument(StaticArgument.required(main, aliases), description); return this.argument(StaticArgument.required(main, aliases), description);
} }
@ -343,8 +332,7 @@ public class Command<C> {
* @param <T> Argument type * @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list * @return New builder instance with the command argument inserted into the argument list
*/ */
@Nonnull public <T> @NonNull Builder<C> argument(@NonNull final CommandArgument<C, T> argument) {
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument) {
return this.argument(argument, Description.empty()); return this.argument(argument, Description.empty());
} }
@ -356,9 +344,8 @@ public class Command<C> {
* @param <T> Argument type * @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list * @return New builder instance with the command argument inserted into the argument list
*/ */
@Nonnull public <T> @NonNull Builder<C> argument(@NonNull final CommandArgument<C, T> argument,
public <T> Builder<C> argument(@Nonnull final CommandArgument<C, T> argument, @NonNull final Description description) {
@Nonnull final Description description) {
final Map<CommandArgument<C, ?>, Description> commandArgumentMap = new LinkedHashMap<>(this.commandArguments); final Map<CommandArgument<C, ?>, Description> commandArgumentMap = new LinkedHashMap<>(this.commandArguments);
commandArgumentMap.put(argument, description); commandArgumentMap.put(argument, description);
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArgumentMap, return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArgumentMap,
@ -374,10 +361,9 @@ public class Command<C> {
* @param <T> Argument type * @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list * @return New builder instance with the command argument inserted into the argument list
*/ */
@Nonnull public <T> @NonNull Builder<C> argument(@NonNull final Class<T> clazz,
public <T> Builder<C> argument(@Nonnull final Class<T> clazz, @NonNull final String name,
@Nonnull final String name, @NonNull final Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
@Nonnull final Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
final CommandArgument.Builder<C, T> builder = CommandArgument.ofType(clazz, name); final CommandArgument.Builder<C, T> builder = CommandArgument.ofType(clazz, name);
if (this.commandManager != null) { if (this.commandManager != null) {
builder.manager(this.commandManager); builder.manager(this.commandManager);
@ -524,8 +510,7 @@ public class Command<C> {
* @param commandExecutionHandler New execution handler * @param commandExecutionHandler New execution handler
* @return New builder instance using the command execution handler * @return New builder instance using the command execution handler
*/ */
@Nonnull public @NonNull Builder<C> handler(@NonNull final CommandExecutionHandler<C> commandExecutionHandler) {
public Builder<C> handler(@Nonnull final CommandExecutionHandler<C> commandExecutionHandler) {
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments, return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments,
commandExecutionHandler, this.commandPermission); commandExecutionHandler, this.commandPermission);
} }
@ -536,8 +521,7 @@ public class Command<C> {
* @param senderType Required sender type * @param senderType Required sender type
* @return New builder instance using the command execution handler * @return New builder instance using the command execution handler
*/ */
@Nonnull public @NonNull Builder<C> withSenderType(@NonNull final Class<? extends C> senderType) {
public Builder<C> withSenderType(@Nonnull final Class<? extends C> senderType) {
return new Builder<>(this.commandManager, this.commandMeta, senderType, this.commandArguments, return new Builder<>(this.commandManager, this.commandMeta, senderType, this.commandArguments,
this.commandExecutionHandler, this.commandPermission); this.commandExecutionHandler, this.commandPermission);
} }
@ -548,8 +532,7 @@ public class Command<C> {
* @param permission Command permission * @param permission Command permission
* @return New builder instance using the command permission * @return New builder instance using the command permission
*/ */
@Nonnull public @NonNull Builder<C> withPermission(@NonNull final CommandPermission permission) {
public Builder<C> withPermission(@Nonnull final CommandPermission permission) {
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments, return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments,
this.commandExecutionHandler, permission); this.commandExecutionHandler, permission);
} }
@ -560,8 +543,7 @@ public class Command<C> {
* @param permission Command permission * @param permission Command permission
* @return New builder instance using the command permission * @return New builder instance using the command permission
*/ */
@Nonnull public @NonNull Builder<C> withPermission(@NonNull final String permission) {
public Builder<C> withPermission(@Nonnull final String permission) {
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments, return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments,
this.commandExecutionHandler, Permission.of(permission)); this.commandExecutionHandler, Permission.of(permission));
} }
@ -577,8 +559,7 @@ public class Command<C> {
* @param command Command to proxy * @param command Command to proxy
* @return New builder that proxies the given command * @return New builder that proxies the given command
*/ */
@Nonnull public @NonNull Builder<C> proxies(@NonNull final Command<C> command) {
public Builder<C> proxies(@Nonnull final Command<C> command) {
Builder<C> builder = this; Builder<C> builder = this;
for (final CommandArgument<C, ?> argument : command.getArguments()) { for (final CommandArgument<C, ?> argument : command.getArguments()) {
if (argument instanceof StaticArgument) { if (argument instanceof StaticArgument) {
@ -599,8 +580,7 @@ public class Command<C> {
* *
* @return New builder instance that indicates that the constructed command should be hidden * @return New builder instance that indicates that the constructed command should be hidden
*/ */
@Nonnull public @NonNull Builder<C> hidden() {
public Builder<C> hidden() {
return this.meta("hidden", "true"); return this.meta("hidden", "true");
} }
@ -609,8 +589,7 @@ public class Command<C> {
* *
* @return Built command * @return Built command
*/ */
@Nonnull public @NonNull Command<C> build() {
public Command<C> build() {
return new Command<>(Collections.unmodifiableMap(this.commandArguments), return new Command<>(Collections.unmodifiableMap(this.commandArguments),
this.commandExecutionHandler, this.commandExecutionHandler,
this.senderType, this.senderType,

View file

@ -31,8 +31,6 @@ import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ParserParameters; import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.context.CommandContext; import cloud.commandframework.context.CommandContext;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.BiFunction; import java.util.function.BiFunction;

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.execution.postprocessor; package cloud.commandframework.execution.postprocessor;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
/** /**
* {@link CommandPostprocessor} that does nothing besides indicating that the context * {@link CommandPostprocessor} that does nothing besides indicating that the context
@ -39,7 +39,7 @@ public final class AcceptingCommandPostprocessor<C> implements CommandPostproces
public static final String PROCESSED_INDICATOR_KEY = "__COMMAND_POST_PROCESSED__"; public static final String PROCESSED_INDICATOR_KEY = "__COMMAND_POST_PROCESSED__";
@Override @Override
public void accept(@Nonnull final CommandPostprocessingContext<C> context) { public void accept(@NonNull final CommandPostprocessingContext<C> context) {
context.getCommandContext().store(PROCESSED_INDICATOR_KEY, "true"); context.getCommandContext().store(PROCESSED_INDICATOR_KEY, "true");
} }

View file

@ -25,8 +25,8 @@ package cloud.commandframework.execution.postprocessor;
import cloud.commandframework.Command; import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext; import cloud.commandframework.context.CommandContext;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.Objects; import java.util.Objects;
/** /**
@ -36,8 +36,8 @@ import java.util.Objects;
*/ */
public final class CommandPostprocessingContext<C> { public final class CommandPostprocessingContext<C> {
private final CommandContext<C> commandContext; private final CommandContext<@NonNull C> commandContext;
private final Command<C> command; private final Command<@NonNull C> command;
/** /**
* Construct a new command postprocessing context * Construct a new command postprocessing context
@ -45,8 +45,8 @@ public final class CommandPostprocessingContext<C> {
* @param commandContext Command context * @param commandContext Command context
* @param command Command instance * @param command Command instance
*/ */
public CommandPostprocessingContext(@Nonnull final CommandContext<C> commandContext, public CommandPostprocessingContext(@NonNull final CommandContext<@NonNull C> commandContext,
@Nonnull final Command<C> command) { @NonNull final Command<@NonNull C> command) {
this.commandContext = commandContext; this.commandContext = commandContext;
this.command = command; this.command = command;
} }
@ -56,8 +56,7 @@ public final class CommandPostprocessingContext<C> {
* *
* @return Command context * @return Command context
*/ */
@Nonnull public @NonNull CommandContext<@NonNull C> getCommandContext() {
public CommandContext<C> getCommandContext() {
return this.commandContext; return this.commandContext;
} }
@ -66,8 +65,7 @@ public final class CommandPostprocessingContext<C> {
* *
* @return Command instance * @return Command instance
*/ */
@Nonnull public @NonNull Command<@NonNull C> getCommand() {
public Command<C> getCommand() {
return this.command; return this.command;
} }

View file

@ -24,8 +24,7 @@
package cloud.commandframework.internal; package cloud.commandframework.internal;
import cloud.commandframework.Command; import cloud.commandframework.Command;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
/** /**
* Utility that registers commands natively for whatever * Utility that registers commands natively for whatever
@ -40,8 +39,7 @@ public interface CommandRegistrationHandler {
* *
* @return Constructed registration * @return Constructed registration
*/ */
@Nonnull static @NonNull CommandRegistrationHandler nullCommandRegistrationHandler() {
static CommandRegistrationHandler nullCommandRegistrationHandler() {
return new NullCommandRegistrationHandler(); return new NullCommandRegistrationHandler();
} }
@ -52,7 +50,7 @@ public interface CommandRegistrationHandler {
* @return {@code true} if the command was registered successfully, * @return {@code true} if the command was registered successfully,
* else {@code false} * else {@code false}
*/ */
boolean registerCommand(@Nonnull Command<?> command); boolean registerCommand(@NonNull Command<?> command);
final class NullCommandRegistrationHandler implements CommandRegistrationHandler { final class NullCommandRegistrationHandler implements CommandRegistrationHandler {
@ -60,7 +58,7 @@ public interface CommandRegistrationHandler {
} }
@Override @Override
public boolean registerCommand(@Nonnull final Command<?> command) { public boolean registerCommand(@NonNull final Command<?> command) {
return true; return true;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.permission; package cloud.commandframework.permission;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection; import java.util.Collection;
/** /**
@ -36,8 +37,7 @@ public interface CommandPermission {
* *
* @return Permission nodes * @return Permission nodes
*/ */
@Nonnull @NonNull Collection<@NonNull CommandPermission> getPermissions();
Collection<CommandPermission> getPermissions();
/** /**
* Get a string representation of the permission * Get a string representation of the permission
@ -45,7 +45,6 @@ public interface CommandPermission {
* @return String representation of the permission node * @return String representation of the permission node
*/ */
@Override @Override
@Nonnull
String toString(); String toString();
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.permission; package cloud.commandframework.permission;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -37,7 +38,7 @@ public final class OrPermission implements CommandPermission {
private final Collection<CommandPermission> permissions; private final Collection<CommandPermission> permissions;
private OrPermission(@Nonnull final Collection<CommandPermission> permissions) { private OrPermission(@NonNull final Collection<CommandPermission> permissions) {
this.permissions = permissions; this.permissions = permissions;
} }
@ -47,8 +48,7 @@ public final class OrPermission implements CommandPermission {
* @param permissions Permissions to join * @param permissions Permissions to join
* @return Constructed permission * @return Constructed permission
*/ */
@Nonnull public static @NonNull CommandPermission of(@NonNull final Collection<CommandPermission> permissions) {
public static CommandPermission of(@Nonnull final Collection<CommandPermission> permissions) {
final Set<CommandPermission> permissionSet = new HashSet<>(); final Set<CommandPermission> permissionSet = new HashSet<>();
for (final CommandPermission permission : permissions) { for (final CommandPermission permission : permissions) {
permissionSet.addAll(permission.getPermissions()); permissionSet.addAll(permission.getPermissions());
@ -56,9 +56,8 @@ public final class OrPermission implements CommandPermission {
return new OrPermission(permissionSet); return new OrPermission(permissionSet);
} }
@Nonnull
@Override @Override
public Collection<CommandPermission> getPermissions() { public @NonNull Collection<@NonNull CommandPermission> getPermissions() {
return this.permissions; return this.permissions;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.permission; package cloud.commandframework.permission;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Objects; import java.util.Objects;
@ -40,7 +41,7 @@ public final class Permission implements CommandPermission {
private final String permission; private final String permission;
private Permission(@Nonnull final String permission) { private Permission(@NonNull final String permission) {
this.permission = permission; this.permission = permission;
} }
@ -49,8 +50,7 @@ public final class Permission implements CommandPermission {
* *
* @return Command permission * @return Command permission
*/ */
@Nonnull public static @NonNull Permission empty() {
public static Permission empty() {
return EMPTY; return EMPTY;
} }
@ -60,8 +60,7 @@ public final class Permission implements CommandPermission {
* @param string Command permission * @param string Command permission
* @return Created command permission * @return Created command permission
*/ */
@Nonnull public static @NonNull Permission of(@NonNull final String string) {
public static Permission of(@Nonnull final String string) {
return new Permission(string); return new Permission(string);
} }
@ -70,14 +69,12 @@ public final class Permission implements CommandPermission {
* *
* @return Command permission * @return Command permission
*/ */
@Nonnull
public String getPermission() { public String getPermission() {
return this.permission; return this.permission;
} }
@Nonnull
@Override @Override
public Collection<CommandPermission> getPermissions() { public @NonNull Collection<@NonNull CommandPermission> getPermissions() {
return Collections.singleton(this); return Collections.singleton(this);
} }
@ -86,7 +83,6 @@ public final class Permission implements CommandPermission {
* *
* @return Command permission * @return Command permission
*/ */
@Nonnull
@Override @Override
public String toString() { public String toString() {
return this.permission; return this.permission;

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects; import java.util.Objects;
/** /**
@ -34,13 +35,11 @@ import java.util.Objects;
*/ */
public class Pair<U, V> implements Tuple { public class Pair<U, V> implements Tuple {
@Nonnull
private final U first; private final U first;
@Nonnull
private final V second; private final V second;
protected Pair(@Nonnull final U first, protected Pair(@NonNull final U first,
@Nonnull final V second) { @NonNull final V second) {
this.first = first; this.first = first;
this.second = second; this.second = second;
} }
@ -54,9 +53,8 @@ public class Pair<U, V> implements Tuple {
* @param <V> Second type * @param <V> Second type
* @return Created pair * @return Created pair
*/ */
@Nonnull public static <U, V> @NonNull Pair<@NonNull U, @NonNull V> of(@NonNull final U first,
public static <U, V> Pair<U, V> of(@Nonnull final U first, @NonNull final V second) {
@Nonnull final V second) {
return new Pair<>(first, second); return new Pair<>(first, second);
} }
@ -65,8 +63,7 @@ public class Pair<U, V> implements Tuple {
* *
* @return First value * @return First value
*/ */
@Nonnull public final @NonNull U getFirst() {
public final U getFirst() {
return this.first; return this.first;
} }
@ -75,8 +72,7 @@ public class Pair<U, V> implements Tuple {
* *
* @return Second value * @return Second value
*/ */
@Nonnull public final @NonNull V getSecond() {
public final V getSecond() {
return this.second; return this.second;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects; import java.util.Objects;
/** /**
@ -36,19 +37,15 @@ import java.util.Objects;
*/ */
public class Quartet<U, V, W, X> implements Tuple { public class Quartet<U, V, W, X> implements Tuple {
@Nonnull
private final U first; private final U first;
@Nonnull
private final V second; private final V second;
@Nonnull
private final W third; private final W third;
@Nonnull
private final X fourth; private final X fourth;
protected Quartet(@Nonnull final U first, protected Quartet(@NonNull final U first,
@Nonnull final V second, @NonNull final V second,
@Nonnull final W third, @NonNull final W third,
@Nonnull final X fourth) { @NonNull final X fourth) {
this.first = first; this.first = first;
this.second = second; this.second = second;
this.third = third; this.third = third;
@ -68,11 +65,10 @@ public class Quartet<U, V, W, X> implements Tuple {
* @param <X> Fourth type * @param <X> Fourth type
* @return Created quartet * @return Created quartet
*/ */
@Nonnull public static <U, V, W, X> @NonNull Quartet<@NonNull U, @NonNull V, @NonNull W, @NonNull X> of(@NonNull final U first,
public static <U, V, W, X> Quartet<U, V, W, X> of(@Nonnull final U first, @NonNull final V second,
@Nonnull final V second, @NonNull final W third,
@Nonnull final W third, @NonNull final X fourth) {
@Nonnull final X fourth) {
return new Quartet<>(first, second, third, fourth); return new Quartet<>(first, second, third, fourth);
} }
@ -81,8 +77,7 @@ public class Quartet<U, V, W, X> implements Tuple {
* *
* @return First value * @return First value
*/ */
@Nonnull public final @NonNull U getFirst() {
public final U getFirst() {
return this.first; return this.first;
} }
@ -91,8 +86,7 @@ public class Quartet<U, V, W, X> implements Tuple {
* *
* @return Second value * @return Second value
*/ */
@Nonnull public final @NonNull V getSecond() {
public final V getSecond() {
return this.second; return this.second;
} }
@ -101,8 +95,7 @@ public class Quartet<U, V, W, X> implements Tuple {
* *
* @return Third value * @return Third value
*/ */
@Nonnull public final @NonNull W getThird() {
public final W getThird() {
return this.third; return this.third;
} }
@ -111,8 +104,7 @@ public class Quartet<U, V, W, X> implements Tuple {
* *
* @return Fourth value * @return Fourth value
*/ */
@Nonnull public final @NonNull X getFourth() {
public final X getFourth() {
return this.fourth; return this.fourth;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects; import java.util.Objects;
/** /**
@ -37,22 +38,17 @@ import java.util.Objects;
*/ */
public class Quintet<U, V, W, X, Y> implements Tuple { public class Quintet<U, V, W, X, Y> implements Tuple {
@Nonnull
private final U first; private final U first;
@Nonnull
private final V second; private final V second;
@Nonnull
private final W third; private final W third;
@Nonnull
private final X fourth; private final X fourth;
@Nonnull
private final Y fifth; private final Y fifth;
protected Quintet(@Nonnull final U first, protected Quintet(@NonNull final U first,
@Nonnull final V second, @NonNull final V second,
@Nonnull final W third, @NonNull final W third,
@Nonnull final X fourth, @NonNull final X fourth,
@Nonnull final Y fifth) { @NonNull final Y fifth) {
this.first = first; this.first = first;
this.second = second; this.second = second;
this.third = third; this.third = third;
@ -75,12 +71,12 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
* @param <Y> Fifth type * @param <Y> Fifth type
* @return Created quintet * @return Created quintet
*/ */
@Nonnull public static <U, V, W, X, Y> @NonNull Quintet<@NonNull U, @NonNull V, @NonNull W, @NonNull X, @NonNull Y> of(
public static <U, V, W, X, Y> Quintet<U, V, W, X, Y> of(@Nonnull final U first, @NonNull final U first,
@Nonnull final V second, @NonNull final V second,
@Nonnull final W third, @NonNull final W third,
@Nonnull final X fourth, @NonNull final X fourth,
@Nonnull final Y fifth) { @NonNull final Y fifth) {
return new Quintet<>(first, second, third, fourth, fifth); return new Quintet<>(first, second, third, fourth, fifth);
} }
@ -89,8 +85,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
* *
* @return First value * @return First value
*/ */
@Nonnull public final @NonNull U getFirst() {
public final U getFirst() {
return this.first; return this.first;
} }
@ -99,8 +94,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
* *
* @return Second value * @return Second value
*/ */
@Nonnull public final @NonNull V getSecond() {
public final V getSecond() {
return this.second; return this.second;
} }
@ -109,8 +103,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
* *
* @return Third value * @return Third value
*/ */
@Nonnull public final @NonNull W getThird() {
public final W getThird() {
return this.third; return this.third;
} }
@ -119,8 +112,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
* *
* @return Fourth value * @return Fourth value
*/ */
@Nonnull public final @NonNull X getFourth() {
public final X getFourth() {
return this.fourth; return this.fourth;
} }
@ -129,8 +121,7 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
* *
* @return Fifth value * @return Fifth value
*/ */
@Nonnull public final @NonNull Y getFifth() {
public final Y getFifth() {
return this.fifth; return this.fifth;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects; import java.util.Objects;
/** /**
@ -38,25 +39,19 @@ import java.util.Objects;
*/ */
public class Sextet<U, V, W, X, Y, Z> implements Tuple { public class Sextet<U, V, W, X, Y, Z> implements Tuple {
@Nonnull
private final U first; private final U first;
@Nonnull
private final V second; private final V second;
@Nonnull
private final W third; private final W third;
@Nonnull
private final X fourth; private final X fourth;
@Nonnull
private final Y fifth; private final Y fifth;
@Nonnull
private final Z sixth; private final Z sixth;
protected Sextet(@Nonnull final U first, protected Sextet(@NonNull final U first,
@Nonnull final V second, @NonNull final V second,
@Nonnull final W third, @NonNull final W third,
@Nonnull final X fourth, @NonNull final X fourth,
@Nonnull final Y fifth, @NonNull final Y fifth,
@Nonnull final Z sixth) { @NonNull final Z sixth) {
this.first = first; this.first = first;
this.second = second; this.second = second;
this.third = third; this.third = third;
@ -82,13 +77,13 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* @param <Z> Sixth type * @param <Z> Sixth type
* @return Created sextet * @return Created sextet
*/ */
@Nonnull public static <U, V, W, X, Y, Z> @NonNull Sextet<@NonNull U, @NonNull V, @NonNull W, @NonNull X, @NonNull Y, @NonNull Z> of(
public static <U, V, W, X, Y, Z> Sextet<U, V, W, X, Y, Z> of(@Nonnull final U first, @NonNull final U first,
@Nonnull final V second, @NonNull final V second,
@Nonnull final W third, @NonNull final W third,
@Nonnull final X fourth, @NonNull final X fourth,
@Nonnull final Y fifth, @NonNull final Y fifth,
@Nonnull final Z sixth) { @NonNull final Z sixth) {
return new Sextet<>(first, second, third, fourth, fifth, sixth); return new Sextet<>(first, second, third, fourth, fifth, sixth);
} }
@ -97,8 +92,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* *
* @return First value * @return First value
*/ */
@Nonnull public final @NonNull U getFirst() {
public final U getFirst() {
return this.first; return this.first;
} }
@ -107,8 +101,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* *
* @return Second value * @return Second value
*/ */
@Nonnull public final @NonNull V getSecond() {
public final V getSecond() {
return this.second; return this.second;
} }
@ -117,8 +110,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* *
* @return Third value * @return Third value
*/ */
@Nonnull public final @NonNull W getThird() {
public final W getThird() {
return this.third; return this.third;
} }
@ -127,8 +119,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* *
* @return Fourth value * @return Fourth value
*/ */
@Nonnull public final @NonNull X getFourth() {
public final X getFourth() {
return this.fourth; return this.fourth;
} }
@ -137,8 +128,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* *
* @return Fifth value * @return Fifth value
*/ */
@Nonnull public final @NonNull Y getFifth() {
public final Y getFifth() {
return this.fifth; return this.fifth;
} }
@ -147,8 +137,7 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* *
* @return Sixth value * @return Sixth value
*/ */
@Nonnull public final @NonNull Z getSixth() {
public final Z getSixth() {
return this.sixth; return this.sixth;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects; import java.util.Objects;
/** /**
@ -35,16 +36,13 @@ import java.util.Objects;
*/ */
public class Triplet<U, V, W> implements Tuple { public class Triplet<U, V, W> implements Tuple {
@Nonnull
private final U first; private final U first;
@Nonnull
private final V second; private final V second;
@Nonnull
private final W third; private final W third;
protected Triplet(@Nonnull final U first, protected Triplet(@NonNull final U first,
@Nonnull final V second, @NonNull final V second,
@Nonnull final W third) { @NonNull final W third) {
this.first = first; this.first = first;
this.second = second; this.second = second;
this.third = third; this.third = third;
@ -61,10 +59,9 @@ public class Triplet<U, V, W> implements Tuple {
* @param <W> Third type * @param <W> Third type
* @return Created triplet * @return Created triplet
*/ */
@Nonnull public static <U, V, W> @NonNull Triplet<@NonNull U, @NonNull V, @NonNull W> of(@NonNull final U first,
public static <U, V, W> Triplet<U, V, W> of(@Nonnull final U first, @NonNull final V second,
@Nonnull final V second, @NonNull final W third) {
@Nonnull final W third) {
return new Triplet<>(first, second, third); return new Triplet<>(first, second, third);
} }
@ -73,8 +70,7 @@ public class Triplet<U, V, W> implements Tuple {
* *
* @return First value * @return First value
*/ */
@Nonnull public final @NonNull U getFirst() {
public final U getFirst() {
return this.first; return this.first;
} }
@ -83,8 +79,7 @@ public class Triplet<U, V, W> implements Tuple {
* *
* @return Second value * @return Second value
*/ */
@Nonnull public final @NonNull V getSecond() {
public final V getSecond() {
return this.second; return this.second;
} }
@ -93,8 +88,7 @@ public class Triplet<U, V, W> implements Tuple {
* *
* @return Third value * @return Third value
*/ */
@Nonnull public final @NonNull W getThird() {
public final W getThird() {
return this.third; return this.third;
} }

View file

@ -1,147 +0,0 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package cloud.commandframework.types.tuples;
import javax.annotation.Nonnull;
/**
* Utility class for dealing with tuples
*/
public final class Tuples {
static final int SIZE_PAIR = 2;
static final int SIZE_TRIPLET = 3;
static final int SIZE_QUARTET = 4;
static final int SIZE_QUINTET = 5;
static final int SIZE_SEXTET = 6;
private Tuples() {
}
/**
* Create a new pair
*
* @param first First value
* @param second Second value
* @param <U> First type
* @param <V> Second type
* @return Created pair
*/
@Nonnull
public static <U, V> Pair<U, V> of(@Nonnull final U first,
@Nonnull final V second) {
return Pair.of(first, second);
}
/**
* Create a new triplet
*
* @param first First value
* @param second Second value
* @param third Third value
* @param <U> First type
* @param <V> Second type
* @param <W> Third type
* @return Created triplet
*/
@Nonnull
public static <U, V, W> Triplet<U, V, W> of(@Nonnull final U first,
@Nonnull final V second,
@Nonnull final W third) {
return Triplet.of(first, second, third);
}
/**
* Create a new quartet
*
* @param first First value
* @param second Second value
* @param third Third value
* @param fourth Fourth value
* @param <U> First type
* @param <V> Second type
* @param <W> Third type
* @param <X> Fourth type
* @return Created quartet
*/
@Nonnull
public static <U, V, W, X> Quartet<U, V, W, X> of(@Nonnull final U first,
@Nonnull final V second,
@Nonnull final W third,
@Nonnull final X fourth) {
return Quartet.of(first, second, third, fourth);
}
/**
* Create a new quintet
*
* @param first First value
* @param second Second value
* @param third Third value
* @param fourth Fourth value
* @param fifth Fifth value
* @param <U> First type
* @param <V> Second type
* @param <W> Third type
* @param <X> Fourth type
* @param <Y> Fifth type
* @return Created quintet
*/
@Nonnull
public static <U, V, W, X, Y> Quintet<U, V, W, X, Y> of(@Nonnull final U first,
@Nonnull final V second,
@Nonnull final W third,
@Nonnull final X fourth,
@Nonnull final Y fifth) {
return Quintet.of(first, second, third, fourth, fifth);
}
/**
* Create a new sextet
*
* @param first First value
* @param second Second value
* @param third Third value
* @param fourth Fourth value
* @param fifth Fifth value
* @param sixth Sixth value
* @param <U> First type
* @param <V> Second type
* @param <W> Third type
* @param <X> Fourth type
* @param <Y> Fifth type
* @param <Z> Sixth type
* @return Created sextet
*/
@Nonnull
public static <U, V, W, X, Y, Z> Sextet<U, V, W, X, Y, Z> of(@Nonnull final U first,
@Nonnull final V second,
@Nonnull final W third,
@Nonnull final X fourth,
@Nonnull final Y fifth,
@Nonnull final Z sixth) {
return Sextet.of(first, second, third, fourth, fifth, sixth);
}
}

View file

@ -25,9 +25,9 @@ package cloud.commandframework.services;
import cloud.commandframework.services.annotations.Order; import cloud.commandframework.services.annotations.Order;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -40,7 +40,8 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
private final Method method; private final Method method;
private final Object instance; private final Object instance;
AnnotatedMethodService(@Nonnull final Object instance, @Nonnull final Method method) AnnotatedMethodService(@NonNull final Object instance,
@NonNull final Method method)
throws Exception { throws Exception {
ExecutionOrder executionOrder = ExecutionOrder.SOON; ExecutionOrder executionOrder = ExecutionOrder.SOON;
try { try {
@ -57,10 +58,9 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
this.method = method; this.method = method;
} }
@Nullable
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Result handle(@Nonnull final Context context) { public @Nullable Result handle(@NonNull final Context context) {
try { try {
return (Result) this.methodHandle.invoke(this.instance, context); return (Result) this.methodHandle.invoke(this.instance, context);
} catch (final Throwable throwable) { } catch (final Throwable throwable) {
@ -72,9 +72,8 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
return null; return null;
} }
@Nonnull
@Override @Override
public ExecutionOrder order() { public @NonNull ExecutionOrder order() {
return this.executionOrder; return this.executionOrder;
} }

View file

@ -26,8 +26,8 @@ package cloud.commandframework.services;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.annotations.ServiceImplementation; import cloud.commandframework.services.annotations.ServiceImplementation;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -35,8 +35,8 @@ import java.util.Map;
enum AnnotatedMethodServiceFactory { enum AnnotatedMethodServiceFactory {
INSTANCE; INSTANCE;
Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> lookupServices( @NonNull Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> lookupServices(
@Nonnull final Object instance) throws Exception { @NonNull final Object instance) throws Exception {
final Map<Service<?, ?>, TypeToken<? extends Service<?, ?>>> map = new HashMap<>(); final Map<Service<?, ?>, TypeToken<? extends Service<?, ?>>> map = new HashMap<>();
final Class<?> clazz = instance.getClass(); final Class<?> clazz = instance.getClass();
for (final Method method : clazz.getDeclaredMethods()) { for (final Method method : clazz.getDeclaredMethods()) {

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -38,18 +39,18 @@ import java.util.Map;
* @param <Context> Context/Request type * @param <Context> Context/Request type
* @param <Result> Result type * @param <Result> Result type
*/ */
public abstract class ChunkedRequestContext<Context, Result> { public abstract class ChunkedRequestContext<@NonNull Context, @NonNull Result> {
private final Object lock = new Object(); private final Object lock = new Object();
private final List<Context> requests; private final List<@NonNull Context> requests;
private final Map<Context, Result> results; private final Map<@NonNull Context, @NonNull Result> results;
/** /**
* Initialize a new request * Initialize a new request
* *
* @param requests Request contexts * @param requests Request contexts
*/ */
protected ChunkedRequestContext(@Nonnull final Collection<Context> requests) { protected ChunkedRequestContext(@NonNull final Collection<Context> requests) {
this.requests = new ArrayList<>(requests); this.requests = new ArrayList<>(requests);
this.results = new HashMap<>(requests.size()); this.results = new HashMap<>(requests.size());
} }
@ -59,8 +60,7 @@ public abstract class ChunkedRequestContext<Context, Result> {
* *
* @return Unmodifiable map of results * @return Unmodifiable map of results
*/ */
@Nonnull public final @NonNull Map<@NonNull Context, @NonNull Result> getAvailableResults() {
public final Map<Context, Result> getAvailableResults() {
synchronized (this.lock) { synchronized (this.lock) {
return Collections.unmodifiableMap(this.results); return Collections.unmodifiableMap(this.results);
} }
@ -71,8 +71,7 @@ public abstract class ChunkedRequestContext<Context, Result> {
* *
* @return Unmodifiable list of remaining requests * @return Unmodifiable list of remaining requests
*/ */
@Nonnull public final @NonNull List<@NonNull Context> getRemaining() {
public final List<Context> getRemaining() {
synchronized (this.lock) { synchronized (this.lock) {
return Collections.unmodifiableList(this.requests); return Collections.unmodifiableList(this.requests);
} }
@ -84,7 +83,7 @@ public abstract class ChunkedRequestContext<Context, Result> {
* @param context Context * @param context Context
* @param result Result * @param result Result
*/ */
public final void storeResult(@Nonnull final Context context, @Nonnull final Result result) { public final void storeResult(@NonNull final Context context, @NonNull final Result result) {
synchronized (this.lock) { synchronized (this.lock) {
this.results.put(context, result); this.results.put(context, result);
this.requests.remove(context); this.requests.remove(context);

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
/** /**
* Wrapper for exceptions thrown during pipeline execution. * Wrapper for exceptions thrown during pipeline execution.
@ -37,7 +37,7 @@ public final class PipelineException extends RuntimeException {
* *
* @param cause Cause of the exception * @param cause Cause of the exception
*/ */
public PipelineException(@Nonnull final Exception cause) { public PipelineException(@NonNull final Exception cause) {
super(cause); super(cause);
} }
@ -47,7 +47,7 @@ public final class PipelineException extends RuntimeException {
* @param message Message explaining the exception * @param message Message explaining the exception
* @param cause Cause of the exception * @param cause Cause of the exception
*/ */
public PipelineException(@Nonnull final String message, @Nonnull final Exception cause) { public PipelineException(@NonNull final String message, @NonNull final Exception cause) {
super(message, cause); super(message, cause);
} }

View file

@ -24,16 +24,16 @@
package cloud.commandframework.services; package cloud.commandframework.services;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.function.Predicate; import java.util.function.Predicate;
enum ServiceFilterHandler { enum ServiceFilterHandler {
INSTANCE; INSTANCE;
<Context> boolean passes( <Context> boolean passes(
@Nonnull final ServiceRepository<Context, ?>.ServiceWrapper<? extends Service<Context, ?>> service, @NonNull final ServiceRepository<Context, ?>.ServiceWrapper<? extends Service<Context, ?>> service,
@Nonnull final Context context) { @NonNull final Context context) {
if (!service.isDefaultImplementation()) { if (!service.isDefaultImplementation()) {
for (final Predicate<Context> predicate : service.getFilters()) { for (final Predicate<Context> predicate : service.getFilters()) {
try { try {

View file

@ -25,8 +25,8 @@ package cloud.commandframework.services;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -45,7 +45,7 @@ public final class ServicePipeline {
private final Map<TypeToken<? extends Service<?, ?>>, ServiceRepository<?, ?>> repositories; private final Map<TypeToken<? extends Service<?, ?>>, ServiceRepository<?, ?>> repositories;
private final Executor executor; private final Executor executor;
ServicePipeline(@Nonnull final Executor executor) { ServicePipeline(@NonNull final Executor executor) {
this.repositories = new HashMap<>(); this.repositories = new HashMap<>();
this.executor = executor; this.executor = executor;
} }
@ -55,8 +55,7 @@ public final class ServicePipeline {
* *
* @return Builder instance * @return Builder instance
*/ */
@Nonnull public static @NonNull ServicePipelineBuilder builder() {
public static ServicePipelineBuilder builder() {
return new ServicePipelineBuilder(); return new ServicePipelineBuilder();
} }
@ -71,9 +70,9 @@ public final class ServicePipeline {
* @param <Result> Service result type * @param <Result> Service result type
* @return ServicePipeline The service pipeline instance * @return ServicePipeline The service pipeline instance
*/ */
public <Context, Result> ServicePipeline registerServiceType( public <Context, Result> @NonNull ServicePipeline registerServiceType(
@Nonnull final TypeToken<? extends Service<Context, Result>> type, @NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type,
@Nonnull final Service<Context, Result> defaultImplementation) { @NonNull final Service<@NonNull Context, @NonNull Result> defaultImplementation) {
synchronized (this.lock) { synchronized (this.lock) {
if (repositories.containsKey(type)) { if (repositories.containsKey(type)) {
throw new IllegalArgumentException(String throw new IllegalArgumentException(String
@ -105,8 +104,8 @@ public final class ServicePipeline {
* @throws Exception Any exceptions thrown during the registration process * @throws Exception Any exceptions thrown during the registration process
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> ServicePipeline registerMethods( public <T> @NonNull ServicePipeline registerMethods(
@Nonnull final T instance) throws Exception { @NonNull final T instance) throws Exception {
synchronized (this.lock) { synchronized (this.lock) {
final Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> services = final Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> services =
AnnotatedMethodServiceFactory.INSTANCE.lookupServices(instance); AnnotatedMethodServiceFactory.INSTANCE.lookupServices(instance);
@ -139,9 +138,9 @@ public final class ServicePipeline {
* @return ServicePipeline The service pipeline instance * @return ServicePipeline The service pipeline instance
*/ */
public <Context, Result> ServicePipeline registerServiceImplementation( public <Context, Result> ServicePipeline registerServiceImplementation(
@Nonnull final TypeToken<? extends Service<Context, Result>> type, @NonNull final TypeToken<? extends Service<Context, Result>> type,
@Nonnull final Service<Context, Result> implementation, @NonNull final Service<Context, Result> implementation,
@Nonnull final Collection<Predicate<Context>> filters) { @NonNull final Collection<Predicate<Context>> filters) {
synchronized (this.lock) { synchronized (this.lock) {
final ServiceRepository<Context, Result> repository = getRepository(type); final ServiceRepository<Context, Result> repository = getRepository(type);
repository.registerImplementation(implementation, filters); repository.registerImplementation(implementation, filters);
@ -163,9 +162,9 @@ public final class ServicePipeline {
* @return ServicePipeline The service pipeline instance * @return ServicePipeline The service pipeline instance
*/ */
public <Context, Result> ServicePipeline registerServiceImplementation( public <Context, Result> ServicePipeline registerServiceImplementation(
@Nonnull final Class<? extends Service<Context, Result>> type, @NonNull final Class<? extends Service<Context, Result>> type,
@Nonnull final Service<Context, Result> implementation, @NonNull final Service<Context, Result> implementation,
@Nonnull final Collection<Predicate<Context>> filters) { @NonNull final Collection<Predicate<Context>> filters) {
return registerServiceImplementation(TypeToken.get(type), implementation, filters); return registerServiceImplementation(TypeToken.get(type), implementation, filters);
} }
@ -177,15 +176,15 @@ public final class ServicePipeline {
* @param <Context> Context type * @param <Context> Context type
* @return Service pumper instance * @return Service pumper instance
*/ */
@Nonnull @NonNull
public <Context> ServicePump<Context> pump(@Nonnull final Context context) { public <Context> ServicePump<Context> pump(@NonNull final Context context) {
return new ServicePump<>(this, context); return new ServicePump<>(this, context);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Nonnull @NonNull
<Context, Result> ServiceRepository<Context, Result> getRepository( <Context, Result> ServiceRepository<Context, Result> getRepository(
@Nonnull final TypeToken<? extends Service<Context, Result>> type) { @NonNull final TypeToken<? extends Service<Context, Result>> type) {
final ServiceRepository<Context, Result> repository = final ServiceRepository<Context, Result> repository =
(ServiceRepository<Context, Result>) this.repositories.get(type); (ServiceRepository<Context, Result>) this.repositories.get(type);
if (repository == null) { if (repository == null) {
@ -200,7 +199,7 @@ public final class ServicePipeline {
* *
* @return Returns an Immutable collection of the service types registered. * @return Returns an Immutable collection of the service types registered.
*/ */
@Nonnull @NonNull
public Collection<TypeToken<? extends Service<?, ?>>> getRecognizedTypes() { public Collection<TypeToken<? extends Service<?, ?>>> getRecognizedTypes() {
return Collections.unmodifiableCollection(this.repositories.keySet()); return Collections.unmodifiableCollection(this.repositories.keySet());
} }
@ -215,10 +214,10 @@ public final class ServicePipeline {
* @return Returns an collection of the {@link TypeToken}s of the implementations for a given * @return Returns an collection of the {@link TypeToken}s of the implementations for a given
* service. Iterator order matches the priority when pumping contexts through the pipeline * service. Iterator order matches the priority when pumping contexts through the pipeline
*/ */
@Nonnull @NonNull
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <Context, Result, S extends Service<Context, Result>> Collection<TypeToken<? extends S>> getImplementations( public <Context, Result, S extends Service<Context, Result>> Collection<TypeToken<? extends S>> getImplementations(
@Nonnull final TypeToken<S> type) { @NonNull final TypeToken<S> type) {
ServiceRepository<Context, Result> repository = getRepository(type); ServiceRepository<Context, Result> repository = getRepository(type);
List<TypeToken<? extends S>> collection = new LinkedList<>(); List<TypeToken<? extends S>> collection = new LinkedList<>();
final LinkedList<? extends ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>> final LinkedList<? extends ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>>
@ -232,7 +231,7 @@ public final class ServicePipeline {
return Collections.unmodifiableList(collection); return Collections.unmodifiableList(collection);
} }
@Nonnull @NonNull
Executor getExecutor() { Executor getExecutor() {
return this.executor; return this.executor;
} }

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import javax.annotation.Nonnull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -44,8 +45,7 @@ public final class ServicePipelineBuilder {
* *
* @return New service pipeline * @return New service pipeline
*/ */
@Nonnull public @NonNull ServicePipeline build() {
public ServicePipeline build() {
return new ServicePipeline(this.executor); return new ServicePipeline(this.executor);
} }
@ -56,8 +56,7 @@ public final class ServicePipelineBuilder {
* @param executor New executor * @param executor New executor
* @return Builder instance * @return Builder instance
*/ */
@Nonnull public @NonNull ServicePipelineBuilder withExecutor(@NonNull final Executor executor) {
public ServicePipelineBuilder withExecutor(@Nonnull final Executor executor) {
this.executor = Objects.requireNonNull(executor, "Executor may not be null"); this.executor = Objects.requireNonNull(executor, "Executor may not be null");
return this; return this;
} }

View file

@ -25,8 +25,7 @@ package cloud.commandframework.services;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
/** /**
* Class that forwards a context to a service type that consumes said context * Class that forwards a context to a service type that consumes said context
@ -38,7 +37,8 @@ public final class ServicePump<Context> {
private final ServicePipeline servicePipeline; private final ServicePipeline servicePipeline;
private final Context context; private final Context context;
ServicePump(final ServicePipeline servicePipeline, final Context context) { ServicePump(@NonNull final ServicePipeline servicePipeline,
@NonNull final Context context) {
this.servicePipeline = servicePipeline; this.servicePipeline = servicePipeline;
this.context = context; this.context = context;
} }
@ -50,9 +50,8 @@ public final class ServicePump<Context> {
* @param <Result> Result type * @param <Result> Result type
* @return Service spigot instance * @return Service spigot instance
*/ */
@Nonnull public <Result> @NonNull ServiceSpigot<@NonNull Context, @NonNull Result> through(
public <Result> ServiceSpigot<Context, Result> through( @NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
@Nonnull final TypeToken<? extends Service<Context, Result>> type) {
return new ServiceSpigot<>(this.servicePipeline, this.context, type); return new ServiceSpigot<>(this.servicePipeline, this.context, type);
} }
@ -63,9 +62,8 @@ public final class ServicePump<Context> {
* @param <Result> Result type * @param <Result> Result type
* @return Service spigot instance * @return Service spigot instance
*/ */
@Nonnull public <Result> @NonNull ServiceSpigot<@NonNull Context, @NonNull Result> through(
public <Result> ServiceSpigot<Context, Result> through( @NonNull final Class<? extends Service<@NonNull Context, @NonNull Result>> clazz) {
@Nonnull final Class<? extends Service<Context, Result>> clazz) {
return this.through(TypeToken.get(clazz)); return this.through(TypeToken.get(clazz));
} }

View file

@ -26,8 +26,8 @@ package cloud.commandframework.services;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.annotations.Order; import cloud.commandframework.services.annotations.Order;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -54,7 +54,7 @@ public final class ServiceRepository<Context, Response> {
* *
* @param serviceType Service type * @param serviceType Service type
*/ */
ServiceRepository(@Nonnull final TypeToken<? extends Service<Context, Response>> serviceType) { ServiceRepository(@NonNull final TypeToken<? extends Service<Context, Response>> serviceType) {
this.serviceType = serviceType; this.serviceType = serviceType;
this.implementations = new LinkedList<>(); this.implementations = new LinkedList<>();
} }
@ -66,8 +66,8 @@ public final class ServiceRepository<Context, Response> {
* @param filters Filters that will be used to determine whether or not the service gets used * @param filters Filters that will be used to determine whether or not the service gets used
* @param <T> Type of the implementation * @param <T> Type of the implementation
*/ */
<T extends Service<Context, Response>> void registerImplementation(@Nonnull final T service, <T extends Service<Context, Response>> void registerImplementation(@NonNull final T service,
@Nonnull final Collection<Predicate<Context>> filters) { @NonNull final Collection<Predicate<Context>> filters) {
synchronized (this.lock) { synchronized (this.lock) {
this.implementations.add(new ServiceWrapper<>(service, filters)); this.implementations.add(new ServiceWrapper<>(service, filters));
} }
@ -78,7 +78,7 @@ public final class ServiceRepository<Context, Response> {
* *
* @return Queue containing all implementations * @return Queue containing all implementations
*/ */
@Nonnull @NonNull
LinkedList<ServiceWrapper<? extends Service<Context, Response>>> getQueue() { LinkedList<ServiceWrapper<? extends Service<Context, Response>>> getQueue() {
synchronized (this.lock) { synchronized (this.lock) {
return new LinkedList<>(this.implementations); return new LinkedList<>(this.implementations);
@ -101,8 +101,8 @@ public final class ServiceRepository<Context, Response> {
private final int registrationOrder = ServiceRepository.this.registrationOrder++; private final int registrationOrder = ServiceRepository.this.registrationOrder++;
private final ExecutionOrder executionOrder; private final ExecutionOrder executionOrder;
private ServiceWrapper(@Nonnull final T implementation, private ServiceWrapper(@NonNull final T implementation,
@Nonnull final Collection<Predicate<Context>> filters) { @NonNull final Collection<Predicate<Context>> filters) {
this.defaultImplementation = implementations.isEmpty(); this.defaultImplementation = implementations.isEmpty();
this.implementation = implementation; this.implementation = implementation;
this.filters = filters; this.filters = filters;
@ -118,12 +118,12 @@ public final class ServiceRepository<Context, Response> {
this.executionOrder = executionOrder; this.executionOrder = executionOrder;
} }
@Nonnull @NonNull
T getImplementation() { T getImplementation() {
return this.implementation; return this.implementation;
} }
@Nonnull @NonNull
Collection<Predicate<Context>> getFilters() { Collection<Predicate<Context>> getFilters() {
return Collections.unmodifiableCollection(this.filters); return Collections.unmodifiableCollection(this.filters);
} }
@ -140,7 +140,7 @@ public final class ServiceRepository<Context, Response> {
} }
@Override @Override
public int compareTo(@Nonnull final ServiceWrapper<T> other) { public int compareTo(@NonNull final ServiceWrapper<T> other) {
return Comparator.<ServiceWrapper<T>>comparingInt( return Comparator.<ServiceWrapper<T>>comparingInt(
wrapper -> wrapper.isDefaultImplementation() wrapper -> wrapper.isDefaultImplementation()
? Integer.MIN_VALUE ? Integer.MIN_VALUE

View file

@ -27,8 +27,8 @@ import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.types.ConsumerService; import cloud.commandframework.services.types.ConsumerService;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import cloud.commandframework.services.types.SideEffectService; import cloud.commandframework.services.types.SideEffectService;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -45,8 +45,9 @@ public final class ServiceSpigot<Context, Result> {
private final ServicePipeline pipeline; private final ServicePipeline pipeline;
private final ServiceRepository<Context, Result> repository; private final ServiceRepository<Context, Result> repository;
ServiceSpigot(@Nonnull final ServicePipeline pipeline, @Nonnull final Context context, ServiceSpigot(@NonNull final ServicePipeline pipeline,
@Nonnull final TypeToken<? extends Service<Context, Result>> type) { @NonNull final Context context,
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
this.context = context; this.context = context;
this.pipeline = pipeline; this.pipeline = pipeline;
this.repository = pipeline.getRepository(type); this.repository = pipeline.getRepository(type);
@ -72,11 +73,11 @@ public final class ServiceSpigot<Context, Result> {
* @see PipelineException PipelineException wraps exceptions thrown during filtering and result * @see PipelineException PipelineException wraps exceptions thrown during filtering and result
* retrieval * retrieval
*/ */
@Nonnull
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Result getResult() public @NonNull Result getResult()
throws IllegalStateException, PipelineException { throws IllegalStateException, PipelineException {
final LinkedList<? extends ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>> final LinkedList<? extends ServiceRepository<@NonNull Context, @NonNull Result>
.ServiceWrapper<? extends Service<@NonNull Context, @NonNull Result>>>
queue = this.repository.getQueue(); queue = this.repository.getQueue();
queue.sort(null); // Sort using the built in comparator method queue.sort(null); // Sort using the built in comparator method
ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>> ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>
@ -128,7 +129,7 @@ public final class ServiceSpigot<Context, Result> {
* default implementation * default implementation
* @throws IllegalStateException If a {@link SideEffectService} returns {@code null} * @throws IllegalStateException If a {@link SideEffectService} returns {@code null}
*/ */
public void getResult(@Nonnull final BiConsumer<Result, Throwable> consumer) { public void getResult(@NonNull final BiConsumer<Result, Throwable> consumer) {
try { try {
consumer.accept(getResult(), null); consumer.accept(getResult(), null);
} catch (final PipelineException pipelineException) { } catch (final PipelineException pipelineException) {
@ -145,8 +146,7 @@ public final class ServiceSpigot<Context, Result> {
* *
* @return Generated result * @return Generated result
*/ */
@Nonnull public @NonNull CompletableFuture<Result> getResultAsynchronously() {
public CompletableFuture<Result> getResultAsynchronously() {
return CompletableFuture.supplyAsync(this::getResult, this.pipeline.getExecutor()); return CompletableFuture.supplyAsync(this::getResult, this.pipeline.getExecutor());
} }
@ -155,8 +155,7 @@ public final class ServiceSpigot<Context, Result> {
* *
* @return New pump, for the result of this request * @return New pump, for the result of this request
*/ */
@Nonnull public @NonNull ServicePump<Result> forward() {
public ServicePump<Result> forward() {
return this.pipeline.pump(this.getResult()); return this.pipeline.pump(this.getResult());
} }
@ -165,8 +164,7 @@ public final class ServiceSpigot<Context, Result> {
* *
* @return New pump, for the result of this request * @return New pump, for the result of this request
*/ */
@Nonnull public @NonNull CompletableFuture<ServicePump<Result>> forwardAsynchronously() {
public CompletableFuture<ServicePump<Result>> forwardAsynchronously() {
return this.getResultAsynchronously().thenApply(pipeline::pump); return this.getResultAsynchronously().thenApply(pipeline::pump);
} }

View file

@ -24,8 +24,8 @@
package cloud.commandframework.services.types; package cloud.commandframework.services.types;
import cloud.commandframework.services.State; import cloud.commandframework.services.State;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@ -49,9 +49,8 @@ public interface ConsumerService<Context>
throw new PipeBurst(); throw new PipeBurst();
} }
@Nonnull
@Override @Override
default State handle(@Nonnull final Context context) { default @NonNull State handle(@NonNull final Context context) {
try { try {
this.accept(context); this.accept(context);
} catch (final PipeBurst burst) { } catch (final PipeBurst burst) {
@ -67,7 +66,7 @@ public interface ConsumerService<Context>
* @param context Context to consume * @param context Context to consume
*/ */
@Override @Override
void accept(@Nonnull Context context); void accept(@NonNull Context context);
class PipeBurst extends RuntimeException { class PipeBurst extends RuntimeException {

View file

@ -24,9 +24,9 @@
package cloud.commandframework.services.types; package cloud.commandframework.services.types;
import cloud.commandframework.services.ChunkedRequestContext; import cloud.commandframework.services.ChunkedRequestContext;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,11 +38,10 @@ import java.util.Map;
* @param <Chunked> Chunk request context * @param <Chunked> Chunk request context
*/ */
public interface PartialResultService<Context, Result, Chunked extends ChunkedRequestContext<Context, Result>> public interface PartialResultService<Context, Result, Chunked extends ChunkedRequestContext<Context, Result>>
extends Service<Chunked, Map<Context, Result>> { extends Service<Chunked, @Nullable Map<@NonNull Context, @NonNull Result>> {
@Override @Override
@Nullable default @Nullable Map<@NonNull Context, @NonNull Result> handle(@NonNull final Chunked context) {
default Map<Context, Result> handle(@Nonnull final Chunked context) {
if (!context.isCompleted()) { if (!context.isCompleted()) {
this.handleRequests(context.getRemaining()).forEach(context::storeResult); this.handleRequests(context.getRemaining()).forEach(context::storeResult);
} }
@ -59,7 +58,6 @@ public interface PartialResultService<Context, Result, Chunked extends ChunkedRe
* @param requests Requests * @param requests Requests
* @return Map of request-result pairs * @return Map of request-result pairs
*/ */
@Nonnull @NonNull Map<@NonNull Context, @NonNull Result> handleRequests(@NonNull List<Context> requests);
Map<Context, Result> handleRequests(@Nonnull List<Context> requests);
} }

View file

@ -25,9 +25,9 @@ package cloud.commandframework.services.types;
import cloud.commandframework.services.ExecutionOrder; import cloud.commandframework.services.ExecutionOrder;
import cloud.commandframework.services.PipelineException; import cloud.commandframework.services.PipelineException;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Function; import java.util.function.Function;
/** /**
@ -39,7 +39,7 @@ import java.util.function.Function;
* @param <Result> Response type, this is what is produced by the service ("provided") * @param <Result> Response type, this is what is produced by the service ("provided")
*/ */
@FunctionalInterface @FunctionalInterface
public interface Service<Context, Result> extends Function<Context, Result> { public interface Service<Context, Result> extends Function<@NonNull Context, @Nullable Result> {
/** /**
* Provide a response for the given context. If the service implementation cannot provide a * Provide a response for the given context. If the service implementation cannot provide a
@ -52,11 +52,10 @@ public interface Service<Context, Result> extends Function<Context, Result> {
* @throws Exception Any exception that occurs during the handling can be thrown, and will be * @throws Exception Any exception that occurs during the handling can be thrown, and will be
* wrapped by a {@link PipelineException} * wrapped by a {@link PipelineException}
*/ */
@Nullable @Nullable Result handle(@NonNull Context context) throws Exception;
Result handle(@Nonnull Context context) throws Exception;
@Override @Override
default Result apply(@Nonnull Context context) { default @Nullable Result apply(@NonNull Context context) {
try { try {
return this.handle(context); return this.handle(context);
} catch (final Exception exception) { } catch (final Exception exception) {
@ -70,8 +69,7 @@ public interface Service<Context, Result> extends Function<Context, Result> {
* *
* @return Execution order * @return Execution order
*/ */
@Nullable default @Nullable ExecutionOrder order() {
default ExecutionOrder order() {
return null; return null;
} }

View file

@ -24,8 +24,7 @@
package cloud.commandframework.services.types; package cloud.commandframework.services.types;
import cloud.commandframework.services.State; import cloud.commandframework.services.State;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
/** /**
* Service implementation that alters the state of the owning application in some way. A * Service implementation that alters the state of the owning application in some way. A
@ -49,7 +48,6 @@ public interface SideEffectService<Context> extends Service<Context, State> {
* wrapped by a {@link cloud.commandframework.services.PipelineException} * wrapped by a {@link cloud.commandframework.services.PipelineException}
*/ */
@Override @Override
@Nonnull @NonNull State handle(@NonNull Context context) throws Exception;
State handle(@Nonnull Context context) throws Exception;
} }

View file

@ -25,12 +25,10 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.annotations.ServiceImplementation; import cloud.commandframework.services.annotations.ServiceImplementation;
import javax.annotation.Nonnull;
public class AnnotatedMethodTest { public class AnnotatedMethodTest {
@ServiceImplementation(MockService.class) @ServiceImplementation(MockService.class)
public MockService.MockResult handle(@Nonnull final MockService.MockContext context) { public MockService.MockResult handle(final MockService.MockContext context) {
return new MockService.MockResult(context.getString().length()); return new MockService.MockResult(context.getString().length());
} }

View file

@ -23,17 +23,14 @@
// //
package cloud.commandframework.services.mock; package cloud.commandframework.services.mock;
import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class CompletingPartialResultService implements MockPartialResultService { public class CompletingPartialResultService implements MockPartialResultService {
@Nonnull
@Override @Override
public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests( public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests(List<MockChunkedRequest.Animal> requests) {
@Nonnull List<MockChunkedRequest.Animal> requests) {
final Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> map = new HashMap<>(); final Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> map = new HashMap<>();
for (final MockChunkedRequest.Animal animal : requests) { for (final MockChunkedRequest.Animal animal : requests) {
if (animal.getName().equals("cow")) { if (animal.getName().equals("cow")) {

View file

@ -23,14 +23,10 @@
// //
package cloud.commandframework.services.mock; package cloud.commandframework.services.mock;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class DefaultMockService implements MockService { public class DefaultMockService implements MockService {
@Nullable
@Override @Override
public MockResult handle(@Nonnull final MockContext mockContext) public MockResult handle(final MockContext mockContext)
throws Exception { throws Exception {
if (mockContext.getString().equals("pls throw exception")) { if (mockContext.getString().equals("pls throw exception")) {
throw new TotallyIntentionalException(); throw new TotallyIntentionalException();

View file

@ -23,17 +23,14 @@
// //
package cloud.commandframework.services.mock; package cloud.commandframework.services.mock;
import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class DefaultPartialRequestService implements MockPartialResultService { public class DefaultPartialRequestService implements MockPartialResultService {
@Nonnull
@Override @Override
public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests( public Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> handleRequests(final List<MockChunkedRequest.Animal> requests) {
@Nonnull final List<MockChunkedRequest.Animal> requests) {
final Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> map = final Map<MockChunkedRequest.Animal, MockChunkedRequest.Sound> map =
new HashMap<>(requests.size()); new HashMap<>(requests.size());
for (final MockChunkedRequest.Animal animal : requests) { for (final MockChunkedRequest.Animal animal : requests) {

View file

@ -25,13 +25,10 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.State; import cloud.commandframework.services.State;
import javax.annotation.Nonnull;
public class DefaultSideEffectService implements MockSideEffectService { public class DefaultSideEffectService implements MockSideEffectService {
@Nonnull
@Override @Override
public State handle(@Nonnull final MockPlayer mockPlayer) { public State handle(final MockPlayer mockPlayer) {
mockPlayer.setHealth(0); mockPlayer.setHealth(0);
return State.ACCEPTED; return State.ACCEPTED;
} }

View file

@ -25,12 +25,10 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.types.ConsumerService; import cloud.commandframework.services.types.ConsumerService;
import javax.annotation.Nonnull;
public class InterruptingMockConsumer implements MockConsumerService { public class InterruptingMockConsumer implements MockConsumerService {
@Override @Override
public void accept(@Nonnull final MockService.MockContext mockContext) { public void accept(final MockService.MockContext mockContext) {
ConsumerService.interrupt(); ConsumerService.interrupt();
} }

View file

@ -25,13 +25,12 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.ChunkedRequestContext; import cloud.commandframework.services.ChunkedRequestContext;
import javax.annotation.Nonnull;
import java.util.Collection; import java.util.Collection;
public class MockChunkedRequest public class MockChunkedRequest
extends ChunkedRequestContext<MockChunkedRequest.Animal, MockChunkedRequest.Sound> { extends ChunkedRequestContext<MockChunkedRequest.Animal, MockChunkedRequest.Sound> {
public MockChunkedRequest(@Nonnull final Collection<Animal> requests) { public MockChunkedRequest(final Collection<Animal> requests) {
super(requests); super(requests);
} }
@ -39,11 +38,10 @@ public class MockChunkedRequest
private final String name; private final String name;
public Animal(@Nonnull final String name) { public Animal(final String name) {
this.name = name; this.name = name;
} }
@Nonnull
public String getName() { public String getName() {
return this.name; return this.name;
} }
@ -54,11 +52,10 @@ public class MockChunkedRequest
private final String sound; private final String sound;
public Sound(@Nonnull final String sound) { public Sound(final String sound) {
this.sound = sound; this.sound = sound;
} }
@Nonnull
public String getSound() { public String getSound() {
return this.sound; return this.sound;
} }

View file

@ -26,15 +26,11 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.ExecutionOrder; import cloud.commandframework.services.ExecutionOrder;
import cloud.commandframework.services.annotations.Order; import cloud.commandframework.services.annotations.Order;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Order(ExecutionOrder.FIRST) @Order(ExecutionOrder.FIRST)
public class MockOrderedFirst implements MockService { public class MockOrderedFirst implements MockService {
@Nullable
@Override @Override
public MockResult handle(@Nonnull final MockContext mockContext) { public MockResult handle(final MockContext mockContext) {
return new MockResult(1); return new MockResult(1);
} }

View file

@ -26,15 +26,11 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.ExecutionOrder; import cloud.commandframework.services.ExecutionOrder;
import cloud.commandframework.services.annotations.Order; import cloud.commandframework.services.annotations.Order;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Order(ExecutionOrder.LAST) @Order(ExecutionOrder.LAST)
public class MockOrderedLast implements MockService { public class MockOrderedLast implements MockService {
@Nullable
@Override @Override
public MockResult handle(@Nonnull final MockContext mockContext) { public MockResult handle(final MockContext mockContext) {
return new MockResult(2); return new MockResult(2);
} }

View file

@ -26,13 +26,10 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.State; import cloud.commandframework.services.State;
import cloud.commandframework.services.types.SideEffectService; import cloud.commandframework.services.types.SideEffectService;
import javax.annotation.Nonnull;
public class MockResultConsumer implements SideEffectService<MockService.MockResult> { public class MockResultConsumer implements SideEffectService<MockService.MockResult> {
@Nonnull
@Override @Override
public State handle(@Nonnull final MockService.MockResult mockResultConsumer) { public State handle(final MockService.MockResult mockResultConsumer) {
return State.ACCEPTED; return State.ACCEPTED;
} }

View file

@ -25,8 +25,6 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import javax.annotation.Nonnull;
public interface MockService extends Service<MockService.MockContext, MockService.MockResult> { public interface MockService extends Service<MockService.MockContext, MockService.MockResult> {
class MockContext { class MockContext {
@ -34,21 +32,19 @@ public interface MockService extends Service<MockService.MockContext, MockServic
private final String string; private final String string;
private String state = ""; private String state = "";
public MockContext(@Nonnull final String string) { public MockContext( final String string) {
this.string = string; this.string = string;
} }
@Nonnull
public String getString() { public String getString() {
return this.string; return this.string;
} }
@Nonnull
public String getState() { public String getState() {
return this.state; return this.state;
} }
public void setState(@Nonnull final String state) { public void setState( final String state) {
this.state = state; this.state = state;
} }

View file

@ -23,15 +23,12 @@
// //
package cloud.commandframework.services.mock; package cloud.commandframework.services.mock;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Predicate; import java.util.function.Predicate;
public class SecondaryMockService implements MockService, Predicate<MockService.MockContext> { public class SecondaryMockService implements MockService, Predicate<MockService.MockContext> {
@Nullable
@Override @Override
public MockResult handle(@Nonnull final MockContext mockContext) { public MockResult handle(final MockContext mockContext) {
return new MockResult(999); return new MockResult(999);
} }

View file

@ -25,13 +25,10 @@ package cloud.commandframework.services.mock;
import cloud.commandframework.services.State; import cloud.commandframework.services.State;
import javax.annotation.Nonnull;
public class SecondaryMockSideEffectService implements MockSideEffectService { public class SecondaryMockSideEffectService implements MockSideEffectService {
@Nonnull
@Override @Override
public State handle(@Nonnull final MockPlayer mockPlayer) { public State handle(final MockPlayer mockPlayer) {
return null; return null;
} }

View file

@ -23,12 +23,10 @@
// //
package cloud.commandframework.services.mock; package cloud.commandframework.services.mock;
import javax.annotation.Nonnull;
public class StateSettingConsumerService implements MockConsumerService { public class StateSettingConsumerService implements MockConsumerService {
@Override @Override
public void accept(@Nonnull final MockService.MockContext mockContext) { public void accept(final MockService.MockContext mockContext) {
mockContext.setState(""); mockContext.setState("");
} }