diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java b/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java index 2f69e3ac..e82f0e21 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java @@ -25,8 +25,8 @@ package cloud.commandframework; import cloud.commandframework.arguments.CommandArgument; import cloud.commandframework.arguments.StaticArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -40,7 +40,7 @@ public final class CommandHelpHandler { private final CommandManager commandManager; - CommandHelpHandler(@Nonnull final CommandManager commandManager) { + CommandHelpHandler(@NonNull final CommandManager commandManager) { this.commandManager = commandManager; } @@ -49,8 +49,7 @@ public final class CommandHelpHandler { * * @return Syntax hints for all registered commands, order in lexicographical order */ - @Nonnull - public List> getAllCommands() { + public @NonNull List<@NonNull VerboseHelpEntry> getAllCommands() { final List> syntaxHints = new ArrayList<>(); for (final Command command : this.commandManager.getCommands()) { final List> arguments = command.getArguments(); @@ -71,8 +70,7 @@ public final class CommandHelpHandler { * * @return Longest shared command chains */ - @Nonnull - public List getLongestSharedChains() { + public @NonNull List<@NonNull String> getLongestSharedChains() { final List chains = new ArrayList<>(); this.commandManager.getCommandTree().getRootNodes().forEach(node -> chains.add(node.getValue() @@ -91,9 +89,9 @@ public final class CommandHelpHandler { private final String syntaxString; private final String description; - private VerboseHelpEntry(@Nonnull final Command command, - @Nonnull final String syntaxString, - @Nonnull final String description) { + private VerboseHelpEntry(@NonNull final Command command, + @NonNull final String syntaxString, + @NonNull final String description) { this.command = command; this.syntaxString = syntaxString; this.description = description; @@ -104,8 +102,7 @@ public final class CommandHelpHandler { * * @return Command */ - @Nonnull - public Command getCommand() { + public @NonNull Command getCommand() { return this.command; } @@ -114,8 +111,7 @@ public final class CommandHelpHandler { * * @return Syntax string */ - @Nonnull - public String getSyntaxString() { + public @NonNull String getSyntaxString() { return this.syntaxString; } @@ -124,7 +120,7 @@ public final class CommandHelpHandler { * * @return Command description */ - public String getDescription() { + public @NonNull String getDescription() { return this.description; } } @@ -135,7 +131,7 @@ public final class CommandHelpHandler { * @param query Query string * @return Help topic, will return an empty {@link IndexHelpTopic} if no results were found */ - public HelpTopic queryHelp(@Nonnull final String query) { + public @NonNull HelpTopic queryHelp(@NonNull final String query) { if (query.replace(" ", "").isEmpty()) { return new IndexHelpTopic<>(this.getAllCommands()); } @@ -265,7 +261,7 @@ public final class CommandHelpHandler { private final List> entries; - private IndexHelpTopic(@Nonnull final List> entries) { + private IndexHelpTopic(@NonNull final List<@NonNull VerboseHelpEntry> entries) { this.entries = entries; } @@ -274,8 +270,7 @@ public final class CommandHelpHandler { * * @return Entries */ - @Nonnull - public List> getEntries() { + public @NonNull List<@NonNull VerboseHelpEntry> getEntries() { return this.entries; } @@ -301,7 +296,7 @@ public final class CommandHelpHandler { private final Command command; private final String description; - private VerboseHelpTopic(@Nonnull final Command command) { + private VerboseHelpTopic(@NonNull final Command command) { this.command = command; final String shortDescription = command.getCommandMeta().getOrDefault("description", "No description"); this.description = command.getCommandMeta().getOrDefault("long-description", shortDescription); @@ -312,8 +307,7 @@ public final class CommandHelpHandler { * * @return Command */ - @Nonnull - public Command getCommand() { + public @NonNull Command getCommand() { return this.command; } @@ -322,8 +316,7 @@ public final class CommandHelpHandler { * * @return Command description */ - @Nonnull - public String getDescription() { + public @NonNull String getDescription() { return this.description; } @@ -340,7 +333,8 @@ public final class CommandHelpHandler { private final String longestPath; private final List childSuggestions; - private MultiHelpTopic(@Nonnull final String longestPath, @Nonnull final List childSuggestions) { + private MultiHelpTopic(@NonNull final String longestPath, + @NonNull final List<@NonNull String> childSuggestions) { this.longestPath = longestPath; this.childSuggestions = childSuggestions; } @@ -350,8 +344,7 @@ public final class CommandHelpHandler { * * @return Longest path */ - @Nonnull - public String getLongestPath() { + public @NonNull String getLongestPath() { return this.longestPath; } @@ -360,8 +353,7 @@ public final class CommandHelpHandler { * * @return Child suggestions */ - @Nonnull - public List getChildSuggestions() { + public @NonNull List<@NonNull String> getChildSuggestions() { return this.childSuggestions; } diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java index 0ec5b9c4..79f51161 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java @@ -51,9 +51,9 @@ import cloud.commandframework.permission.OrPermission; import cloud.commandframework.permission.Permission; import cloud.commandframework.services.ServicePipeline; import cloud.commandframework.services.State; +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.Collection; import java.util.Collections; import java.util.EnumSet; @@ -96,8 +96,8 @@ public abstract class CommandManager { * @param commandRegistrationHandler Command registration handler */ public CommandManager( - @Nonnull final Function, CommandExecutionCoordinator> commandExecutionCoordinator, - @Nonnull final CommandRegistrationHandler commandRegistrationHandler) { + @NonNull final Function<@NonNull CommandTree, @NonNull CommandExecutionCoordinator> commandExecutionCoordinator, + @NonNull final CommandRegistrationHandler commandRegistrationHandler) { this.commandTree = CommandTree.newTree(this); this.commandExecutionCoordinator = commandExecutionCoordinator.apply(commandTree); this.commandRegistrationHandler = commandRegistrationHandler; @@ -113,8 +113,7 @@ public abstract class CommandManager { * @param input Input string * @return List of tokens */ - @Nonnull - public static LinkedList tokenize(@Nonnull final String input) { + public static @NonNull LinkedList<@NonNull String> tokenize(@NonNull final String input) { final StringTokenizer stringTokenizer = new StringTokenizer(input, " "); final LinkedList tokens = new LinkedList<>(); while (stringTokenizer.hasMoreElements()) { @@ -133,8 +132,8 @@ public abstract class CommandManager { * @param input Input provided by the sender * @return Command result */ - @Nonnull - public CompletableFuture> executeCommand(@Nonnull final C commandSender, @Nonnull final String input) { + public @NonNull CompletableFuture> executeCommand(@NonNull final C commandSender, + @NonNull final String input) { final CommandContext context = this.commandContextFactory.create(false, commandSender); final LinkedList inputQueue = tokenize(input); try { @@ -158,8 +157,8 @@ public abstract class CommandManager { * @param input Input provided by the sender * @return List of suggestions */ - @Nonnull - public List suggest(@Nonnull final C commandSender, @Nonnull final String input) { + public @NonNull List<@NonNull String> suggest(@NonNull final C commandSender, + @NonNull final String input) { final CommandContext context = this.commandContextFactory.create(true, commandSender); final LinkedList inputQueue = tokenize(input); if (this.preprocessContext(context, inputQueue) == State.ACCEPTED) { @@ -177,7 +176,7 @@ public abstract class CommandManager { * @param command Command to register * @return The command manager instance */ - public CommandManager command(@Nonnull final Command command) { + public @NonNull CommandManager command(@NonNull final Command command) { this.commandTree.insertCommand(command); this.commands.add(command); return this; @@ -188,8 +187,7 @@ public abstract class CommandManager { * * @return Command syntax formatter */ - @Nonnull - public CommandSyntaxFormatter getCommandSyntaxFormatter() { + public @NonNull CommandSyntaxFormatter getCommandSyntaxFormatter() { return this.commandSyntaxFormatter; } @@ -198,7 +196,7 @@ public abstract class CommandManager { * * @param commandSyntaxFormatter New formatter */ - public void setCommandSyntaxFormatter(@Nonnull final CommandSyntaxFormatter commandSyntaxFormatter) { + public void setCommandSyntaxFormatter(@NonNull final CommandSyntaxFormatter commandSyntaxFormatter) { this.commandSyntaxFormatter = commandSyntaxFormatter; } @@ -207,12 +205,11 @@ public abstract class CommandManager { * * @return Command registration handler */ - @Nonnull - protected CommandRegistrationHandler getCommandRegistrationHandler() { + protected @NonNull CommandRegistrationHandler getCommandRegistrationHandler() { return this.commandRegistrationHandler; } - protected final void setCommandRegistrationHandler(@Nonnull final CommandRegistrationHandler commandRegistrationHandler) { + protected final void setCommandRegistrationHandler(@NonNull final CommandRegistrationHandler commandRegistrationHandler) { this.commandRegistrationHandler = commandRegistrationHandler; } @@ -224,7 +221,8 @@ public abstract class CommandManager { * @param permission Permission node * @return {@code true} if the sender has the permission, else {@code false} */ - public boolean hasPermission(@Nonnull final C sender, @Nonnull final CommandPermission permission) { + public boolean hasPermission(@NonNull final C sender, + @NonNull final CommandPermission permission) { if (permission.toString().isEmpty()) { return true; } @@ -250,7 +248,7 @@ public abstract class CommandManager { * @param permission Permission node * @return {@code true} if the sender has the permission, else {@code false} */ - public abstract boolean hasPermission(@Nonnull C sender, @Nonnull String permission); + public abstract boolean hasPermission(@NonNull C sender, @NonNull String permission); /** * Create a new command builder @@ -261,11 +259,10 @@ public abstract class CommandManager { * @param meta Command meta * @return Builder instance */ - @Nonnull - public Command.Builder commandBuilder(@Nonnull final String name, - @Nonnull final Collection aliases, - @Nonnull final Description description, - @Nonnull final CommandMeta meta) { + public Command.@NonNull Builder commandBuilder(@NonNull final String name, + @NonNull final Collection aliases, + @NonNull final Description description, + @NonNull final CommandMeta meta) { return Command.newBuilder(name, meta, description, aliases.toArray(new String[0])); } @@ -277,10 +274,9 @@ public abstract class CommandManager { * @param meta Command meta * @return Builder instance */ - @Nonnull - public Command.Builder commandBuilder(@Nonnull final String name, - @Nonnull final Collection aliases, - @Nonnull final CommandMeta meta) { + public Command.@NonNull Builder commandBuilder(@NonNull final String name, + @NonNull final Collection aliases, + @NonNull final CommandMeta meta) { return Command.newBuilder(name, meta, Description.empty(), aliases.toArray(new String[0])); } @@ -293,11 +289,10 @@ public abstract class CommandManager { * @param aliases Command aliases * @return Builder instance */ - @Nonnull - public Command.Builder commandBuilder(@Nonnull final String name, - @Nonnull final CommandMeta meta, - @Nonnull final Description description, - @Nonnull final String... aliases) { + public Command.@NonNull Builder commandBuilder(@NonNull final String name, + @NonNull final CommandMeta meta, + @NonNull final Description description, + @NonNull final String... aliases) { return Command.newBuilder(name, meta, description, aliases); } @@ -309,10 +304,9 @@ public abstract class CommandManager { * @param aliases Command aliases * @return Builder instance */ - @Nonnull - public Command.Builder commandBuilder(@Nonnull final String name, - @Nonnull final CommandMeta meta, - @Nonnull final String... aliases) { + public Command.@NonNull Builder commandBuilder(@NonNull final String name, + @NonNull final CommandMeta meta, + @NonNull final String... aliases) { return Command.newBuilder(name, meta, Description.empty(), aliases); } @@ -326,10 +320,9 @@ public abstract class CommandManager { * @throws UnsupportedOperationException If the command manager does not support default command meta creation * @see #createDefaultCommandMeta() Default command meta creation */ - @Nonnull - public Command.Builder commandBuilder(@Nonnull final String name, - @Nonnull final Description description, - @Nonnull final String... aliases) { + public Command.@NonNull Builder commandBuilder(@NonNull final String name, + @NonNull final Description description, + @NonNull final String... aliases) { return Command.newBuilder(name, this.createDefaultCommandMeta(), description, aliases).manager(this); } @@ -342,9 +335,8 @@ public abstract class CommandManager { * @throws UnsupportedOperationException If the command manager does not support default command meta creation * @see #createDefaultCommandMeta() Default command meta creation */ - @Nonnull - public Command.Builder commandBuilder(@Nonnull final String name, - @Nonnull final String... aliases) { + public Command.@NonNull Builder commandBuilder(@NonNull final String name, + @NonNull final String... aliases) { return Command.newBuilder(name, this.createDefaultCommandMeta(), Description.empty(), aliases).manager(this); } @@ -356,8 +348,8 @@ public abstract class CommandManager { * @param Generic argument name * @return Argument builder */ - @Nonnull - public CommandArgument.Builder argumentBuilder(@Nonnull final Class type, @Nonnull final String name) { + public CommandArgument.@NonNull Builder argumentBuilder(@NonNull final Class type, + @NonNull final String name) { return CommandArgument.ofType(type, name).manager(this); } @@ -367,8 +359,7 @@ public abstract class CommandManager { * * @return Command tree */ - @Nonnull - public CommandTree getCommandTree() { + public @NonNull CommandTree getCommandTree() { return this.commandTree; } @@ -378,8 +369,7 @@ public abstract class CommandManager { * @return Default command meta * @throws UnsupportedOperationException If the command manager does not support this operation */ - @Nonnull - public abstract CommandMeta createDefaultCommandMeta(); + public abstract @NonNull CommandMeta createDefaultCommandMeta(); /** * Register a new command preprocessor. The order they are registered in is respected, and they @@ -388,7 +378,7 @@ public abstract class CommandManager { * @param processor Processor to register * @see #preprocessContext(CommandContext, LinkedList) Preprocess a context */ - public void registerCommandPreProcessor(@Nonnull final CommandPreprocessor processor) { + public void registerCommandPreProcessor(@NonNull final CommandPreprocessor processor) { this.servicePipeline.registerServiceImplementation(new TypeToken>() { }, processor, Collections.emptyList()); @@ -401,7 +391,7 @@ public abstract class CommandManager { * @param processor Processor to register * @see #preprocessContext(CommandContext, LinkedList) Preprocess a context */ - public void registerCommandPostProcessor(@Nonnull final CommandPostprocessor processor) { + public void registerCommandPostProcessor(@NonNull final CommandPostprocessor processor) { this.servicePipeline.registerServiceImplementation(new TypeToken>() { }, processor, Collections.emptyList()); @@ -415,7 +405,8 @@ public abstract class CommandManager { * @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED} * @see #registerCommandPreProcessor(CommandPreprocessor) Register a command preprocessor */ - public State preprocessContext(@Nonnull final CommandContext context, @Nonnull final LinkedList inputQueue) { + public State preprocessContext(@NonNull final CommandContext context, + @NonNull final LinkedList<@NonNull String> inputQueue) { this.servicePipeline.pump(new CommandPreprocessingContext<>(context, inputQueue)) .through(new TypeToken>() { }) @@ -433,7 +424,8 @@ public abstract class CommandManager { * @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED} * @see #registerCommandPostProcessor(CommandPostprocessor) Register a command postprocessor */ - public State postprocessContext(@Nonnull final CommandContext context, @Nonnull final Command command) { + public State postprocessContext(@NonNull final CommandContext context, + @NonNull final Command command) { this.servicePipeline.pump(new CommandPostprocessingContext<>(context, command)) .through(new TypeToken>() { }) @@ -449,8 +441,7 @@ public abstract class CommandManager { * @return Command suggestions processor * @see #setCommandSuggestionProcessor(CommandSuggestionProcessor) Setting the suggestion processor */ - @Nonnull - public CommandSuggestionProcessor getCommandSuggestionProcessor() { + public @NonNull CommandSuggestionProcessor getCommandSuggestionProcessor() { return this.commandSuggestionProcessor; } @@ -461,7 +452,7 @@ public abstract class CommandManager { * * @param commandSuggestionProcessor New command suggestions processor */ - public void setCommandSuggestionProcessor(@Nonnull final CommandSuggestionProcessor commandSuggestionProcessor) { + public void setCommandSuggestionProcessor(@NonNull final CommandSuggestionProcessor commandSuggestionProcessor) { this.commandSuggestionProcessor = commandSuggestionProcessor; } @@ -478,7 +469,6 @@ public abstract class CommandManager { * * @return Parser registry instance */ - @Nonnull public ParserRegistry getParserRegistry() { return this.parserRegistry; } @@ -491,8 +481,8 @@ public abstract class CommandManager { * @return Exception handler, or {@code null} * @see #registerCommandPreProcessor(CommandPreprocessor) Registering an exception handler */ - @Nullable - public final BiConsumer getExceptionHandler(@Nullable final Class clazz) { + public final @Nullable BiConsumer<@NonNull C, @NonNull E> + getExceptionHandler(@NonNull final Class clazz) { final BiConsumer consumer = this.exceptionHandlers.get(clazz); if (consumer == null) { return null; @@ -510,8 +500,8 @@ public abstract class CommandManager { * @param handler Exception handler * @param Exception type */ - public final void registerExceptionHandler(@Nonnull final Class clazz, - @Nonnull final BiConsumer handler) { + public final void registerExceptionHandler(@NonNull final Class clazz, + @NonNull final BiConsumer<@NonNull C, @NonNull E> handler) { this.exceptionHandlers.put(clazz, handler); } @@ -526,10 +516,10 @@ public abstract class CommandManager { * handler stored for the exception type * @param Exception type */ - public final void handleException(@Nonnull final C sender, - @Nonnull final Class clazz, - @Nonnull final E exception, - @Nonnull final BiConsumer defaultHandler) { + public final void handleException(@NonNull final C sender, + @NonNull final Class clazz, + @NonNull final E exception, + @NonNull final BiConsumer defaultHandler) { Optional.ofNullable(this.getExceptionHandler(clazz)).orElse(defaultHandler).accept(sender, exception); } @@ -538,8 +528,7 @@ public abstract class CommandManager { * * @return Unmodifiable view of all registered commands */ - @Nonnull - public final Collection> getCommands() { + public final @NonNull Collection<@NonNull Command> getCommands() { return Collections.unmodifiableCollection(this.commands); } @@ -550,8 +539,7 @@ public abstract class CommandManager { * @return Command help handler. A new instance will be created * each time this method is called. */ - @Nonnull - public final CommandHelpHandler getCommandHelpHandler() { + public final @NonNull CommandHelpHandler getCommandHelpHandler() { return new CommandHelpHandler<>(this); } @@ -561,7 +549,7 @@ public abstract class CommandManager { * @param setting Setting * @return {@code true} if the setting is activated or {@code false} if it's not */ - public boolean getSetting(@Nonnull final ManagerSettings setting) { + public boolean getSetting(@NonNull final ManagerSettings setting) { return this.managerSettings.contains(setting); } @@ -571,7 +559,7 @@ public abstract class CommandManager { * @param setting Setting to set * @param value Value */ - public void setSetting(@Nonnull final ManagerSettings setting, + public void setSetting(@NonNull final ManagerSettings setting, final boolean value) { if (value) { this.managerSettings.add(setting); diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java index 1d396d8b..308ed92b 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java @@ -28,31 +28,13 @@ import cloud.commandframework.arguments.StaticArgument; import cloud.commandframework.arguments.compound.CompoundArgument; import cloud.commandframework.arguments.parser.ArgumentParseResult; import cloud.commandframework.context.CommandContext; -import cloud.commandframework.exceptions.AmbiguousNodeException; -import cloud.commandframework.exceptions.ArgumentParseException; -import cloud.commandframework.exceptions.InvalidCommandSenderException; -import cloud.commandframework.exceptions.InvalidSyntaxException; -import cloud.commandframework.exceptions.NoCommandInLeafException; -import cloud.commandframework.exceptions.NoPermissionException; -import cloud.commandframework.exceptions.NoSuchCommandException; +import cloud.commandframework.exceptions.*; import cloud.commandframework.permission.CommandPermission; import cloud.commandframework.permission.OrPermission; +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.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Queue; +import java.util.*; import java.util.stream.Collectors; /** @@ -89,7 +71,7 @@ public final class CommandTree { private final Node> internalTree = new Node<>(null); private final CommandManager commandManager; - private CommandTree(@Nonnull final CommandManager commandManager) { + private CommandTree(@NonNull final CommandManager commandManager) { this.commandManager = commandManager; } @@ -100,8 +82,7 @@ public final class CommandTree { * @param Command sender type * @return New command tree */ - @Nonnull - public static CommandTree newTree(@Nonnull final CommandManager commandManager) { + public static @NonNull CommandTree newTree(@NonNull final CommandManager commandManager) { return new CommandTree<>(commandManager); } @@ -115,8 +96,8 @@ public final class CommandTree { * @throws NoPermissionException If the sender lacks permission to execute the command * @throws InvalidSyntaxException If the command syntax is invalid */ - public Optional> parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue args) throws + public @NonNull Optional> parse(@NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> args) throws NoSuchCommandException, NoPermissionException, InvalidSyntaxException { final Optional> commandOptional = parseCommand(new ArrayList<>(), commandContext, @@ -130,10 +111,10 @@ public final class CommandTree { return commandOptional; } - private Optional> parseCommand(@Nonnull final List> parsedArguments, - @Nonnull final CommandContext commandContext, - @Nonnull final Queue commandQueue, - @Nonnull final Node> root) { + private Optional> parseCommand(@NonNull final List<@NonNull CommandArgument> parsedArguments, + @NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> commandQueue, + @NonNull final Node<@Nullable CommandArgument> root) { CommandPermission permission = this.isPermitted(commandContext.getSender(), root); if (permission != null) { throw new NoPermissionException(permission, commandContext.getSender(), this.getChain(root) @@ -225,11 +206,11 @@ public final class CommandTree { } } - @Nullable - private Optional> attemptParseUnambiguousChild(@Nonnull final List> parsedArguments, - @Nonnull final CommandContext commandContext, - @Nonnull final Node> root, - @Nonnull final Queue commandQueue) { + private @Nullable Optional> + attemptParseUnambiguousChild(@NonNull final List<@NonNull CommandArgument> parsedArguments, + @NonNull final CommandContext commandContext, + @NonNull final Node<@Nullable CommandArgument> root, + @NonNull final Queue commandQueue) { CommandPermission permission; final List>> children = root.getChildren(); if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) { @@ -343,15 +324,14 @@ public final class CommandTree { * @param commandQueue Input queue * @return String suggestions. These should be filtered based on {@link String#startsWith(String)} */ - @Nonnull - public List getSuggestions(@Nonnull final CommandContext context, @Nonnull final Queue commandQueue) { + public @NonNull List<@NonNull String> getSuggestions(@NonNull final CommandContext context, + @NonNull final Queue<@NonNull String> commandQueue) { return getSuggestions(context, commandQueue, this.internalTree); } - @Nonnull - private List getSuggestions(@Nonnull final CommandContext commandContext, - @Nonnull final Queue commandQueue, - @Nonnull final Node> root) { + private @NonNull List<@NonNull String> getSuggestions(@NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> commandQueue, + @NonNull final Node<@Nullable CommandArgument> root) { /* If the sender isn't allowed to access the root node, no suggestions are needed */ if (this.isPermitted(commandContext.getSender(), root) != null) { @@ -432,8 +412,7 @@ public final class CommandTree { } } - @Nonnull - private String stringOrEmpty(@Nullable final String string) { + private @NonNull String stringOrEmpty(@Nullable final String string) { if (string == null) { return ""; } @@ -446,7 +425,7 @@ public final class CommandTree { * @param command Command to insert */ @SuppressWarnings("unchecked") - public void insertCommand(@Nonnull final Command command) { + public void insertCommand(@NonNull final Command command) { synchronized (this.commandLock) { Node> node = this.internalTree; for (final CommandArgument argument : command.getArguments()) { @@ -478,8 +457,8 @@ public final class CommandTree { } } - @Nullable - private CommandPermission isPermitted(@Nonnull final C sender, @Nonnull final Node> node) { + private @Nullable CommandPermission isPermitted(@NonNull final C sender, + @NonNull final Node<@Nullable CommandArgument> node) { final CommandPermission permission = (CommandPermission) node.nodeMeta.get("permission"); if (permission != null) { return this.commandManager.hasPermission(sender, permission) ? null : permission; @@ -569,7 +548,7 @@ public final class CommandTree { }); } - private void checkAmbiguity(@Nonnull final Node> node) throws AmbiguousNodeException { + private void checkAmbiguity(@NonNull final Node<@Nullable CommandArgument> node) throws AmbiguousNodeException { if (node.isLeaf()) { return; } @@ -584,7 +563,8 @@ public final class CommandTree { node.children.forEach(this::checkAmbiguity); } - private List>> getLeavesRaw(@Nonnull final Node> node) { + private @NonNull List<@NonNull Node<@Nullable CommandArgument>> + getLeavesRaw(@NonNull final Node<@Nullable CommandArgument> node) { final List>> leaves = new LinkedList<>(); if (node.isLeaf()) { if (node.getValue() != null) { @@ -596,7 +576,7 @@ public final class CommandTree { return leaves; } - private List> getLeaves(@Nonnull final Node> node) { + private @NonNull List<@NonNull CommandArgument> getLeaves(@NonNull final Node<@NonNull CommandArgument> node) { final List> leaves = new LinkedList<>(); if (node.isLeaf()) { if (node.getValue() != null) { @@ -608,7 +588,8 @@ public final class CommandTree { return leaves; } - private List>> getChain(@Nullable final Node> end) { + private @NonNull List<@NonNull Node<@Nullable CommandArgument>> + getChain(@Nullable final Node<@Nullable CommandArgument> end) { final List>> chain = new LinkedList<>(); Node> tail = end; while (tail != null) { @@ -619,8 +600,7 @@ public final class CommandTree { return chain; } - @Nullable - private Command cast(@Nullable final Command command) { + private @Nullable Command cast(@Nullable final Command command) { return command; } @@ -630,8 +610,7 @@ public final class CommandTree { * * @return Root nodes */ - @Nonnull - public Collection>> getRootNodes() { + public @NonNull Collection<@NonNull Node<@Nullable CommandArgument>> getRootNodes() { return this.internalTree.getChildren(); } @@ -641,8 +620,7 @@ public final class CommandTree { * @param name Root node name * @return Root node, or {@code null} */ - @Nullable - public Node> getNamedNode(@Nullable final String name) { + public @Nullable Node<@Nullable CommandArgument> getNamedNode(@Nullable final String name) { for (final Node> node : this.getRootNodes()) { if (node.getValue() != null && node.getValue() instanceof StaticArgument) { @SuppressWarnings("unchecked") final StaticArgument staticArgument = (StaticArgument) node.getValue(); @@ -661,8 +639,7 @@ public final class CommandTree { * * @return Command manager */ - @Nonnull - public CommandManager getCommandManager() { + public @NonNull CommandManager getCommandManager() { return this.commandManager; } @@ -687,20 +664,17 @@ public final class CommandTree { * * @return Children */ - @Nonnull - public List> getChildren() { + public @NonNull List<@NonNull Node<@Nullable T>> getChildren() { return Collections.unmodifiableList(this.children); } - @Nonnull - private Node addChild(@Nonnull final T child) { + private @NonNull Node<@Nullable T> addChild(@NonNull final T child) { final Node node = new Node<>(child); this.children.add(node); return node; } - @Nullable - private Node getChild(@Nonnull final T type) { + private @Nullable Node<@Nullable T> getChild(@NonNull final T type) { for (final Node child : this.children) { if (type.equals(child.getValue())) { return child; @@ -723,8 +697,7 @@ public final class CommandTree { * * @return Node meta */ - @Nonnull - public Map getNodeMeta() { + public @NonNull Map<@NonNull String, @NonNull Object> getNodeMeta() { return this.nodeMeta; } @@ -733,8 +706,7 @@ public final class CommandTree { * * @return Node value */ - @Nullable - public T getValue() { + public @Nullable T getValue() { return this.value; } @@ -760,8 +732,7 @@ public final class CommandTree { * * @return Parent node */ - @Nullable - public Node getParent() { + public @Nullable Node<@Nullable T> getParent() { return this.parent; } @@ -770,7 +741,7 @@ public final class CommandTree { * * @param parent new parent node */ - public void setParent(@Nullable final Node parent) { + public void setParent(@Nullable final Node<@Nullable T> parent) { this.parent = parent; } diff --git a/cloud-core/src/main/java/cloud/commandframework/Description.java b/cloud-core/src/main/java/cloud/commandframework/Description.java index 1a314636..8c28bc91 100644 --- a/cloud-core/src/main/java/cloud/commandframework/Description.java +++ b/cloud-core/src/main/java/cloud/commandframework/Description.java @@ -24,8 +24,7 @@ package cloud.commandframework; import cloud.commandframework.arguments.CommandArgument; - -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * {@link CommandArgument} description @@ -39,7 +38,7 @@ public final class Description { private final String description; - private Description(@Nonnull final String description) { + private Description(@NonNull final String description) { this.description = description; } @@ -48,8 +47,7 @@ public final class Description { * * @return Command description */ - @Nonnull - public static Description empty() { + public static @NonNull Description empty() { return EMPTY; } @@ -59,8 +57,7 @@ public final class Description { * @param string Command description * @return Created command description */ - @Nonnull - public static Description of(@Nonnull final String string) { + public static @NonNull Description of(@NonNull final String string) { return new Description(string); } @@ -69,8 +66,7 @@ public final class Description { * * @return Command description */ - @Nonnull - public String getDescription() { + public @NonNull String getDescription() { return this.description; } @@ -79,9 +75,8 @@ public final class Description { * * @return Command description */ - @Nonnull @Override - public String toString() { + public @NonNull String toString() { return this.description; } diff --git a/cloud-core/src/main/java/cloud/commandframework/annotations/specifier/Range.java b/cloud-core/src/main/java/cloud/commandframework/annotations/specifier/Range.java index 5ccbd8d8..0e5da1a9 100644 --- a/cloud-core/src/main/java/cloud/commandframework/annotations/specifier/Range.java +++ b/cloud-core/src/main/java/cloud/commandframework/annotations/specifier/Range.java @@ -24,8 +24,8 @@ package cloud.commandframework.annotations.specifier; import cloud.commandframework.arguments.parser.ArgumentParser; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -44,13 +44,13 @@ public @interface Range { * * @return String serialized number */ - @Nonnull String min() default ""; + @NonNull String min() default ""; /** * Maximum value accepted by the parser * * @return String serialized number */ - @Nonnull String max() default ""; + @NonNull String max() default ""; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/CommandArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/CommandArgument.java index 76b2df91..b48c9716 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/CommandArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/CommandArgument.java @@ -30,6 +30,8 @@ import cloud.commandframework.CommandManager; import cloud.commandframework.arguments.parser.ArgumentParseResult; import cloud.commandframework.arguments.parser.ParserParameters; import cloud.commandframework.context.CommandContext; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; import java.util.Objects; @@ -94,10 +96,10 @@ public class CommandArgument implements Comparable> * @param suggestionsProvider Suggestions provider */ public CommandArgument(final boolean required, - @Nonnull final String name, - @Nonnull final ArgumentParser parser, - @Nonnull final String defaultValue, - @Nonnull final TypeToken valueType, + @NonNull final String name, + @NonNull final ArgumentParser parser, + @NonNull final String defaultValue, + @NonNull final TypeToken valueType, @Nullable final BiFunction, String, List> suggestionsProvider) { this.required = required; this.name = Objects.requireNonNull(name, "Name may not be null"); @@ -140,14 +142,14 @@ public class CommandArgument implements Comparable> * @param valueType Type produced by the parser */ public CommandArgument(final boolean required, - @Nonnull final String name, - @Nonnull final ArgumentParser parser, - @Nonnull final Class valueType) { + @NonNull final String name, + @NonNull final ArgumentParser parser, + @NonNull final Class valueType) { this(required, name, parser, "", valueType, null); } - private static BiFunction, String, List> buildDefaultSuggestionsProvider( - @Nonnull final CommandArgument argument) { + private static @NonNull BiFunction<@NonNull CommandContext, @NonNull String, + @NonNull List> buildDefaultSuggestionsProvider(@NonNull final CommandArgument argument) { return new DelegatingSuggestionsProvider<>(argument.getName(), argument.getParser()); } @@ -175,9 +177,8 @@ public class CommandArgument implements Comparable> * @param Argument Type. Used to make the compiler happy. * @return Argument builder */ - @Nonnull - public static CommandArgument.Builder ofType(@Nonnull final Class clazz, - @Nonnull final String name) { + public static CommandArgument.@NonNull Builder<@NonNull C, @NonNull T> ofType(@NonNull final Class clazz, + @NonNull final String name) { return new Builder<>(TypeToken.get(clazz), name); } @@ -195,8 +196,7 @@ public class CommandArgument implements Comparable> * * @return Argument name */ - @Nonnull - public String getName() { + public @NonNull String getName() { return this.name; } @@ -206,14 +206,12 @@ public class CommandArgument implements Comparable> * * @return Command parser */ - @Nonnull - public ArgumentParser getParser() { + public @NonNull ArgumentParser getParser() { return this.parser; } - @Nonnull @Override - public final String toString() { + public final @NonNull String toString() { return String.format("%s{name=%s}", this.getClass().getSimpleName(), this.name); } @@ -232,7 +230,7 @@ public class CommandArgument implements Comparable> * * @param owningCommand Owning command */ - public void setOwningCommand(@Nonnull final Command owningCommand) { + public void setOwningCommand(@NonNull final Command owningCommand) { if (this.owningCommand != null) { throw new IllegalStateException("Cannot replace owning command"); } @@ -244,8 +242,8 @@ public class CommandArgument implements Comparable> * * @return Suggestions provider */ - @Nonnull - public final BiFunction, String, List> getSuggestionsProvider() { + public final @NonNull BiFunction<@NonNull CommandContext, @NonNull String, + @NonNull List> getSuggestionsProvider() { return this.suggestionsProvider; } @@ -267,7 +265,7 @@ public class CommandArgument implements Comparable> } @Override - public final int compareTo(@Nonnull final CommandArgument o) { + public final int compareTo(@NonNull CommandArgument o) { if (this instanceof StaticArgument) { if (o instanceof StaticArgument) { return (this.getName().compareTo(o.getName())); @@ -288,8 +286,7 @@ public class CommandArgument implements Comparable> * * @return Default value */ - @Nonnull - public String getDefaultValue() { + public @NonNull String getDefaultValue() { return this.defaultValue; } @@ -308,8 +305,7 @@ public class CommandArgument implements Comparable> * * @return Value type */ - @Nonnull - public TypeToken getValueType() { + public @NonNull TypeToken getValueType() { return this.valueType; } @@ -318,8 +314,7 @@ public class CommandArgument implements Comparable> * * @return Copied argument */ - @Nonnull - public CommandArgument copy() { + public @NonNull CommandArgument copy() { CommandArgument.Builder builder = ofType(this.valueType, this.name); builder = builder.withSuggestionsProvider(this.suggestionsProvider); builder = builder.withParser(this.parser); @@ -349,10 +344,10 @@ public class CommandArgument implements Comparable> private boolean required = true; private ArgumentParser parser; private String defaultValue = ""; - private BiFunction, String, List> suggestionsProvider; + private BiFunction<@NonNull CommandContext, @NonNull String, @NonNull List> suggestionsProvider; - protected Builder(@Nonnull final TypeToken valueType, - @Nonnull final String name) { + protected Builder(@NonNull final TypeToken valueType, + @NonNull final String name) { this.valueType = valueType; this.name = name; } @@ -369,8 +364,7 @@ public class CommandArgument implements Comparable> * @param manager Command manager * @return Builder instance */ - @Nonnull - public Builder manager(@Nonnull final CommandManager manager) { + public @NonNull Builder<@NonNull C, @NonNull T> manager(@NonNull final CommandManager manager) { this.manager = manager; return this; } @@ -384,8 +378,7 @@ public class CommandArgument implements Comparable> * * @return Builder instance */ - @Nonnull - public Builder asRequired() { + public @NonNull Builder<@NonNull C, @NonNull T> asRequired() { this.required = true; return this; } @@ -399,8 +392,7 @@ public class CommandArgument implements Comparable> * * @return Builder instance */ - @Nonnull - public Builder asOptional() { + public @NonNull Builder<@NonNull C, @NonNull T> asOptional() { this.required = false; return this; } @@ -415,8 +407,7 @@ public class CommandArgument implements Comparable> * @param defaultValue Default value that will be used if none was supplied * @return Builder instance */ - @Nonnull - public Builder asOptionalWithDefault(@Nonnull final String defaultValue) { + public @NonNull Builder<@NonNull C, @NonNull T> asOptionalWithDefault(@NonNull final String defaultValue) { this.defaultValue = defaultValue; this.required = false; return this; @@ -428,8 +419,7 @@ public class CommandArgument implements Comparable> * @param parser Argument parser * @return Builder instance */ - @Nonnull - public Builder withParser(@Nonnull final ArgumentParser parser) { + public @NonNull Builder<@NonNull C, @NonNull T> withParser(@NonNull final ArgumentParser<@NonNull C, @NonNull T> parser) { this.parser = Objects.requireNonNull(parser, "Parser may not be null"); return this; } @@ -440,9 +430,9 @@ public class CommandArgument implements Comparable> * @param suggestionsProvider Suggestions provider * @return Builder instance */ - @Nonnull - public Builder withSuggestionsProvider( - @Nonnull final BiFunction, String, List> suggestionsProvider) { + public @NonNull Builder<@NonNull C, @NonNull T> withSuggestionsProvider( + @NonNull final BiFunction<@NonNull CommandContext, + @NonNull String, @NonNull List> suggestionsProvider) { this.suggestionsProvider = suggestionsProvider; return this; } @@ -452,8 +442,7 @@ public class CommandArgument implements Comparable> * * @return Constructed argument */ - @Nonnull - public CommandArgument build() { + public @NonNull CommandArgument<@NonNull C, @NonNull T> build() { if (this.parser == null && this.manager != null) { this.parser = this.manager.getParserRegistry().createParser(valueType, ParserParameters.empty()) .orElse(null); @@ -469,8 +458,7 @@ public class CommandArgument implements Comparable> this.defaultValue, this.valueType, this.suggestionsProvider); } - @Nonnull - protected final String getName() { + protected final @NonNull String getName() { return this.name; } @@ -478,18 +466,16 @@ public class CommandArgument implements Comparable> return this.required; } - @Nonnull - protected final ArgumentParser getParser() { + protected final @NonNull ArgumentParser<@NonNull C, @NonNull T> getParser() { return this.parser; } - @Nonnull - protected final String getDefaultValue() { + protected final @NonNull String getDefaultValue() { return this.defaultValue; } - @Nonnull - protected final BiFunction, String, List> getSuggestionsProvider() { + protected final @NonNull BiFunction<@NonNull CommandContext,@NonNull String, @NonNull List> + getSuggestionsProvider() { return this.suggestionsProvider; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/CommandSyntaxFormatter.java b/cloud-core/src/main/java/cloud/commandframework/arguments/CommandSyntaxFormatter.java index 9c09b54e..7113df7e 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/CommandSyntaxFormatter.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/CommandSyntaxFormatter.java @@ -24,9 +24,9 @@ package cloud.commandframework.arguments; import cloud.commandframework.CommandTree; +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; /** @@ -44,8 +44,7 @@ public interface CommandSyntaxFormatter { * @param node Trailing node * @return Syntax string */ - @Nonnull - String apply(@Nonnull List> commandArguments, - @Nullable CommandTree.Node> node); + @NonNull String apply(@NonNull List<@NonNull CommandArgument> commandArguments, + CommandTree.@Nullable Node<@Nullable CommandArgument> node); } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/DelegatingSuggestionsProvider.java b/cloud-core/src/main/java/cloud/commandframework/arguments/DelegatingSuggestionsProvider.java index 9af8860e..4b834e5d 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/DelegatingSuggestionsProvider.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/DelegatingSuggestionsProvider.java @@ -25,24 +25,25 @@ package cloud.commandframework.arguments; import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.context.CommandContext; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.List; import java.util.function.BiFunction; -final class DelegatingSuggestionsProvider implements BiFunction, String, List> { +final class DelegatingSuggestionsProvider implements BiFunction<@NonNull CommandContext, + @NonNull String, @NonNull List> { private final String argumentName; private final ArgumentParser parser; - DelegatingSuggestionsProvider(@Nonnull final String argumentName, @Nonnull final ArgumentParser parser) { + DelegatingSuggestionsProvider(@NonNull final String argumentName, @NonNull final ArgumentParser parser) { this.argumentName = argumentName; this.parser = parser; } @Override - public List apply(final CommandContext context, final String string) { - return this.parser.suggestions(context, string); + public @NonNull List<@NonNull String> apply(@NonNull final CommandContext context, @NonNull final String s) { + return this.parser.suggestions(context, s); } @Override diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/StandardCommandSyntaxFormatter.java b/cloud-core/src/main/java/cloud/commandframework/arguments/StandardCommandSyntaxFormatter.java index df95ce7a..2a581bd2 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/StandardCommandSyntaxFormatter.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/StandardCommandSyntaxFormatter.java @@ -25,9 +25,9 @@ package cloud.commandframework.arguments; import cloud.commandframework.CommandTree; import cloud.commandframework.arguments.compound.CompoundArgument; +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.Iterator; import java.util.List; @@ -43,10 +43,9 @@ import java.util.List; */ public class StandardCommandSyntaxFormatter implements CommandSyntaxFormatter { - @Nonnull @Override - public final String apply(@Nonnull final List> commandArguments, - @Nullable final CommandTree.Node> node) { + public final @NonNull String apply(@NonNull final List<@NonNull CommandArgument> commandArguments, + final CommandTree.@Nullable Node<@Nullable CommandArgument> node) { final StringBuilder stringBuilder = new StringBuilder(); final Iterator> iterator = commandArguments.iterator(); while (iterator.hasNext()) { diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/StaticArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/StaticArgument.java index 1109fbd9..55bf3aff 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/StaticArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/StaticArgument.java @@ -26,8 +26,8 @@ package cloud.commandframework.arguments; import cloud.commandframework.arguments.parser.ArgumentParseResult; import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.context.CommandContext; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -44,7 +44,7 @@ import java.util.TreeSet; */ public final class StaticArgument extends CommandArgument { - private StaticArgument(final boolean required, @Nonnull final String name, @Nonnull final String... aliases) { + private StaticArgument(final boolean required, @NonNull final String name, @NonNull final String... aliases) { super(required, name, new StaticArgumentParser<>(name, aliases), String.class); } @@ -56,9 +56,8 @@ public final class StaticArgument extends CommandArgument { * @param Command sender type * @return Constructed argument */ - @Nonnull - public static StaticArgument required(@Nonnull final String name, - @Nonnull final String... aliases) { + public static @NonNull StaticArgument required(@NonNull final String name, + @NonNull final String... aliases) { return new StaticArgument<>(true, name, aliases); } @@ -70,9 +69,8 @@ public final class StaticArgument extends CommandArgument { * @param Command sender type * @return Constructed argument */ - @Nonnull - public static StaticArgument optional(@Nonnull final String name, - @Nonnull final String... aliases) { + public static @NonNull StaticArgument optional(@NonNull final String name, + @NonNull final String... aliases) { return new StaticArgument<>(false, name, aliases); } @@ -81,7 +79,7 @@ public final class StaticArgument extends CommandArgument { * * @param alias New alias */ - public void registerAlias(@Nonnull final String alias) { + public void registerAlias(@NonNull final String alias) { ((StaticArgumentParser) this.getParser()).insertAlias(alias); } @@ -90,8 +88,7 @@ public final class StaticArgument extends CommandArgument { * * @return Immutable view of the argument aliases */ - @Nonnull - public Set getAliases() { + public @NonNull Set<@NonNull String> getAliases() { return Collections.unmodifiableSet(((StaticArgumentParser) this.getParser()).getAcceptedStrings()); } @@ -100,8 +97,7 @@ public final class StaticArgument extends CommandArgument { * * @return Immutable view of the optional argument aliases */ - @Nonnull - public List getAlternativeAliases() { + public @NonNull List<@NonNull String> getAlternativeAliases() { return Collections.unmodifiableList(new ArrayList<>(((StaticArgumentParser) this.getParser()).alternativeAliases)); } @@ -113,17 +109,16 @@ public final class StaticArgument extends CommandArgument { private final String name; - private StaticArgumentParser(@Nonnull final String name, @Nonnull final String... aliases) { + private StaticArgumentParser(@NonNull final String name, @NonNull final String... aliases) { this.name = name; this.allAcceptedAliases.add(this.name); this.allAcceptedAliases.addAll(Arrays.asList(aliases)); this.alternativeAliases.addAll(Arrays.asList(aliases)); } - @Nonnull @Override - public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public @NonNull ArgumentParseResult parse(@NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> inputQueue) { final String string = inputQueue.peek(); if (string == null) { return ArgumentParseResult.failure(new NullPointerException("No input provided")); @@ -135,9 +130,9 @@ public final class StaticArgument extends CommandArgument { return ArgumentParseResult.failure(new IllegalArgumentException(string)); } - @Nonnull @Override - public List suggestions(@Nonnull final CommandContext commandContext, @Nonnull final String input) { + public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext commandContext, + @NonNull final String input) { return Collections.singletonList(this.name); } @@ -146,8 +141,7 @@ public final class StaticArgument extends CommandArgument { * * @return Accepted strings */ - @Nonnull - public Set getAcceptedStrings() { + public @NonNull Set<@NonNull String> getAcceptedStrings() { return this.allAcceptedAliases; } @@ -156,7 +150,7 @@ public final class StaticArgument extends CommandArgument { * * @param alias New alias */ - public void insertAlias(@Nonnull final String alias) { + public void insertAlias(@NonNull final String alias) { this.allAcceptedAliases.add(alias); this.alternativeAliases.add(alias); } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParseResult.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParseResult.java index 9f88b966..cc3b3aec 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParseResult.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParseResult.java @@ -23,7 +23,8 @@ // package cloud.commandframework.arguments.parser; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.util.Optional; /** @@ -43,8 +44,7 @@ public abstract class ArgumentParseResult { * @param Parser return type * @return Failed parse result */ - @Nonnull - public static ArgumentParseResult failure(@Nonnull final Throwable failure) { + public static @NonNull ArgumentParseResult failure(@NonNull final Throwable failure) { return new ParseFailure<>(failure); } @@ -55,8 +55,7 @@ public abstract class ArgumentParseResult { * @param Parser return type * @return Succeeded parse result */ - @Nonnull - public static ArgumentParseResult success(@Nonnull final T value) { + public static @NonNull ArgumentParseResult success(@NonNull final T value) { return new ParseSuccess<>(value); } @@ -65,16 +64,14 @@ public abstract class ArgumentParseResult { * * @return Optional containing the parsed value */ - @Nonnull - public abstract Optional getParsedValue(); + public abstract @NonNull Optional getParsedValue(); /** * Get the failure reason, if it exists * * @return Optional containing the failure reason */ - @Nonnull - public abstract Optional getFailure(); + public abstract @NonNull Optional getFailure(); private static final class ParseSuccess extends ArgumentParseResult { @@ -84,19 +81,17 @@ public abstract class ArgumentParseResult { */ private final T value; - private ParseSuccess(@Nonnull final T value) { + private ParseSuccess(@NonNull final T value) { this.value = value; } - @Nonnull @Override - public Optional getParsedValue() { + public @NonNull Optional getParsedValue() { return Optional.of(this.value); } - @Nonnull @Override - public Optional getFailure() { + public @NonNull Optional getFailure() { return Optional.empty(); } @@ -110,19 +105,17 @@ public abstract class ArgumentParseResult { */ private final Throwable failure; - private ParseFailure(@Nonnull final Throwable failure) { + private ParseFailure(@NonNull final Throwable failure) { this.failure = failure; } - @Nonnull @Override - public Optional getParsedValue() { + public @NonNull Optional getParsedValue() { return Optional.empty(); } - @Nonnull @Override - public Optional getFailure() { + public @NonNull Optional getFailure() { return Optional.of(this.failure); } } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParser.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParser.java index 72be9f4b..f8b58bed 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParser.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ArgumentParser.java @@ -24,8 +24,8 @@ package cloud.commandframework.arguments.parser; import cloud.commandframework.context.CommandContext; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; import java.util.Queue; @@ -46,8 +46,8 @@ public interface ArgumentParser { * @param inputQueue The queue of arguments * @return Parsed command result */ - @Nonnull - ArgumentParseResult parse(@Nonnull CommandContext commandContext, @Nonnull Queue inputQueue); + @NonNull ArgumentParseResult<@NonNull T> parse(@NonNull CommandContext<@NonNull C> commandContext, + @NonNull Queue<@NonNull String> inputQueue); /** * Get a list of suggested arguments that would be correctly parsed by this parser @@ -56,8 +56,8 @@ public interface ArgumentParser { * @param input Input string * @return List of suggestions */ - @Nonnull - default List suggestions(@Nonnull final CommandContext commandContext, @Nonnull final String input) { + default @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext commandContext, + @NonNull final String input) { return Collections.emptyList(); } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameter.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameter.java index cd251638..8dd40d24 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameter.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameter.java @@ -24,8 +24,8 @@ package cloud.commandframework.arguments.parser; import io.leangen.geantyref.TypeToken; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Objects; /** @@ -44,7 +44,8 @@ public class ParserParameter { * @param key Parameter key * @param expectedType Type that is expected to be mapped to this parameter */ - public ParserParameter(@Nonnull final String key, @Nonnull final TypeToken expectedType) { + public ParserParameter(@NonNull final String key, + @NonNull final TypeToken expectedType) { this.key = key; this.expectedType = expectedType; } @@ -54,8 +55,7 @@ public class ParserParameter { * * @return Parameter key */ - @Nonnull - public String getKey() { + public @NonNull String getKey() { return this.key; } @@ -64,8 +64,7 @@ public class ParserParameter { * * @return Expected type */ - @Nonnull - public TypeToken getExpectedType() { + public @NonNull TypeToken getExpectedType() { return this.expectedType; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameters.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameters.java index 309a20c5..2e00d436 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameters.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserParameters.java @@ -23,7 +23,8 @@ // package cloud.commandframework.arguments.parser; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -40,8 +41,7 @@ public final class ParserParameters { * * @return Empty instance */ - @Nonnull - public static ParserParameters empty() { + public static @NonNull ParserParameters empty() { return new ParserParameters(); } @@ -53,8 +53,8 @@ public final class ParserParameters { * @param Value type * @return Constructed instance */ - @Nonnull - public static ParserParameters single(@Nonnull final ParserParameter parameter, @Nonnull final T value) { + public static @NonNull ParserParameters single(@NonNull final ParserParameter parameter, + @NonNull final T value) { final ParserParameters parameters = new ParserParameters(); parameters.store(parameter, value); return parameters; @@ -67,7 +67,7 @@ public final class ParserParameters { * @param Parameter type * @return {@code true} if such a pair is stored, else {@code false} */ - public boolean has(@Nonnull final ParserParameter parameter) { + public boolean has(@NonNull final ParserParameter parameter) { return this.internalMap.containsKey(parameter); } @@ -78,7 +78,8 @@ public final class ParserParameters { * @param value Object * @param Parameter type */ - public void store(@Nonnull final ParserParameter parameter, @Nonnull final T value) { + public void store(@NonNull final ParserParameter parameter, + @NonNull final T value) { this.internalMap.put(parameter, value); } @@ -90,9 +91,9 @@ public final class ParserParameters { * @param Parameter type * @return Parameter value */ - @Nonnull @SuppressWarnings("unchecked") - public T get(@Nonnull final ParserParameter parameter, @Nonnull final T defaultValue) { + public @NonNull T get(@NonNull final ParserParameter parameter, + @NonNull final T defaultValue) { return (T) this.internalMap.getOrDefault(parameter, defaultValue); } @@ -102,7 +103,7 @@ public final class ParserParameters { * * @param other Other instance */ - public void merge(@Nonnull final ParserParameters other) { + public void merge(@NonNull final ParserParameters other) { this.internalMap.putAll(other.internalMap); } @@ -111,8 +112,7 @@ public final class ParserParameters { * * @return Immutable map */ - @Nonnull - public Map, Object> getAll() { + public @NonNull Map<@NonNull ParserParameter, @NonNull Object> getAll() { return Collections.unmodifiableMap(this.internalMap); } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserRegistry.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserRegistry.java index dc350828..8354be34 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserRegistry.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/ParserRegistry.java @@ -24,8 +24,8 @@ package cloud.commandframework.arguments.parser; import io.leangen.geantyref.TypeToken; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.lang.annotation.Annotation; import java.util.Collection; import java.util.Optional; @@ -49,8 +49,8 @@ public interface ParserRegistry { * to configure the parser, many of which are documented in {@link StandardParameters} * @param Generic type specifying what is produced by the parser */ - void registerParserSupplier(@Nonnull TypeToken type, - @Nonnull Function> supplier); + void registerParserSupplier(@NonNull TypeToken type, + @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser> supplier); /** * Register a named parser supplier @@ -59,8 +59,8 @@ public interface ParserRegistry { * @param supplier The function that generates the parser. The map supplied my contain parameters used * to configure the parser, many of which are documented in {@link StandardParameters} */ - void registerNamedParserSupplier(@Nonnull String name, - @Nonnull Function> supplier); + void registerNamedParserSupplier(@NonNull String name, + @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser> supplier); /** * Register a mapper that maps annotation instances to a map of parameter-object pairs @@ -71,9 +71,9 @@ public interface ParserRegistry { * @param Annotation type * @param Type of the object that the parser is retrieved for */ - void registerAnnotationMapper(@Nonnull Class annotation, - @Nonnull BiFunction, - ParserParameters> mapper); + void registerAnnotationMapper(@NonNull Class annotation, + @NonNull BiFunction<@NonNull A, @NonNull TypeToken, + @NonNull ParserParameters> mapper); /** * Parse annotations into {@link ParserParameters} @@ -82,8 +82,8 @@ public interface ParserRegistry { * @param annotations The annotations to be parsed * @return Parsed parameters */ - @Nonnull - ParserParameters parseAnnotations(@Nonnull TypeToken parsingType, @Nonnull Collection annotations); + @NonNull ParserParameters parseAnnotations(@NonNull TypeToken parsingType, + @NonNull Collection annotations); /** * Attempt to create a {@link ArgumentParser} for a specified type, using @@ -94,9 +94,8 @@ public interface ParserRegistry { * @param Generic type * @return Parser, if one can be created */ - @Nonnull - Optional> createParser(@Nonnull TypeToken type, - @Nonnull ParserParameters parserParameters); + @NonNull Optional> createParser(@NonNull TypeToken type, + @NonNull ParserParameters parserParameters); /** * Attempt to create a {@link ArgumentParser} for a specified type, using @@ -107,8 +106,7 @@ public interface ParserRegistry { * @param Generic type * @return Parser, if one can be created */ - @Nonnull - Optional> createParser(@Nonnull String name, - @Nonnull ParserParameters parserParameters); + @NonNull Optional> createParser(@NonNull String name, + @NonNull ParserParameters parserParameters); } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParameters.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParameters.java index a91ae275..7af083a6 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParameters.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParameters.java @@ -24,8 +24,7 @@ package cloud.commandframework.arguments.parser; import io.leangen.geantyref.TypeToken; - -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * Common parser parameters used when resolving types in the {@link ParserRegistry} @@ -60,7 +59,8 @@ public final class StandardParameters { private StandardParameters() { } - private static ParserParameter create(@Nonnull final String key, @Nonnull final TypeToken expectedType) { + private static @NonNull ParserParameter create(@NonNull final String key, + @NonNull final TypeToken expectedType) { return new ParserParameter<>(key, expectedType); } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java index 4e1eebe7..5056fb4c 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java @@ -36,8 +36,8 @@ import cloud.commandframework.arguments.standard.ShortArgument; import cloud.commandframework.arguments.standard.StringArgument; import io.leangen.geantyref.GenericTypeReflector; import io.leangen.geantyref.TypeToken; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collection; @@ -56,14 +56,14 @@ public final class StandardParserRegistry implements ParserRegistry { private static final Map, Class> PRIMITIVE_MAPPINGS = new HashMap, Class>() { { - put(char.class, Character .class); - put(int.class, Integer .class); - put(short.class, Short .class); - put(byte.class, Byte .class); - put(float.class, Float .class); - put(double.class, Double .class); - put(long.class, Long .class); - put(boolean.class, Boolean .class); + put(char.class, Character.class); + put(int.class, Integer.class); + put(short.class, Short.class); + put(byte.class, Byte.class); + put(float.class, Float.class); + put(double.class, Double.class); + put(long.class, Long.class); + put(boolean.class, Boolean.class); } }; @@ -107,28 +107,29 @@ public final class StandardParserRegistry implements ParserRegistry { } @Override - public void registerParserSupplier(@Nonnull final TypeToken type, - @Nonnull final Function> supplier) { + public void registerParserSupplier(@NonNull final TypeToken type, + @NonNull final Function<@NonNull ParserParameters, + @NonNull ArgumentParser> supplier) { this.parserSuppliers.put(type, supplier); } @Override - public void registerNamedParserSupplier(@Nonnull final String name, - @Nonnull final Function> supplier) { + public void registerNamedParserSupplier(@NonNull final String name, + @NonNull final Function<@NonNull ParserParameters, + @NonNull ArgumentParser> supplier) { this.namedParsers.put(name, supplier); } @Override - public void registerAnnotationMapper(@Nonnull final Class annotation, - @Nonnull final BiFunction, - ParserParameters> mapper) { + public void registerAnnotationMapper(@NonNull final Class annotation, + @NonNull final BiFunction<@NonNull A, @NonNull TypeToken, + @NonNull ParserParameters> mapper) { this.annotationMappers.put(annotation, mapper); } - @Nonnull @Override - public ParserParameters parseAnnotations(@Nonnull final TypeToken parsingType, - @Nonnull final Collection annotations) { + public @NonNull ParserParameters parseAnnotations(@NonNull final TypeToken parsingType, + @NonNull final Collection<@NonNull ? extends Annotation> annotations) { final ParserParameters parserParameters = new ParserParameters(); annotations.forEach(annotation -> { // noinspection all @@ -143,10 +144,9 @@ public final class StandardParserRegistry implements ParserRegistry { return parserParameters; } - @Nonnull @Override - public Optional> createParser(@Nonnull final TypeToken type, - @Nonnull final ParserParameters parserParameters) { + public @NonNull Optional> createParser(@NonNull final TypeToken type, + @NonNull final ParserParameters parserParameters) { final TypeToken actualType; if (GenericTypeReflector.erase(type.getType()).isPrimitive()) { actualType = TypeToken.get(PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType()))); @@ -169,10 +169,9 @@ public final class StandardParserRegistry implements ParserRegistry { return Optional.of(parser); } - @Nonnull @Override - public Optional> createParser(@Nonnull final String name, - @Nonnull final ParserParameters parserParameters) { + public @NonNull Optional> createParser(@NonNull final String name, + @NonNull final ParserParameters parserParameters) { final Function> producer = this.namedParsers.get(name); if (producer == null) { return Optional.empty(); @@ -183,15 +182,16 @@ public final class StandardParserRegistry implements ParserRegistry { } - private static boolean isPrimitive(@Nonnull final TypeToken type) { + private static boolean isPrimitive(@NonNull final TypeToken type) { return GenericTypeReflector.erase(type.getType()).isPrimitive(); } - private static final class RangeMapper implements BiFunction, ParserParameters> { + private static final class RangeMapper implements BiFunction<@NonNull Range, @NonNull TypeToken, + @NonNull ParserParameters> { @Override - public ParserParameters apply(final Range range, final TypeToken type) { + public @NonNull ParserParameters apply(@NonNull final Range range, @NonNull final TypeToken type) { final Class clazz; if (isPrimitive(type)) { clazz = PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType())); @@ -259,10 +259,11 @@ public final class StandardParserRegistry implements ParserRegistry { } - private static final class CompletionsMapper implements BiFunction, ParserParameters> { + private static final class CompletionsMapper implements BiFunction<@NonNull Completions, @NonNull TypeToken, + @NonNull ParserParameters> { @Override - public ParserParameters apply(final Completions completions, final TypeToken token) { + public @NonNull ParserParameters apply(@NonNull final Completions completions, @NonNull final TypeToken token) { if (GenericTypeReflector.erase(token.getType()).equals(String.class)) { final String[] splitCompletions = completions.value().replace(" ", "").split(","); return ParserParameters.single(StandardParameters.COMPLETIONS, splitCompletions); diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ShortArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ShortArgument.java index 0ba73915..0ef0073f 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ShortArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ShortArgument.java @@ -28,9 +28,9 @@ import cloud.commandframework.arguments.parser.ArgumentParseResult; import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.context.CommandContext; import cloud.commandframework.exceptions.parsing.NumberParseException; +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.Queue; import java.util.function.BiFunction; @@ -42,11 +42,12 @@ public final class ShortArgument extends CommandArgument { private final short max; private ShortArgument(final boolean required, - @Nonnull final String name, + @NonNull final String name, final short min, final short max, final String defaultValue, - @Nullable final BiFunction, String, List> suggestionsProvider) { + @Nullable final BiFunction<@NonNull CommandContext, @NonNull String, + @NonNull List> suggestionsProvider) { super(required, name, new ShortParser<>(min, max), defaultValue, Short.class, suggestionsProvider); this.min = min; this.max = max; @@ -59,8 +60,7 @@ public final class ShortArgument extends CommandArgument { * @param Command sender type * @return Created builder */ - @Nonnull - public static ShortArgument.Builder newBuilder(@Nonnull final String name) { + public static ShortArgument.@NonNull Builder newBuilder(@NonNull final String name) { return new Builder<>(name); } @@ -71,8 +71,7 @@ public final class ShortArgument extends CommandArgument { * @param Command sender type * @return Created argument */ - @Nonnull - public static CommandArgument required(@Nonnull final String name) { + public static @NonNull CommandArgument required(@NonNull final String name) { return ShortArgument.newBuilder(name).asRequired().build(); } @@ -83,8 +82,7 @@ public final class ShortArgument extends CommandArgument { * @param Command sender type * @return Created argument */ - @Nonnull - public static CommandArgument optional(@Nonnull final String name) { + public static @NonNull CommandArgument optional(@NonNull final String name) { return ShortArgument.newBuilder(name).asOptional().build(); } @@ -96,9 +94,8 @@ public final class ShortArgument extends CommandArgument { * @param Command sender type * @return Created argument */ - @Nonnull - public static CommandArgument optional(@Nonnull final String name, - final short defaultNum) { + public static @NonNull CommandArgument optional(@NonNull final String name, + final short defaultNum) { return ShortArgument.newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build(); } @@ -125,7 +122,7 @@ public final class ShortArgument extends CommandArgument { private short min = Short.MIN_VALUE; private short max = Short.MAX_VALUE; - protected Builder(@Nonnull final String name) { + protected Builder(@NonNull final String name) { super(Short.class, name); } @@ -135,8 +132,7 @@ public final class ShortArgument extends CommandArgument { * @param min Minimum value * @return Builder instance */ - @Nonnull - public Builder withMin(final short min) { + public @NonNull Builder withMin(final short min) { this.min = min; return this; } @@ -147,8 +143,7 @@ public final class ShortArgument extends CommandArgument { * @param max Maximum value * @return Builder instance */ - @Nonnull - public Builder withMax(final short max) { + public @NonNull Builder withMax(final short max) { this.max = max; return this; } @@ -158,9 +153,8 @@ public final class ShortArgument extends CommandArgument { * * @return Constructed argument */ - @Nonnull @Override - public ShortArgument build() { + public @NonNull ShortArgument build() { return new ShortArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue(), this.getSuggestionsProvider()); } @@ -183,11 +177,10 @@ public final class ShortArgument extends CommandArgument { this.max = max; } - @Nonnull @Override - public ArgumentParseResult parse( - @Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public @NonNull ArgumentParseResult parse( + @NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> inputQueue) { final String input = inputQueue.peek(); if (input == null) { return ArgumentParseResult.failure(new NullPointerException("No input was provided")); @@ -209,10 +202,9 @@ public final class ShortArgument extends CommandArgument { return true; } - @Nonnull @Override - public List suggestions(@Nonnull final CommandContext commandContext, - @Nonnull final String input) { + public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext commandContext, + @NonNull final String input) { return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input); } @@ -246,7 +238,7 @@ public final class ShortArgument extends CommandArgument { * @param min Minimum value * @param max Maximum value */ - public ShortParseException(@Nonnull final String input, final short min, final short max) { + public ShortParseException(@NonNull final String input, final short min, final short max) { super(input, min, max); } @@ -261,8 +253,7 @@ public final class ShortArgument extends CommandArgument { } @Override - @Nonnull - public String getNumberType() { + public @NonNull String getNumberType() { return "short"; } diff --git a/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java b/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java index a29daa7b..1fb478ed 100644 --- a/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java +++ b/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java @@ -24,8 +24,8 @@ package cloud.commandframework.context; import cloud.commandframework.arguments.CommandArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -48,7 +48,7 @@ public final class CommandContext { * * @param commandSender Sender of the command */ - public CommandContext(@Nonnull final C commandSender) { + public CommandContext(@NonNull final C commandSender) { this(false, commandSender); } @@ -58,7 +58,8 @@ public final class CommandContext { * @param suggestions Whether or not the context is created for command suggestions * @param commandSender Sender of the command */ - public CommandContext(final boolean suggestions, @Nonnull final C commandSender) { + public CommandContext(final boolean suggestions, + @NonNull final C commandSender) { this.commandSender = commandSender; this.suggestions = suggestions; } @@ -68,8 +69,7 @@ public final class CommandContext { * * @return Command sender */ - @Nonnull - public C getSender() { + public @NonNull C getSender() { return this.commandSender; } @@ -89,7 +89,7 @@ public final class CommandContext { * @param value Value * @param Value type */ - public void store(@Nonnull final String key, @Nonnull final T value) { + public void store(@NonNull final String key, @NonNull final T value) { this.internalStorage.put(key, value); } @@ -100,8 +100,7 @@ public final class CommandContext { * @param Value type * @return Value */ - @Nonnull - public Optional get(@Nonnull final String key) { + public @NonNull Optional get(@NonNull final String key) { final Object value = this.internalStorage.get(key); if (value != null) { @SuppressWarnings("ALL") final T castedValue = (T) value; @@ -119,9 +118,8 @@ public final class CommandContext { * @return Argument * @throws NullPointerException If no such argument is stored */ - @Nonnull @SuppressWarnings("unchecked") - public T getRequired(@Nonnull final String key) { + public @NonNull T getRequired(@NonNull final String key) { final Object value = this.internalStorage.get(key); if (value == null) { throw new NullPointerException("No such object stored in the context: " + key); @@ -137,8 +135,8 @@ public final class CommandContext { * @param Argument type * @return Argument, or supplied default value */ - @Nonnull - public T getOrDefault(@Nonnull final String key, @Nonnull final T defaultValue) { + public @NonNull T getOrDefault(@NonNull final String key, + @NonNull final T defaultValue) { return this.get(key).orElse(defaultValue); } @@ -148,8 +146,7 @@ public final class CommandContext { * @param argument Argument * @return Created timing instance */ - @Nonnull - public ArgumentTiming createTiming(@Nonnull final CommandArgument argument) { + public @NonNull ArgumentTiming createTiming(@NonNull final CommandArgument argument) { final ArgumentTiming argumentTiming = new ArgumentTiming(); this.argumentTimings.put(argument, argumentTiming); return argumentTiming; @@ -160,8 +157,7 @@ public final class CommandContext { * * @return Argument timings */ - @Nonnull - public Map, ArgumentTiming> getArgumentTimings() { + public @NonNull Map, ArgumentTiming> getArgumentTimings() { return Collections.unmodifiableMap(this.argumentTimings); } diff --git a/cloud-core/src/main/java/cloud/commandframework/context/CommandContextFactory.java b/cloud-core/src/main/java/cloud/commandframework/context/CommandContextFactory.java index 9fd70cc0..c51b8bae 100644 --- a/cloud-core/src/main/java/cloud/commandframework/context/CommandContextFactory.java +++ b/cloud-core/src/main/java/cloud/commandframework/context/CommandContextFactory.java @@ -23,7 +23,7 @@ // package cloud.commandframework.context; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * Factory for {@link CommandContext} instances @@ -39,7 +39,6 @@ public interface CommandContextFactory { * @param sender Command sender * @return Command context */ - @Nonnull - CommandContext create(boolean suggestions, @Nonnull C sender); + @NonNull CommandContext create(boolean suggestions, @NonNull C sender); } diff --git a/cloud-core/src/main/java/cloud/commandframework/context/StandardCommandContextFactory.java b/cloud-core/src/main/java/cloud/commandframework/context/StandardCommandContextFactory.java index f13e1214..b4750aba 100644 --- a/cloud-core/src/main/java/cloud/commandframework/context/StandardCommandContextFactory.java +++ b/cloud-core/src/main/java/cloud/commandframework/context/StandardCommandContextFactory.java @@ -23,7 +23,7 @@ // package cloud.commandframework.context; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; public final class StandardCommandContextFactory implements CommandContextFactory { @@ -34,9 +34,8 @@ public final class StandardCommandContextFactory implements CommandContextFac * @param sender Command sender * @return Created context */ - @Nonnull @Override - public CommandContext create(final boolean suggestions, @Nonnull final C sender) { + public CommandContext create(final boolean suggestions, @NonNull final C sender) { return new CommandContext<>(suggestions, sender); } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/AmbiguousNodeException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/AmbiguousNodeException.java index 2085ecd8..eb2150bb 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/AmbiguousNodeException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/AmbiguousNodeException.java @@ -26,9 +26,9 @@ package cloud.commandframework.exceptions; import cloud.commandframework.CommandTree; import cloud.commandframework.arguments.CommandArgument; import cloud.commandframework.context.CommandContext; +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.Iterator; import java.util.List; @@ -52,8 +52,8 @@ public final class AmbiguousNodeException extends IllegalStateException { * @param children All children of the parent */ public AmbiguousNodeException(@Nullable final CommandArgument parentNode, - @Nonnull final CommandArgument ambiguousNode, - @Nonnull final List> children) { + @NonNull final CommandArgument ambiguousNode, + @NonNull final List<@NonNull CommandArgument> children) { this.parentNode = parentNode; this.ambiguousNode = ambiguousNode; this.children = children; @@ -64,8 +64,7 @@ public final class AmbiguousNodeException extends IllegalStateException { * * @return Parent node */ - @Nullable - public CommandArgument getParentNode() { + public @Nullable CommandArgument getParentNode() { return this.parentNode; } @@ -74,8 +73,7 @@ public final class AmbiguousNodeException extends IllegalStateException { * * @return Ambiguous node */ - @Nonnull - public CommandArgument getAmbiguousNode() { + public @NonNull CommandArgument getAmbiguousNode() { return this.ambiguousNode; } @@ -84,8 +82,7 @@ public final class AmbiguousNodeException extends IllegalStateException { * * @return Child nodes */ - @Nonnull - public List> getChildren() { + public @NonNull List<@NonNull CommandArgument> getChildren() { return this.children; } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/ArgumentParseException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/ArgumentParseException.java index 9dc410e7..9d932168 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/ArgumentParseException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/ArgumentParseException.java @@ -24,8 +24,8 @@ package cloud.commandframework.exceptions; import cloud.commandframework.arguments.CommandArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.List; public class ArgumentParseException extends CommandParseException { @@ -39,9 +39,9 @@ public class ArgumentParseException extends CommandParseException { * @param commandSender Command sender * @param currentChain Chain leading up to the exception */ - public ArgumentParseException(@Nonnull final Throwable throwable, - @Nonnull final Object commandSender, - @Nonnull final List> currentChain) { + public ArgumentParseException(@NonNull final Throwable throwable, + @NonNull final Object commandSender, + @NonNull final List<@NonNull CommandArgument> currentChain) { super(commandSender, currentChain); this.cause = throwable; } @@ -51,8 +51,7 @@ public class ArgumentParseException extends CommandParseException { * * @return Cause */ - @Nonnull - public Throwable getCause() { + public @NonNull Throwable getCause() { return this.cause; } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/CommandParseException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/CommandParseException.java index bd1db92a..8c4e3b1b 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/CommandParseException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/CommandParseException.java @@ -24,8 +24,8 @@ package cloud.commandframework.exceptions; import cloud.commandframework.arguments.CommandArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; @@ -44,8 +44,8 @@ public class CommandParseException extends IllegalArgumentException { * @param commandSender Sender who executed the command * @param currentChain Chain leading up to the exception */ - protected CommandParseException(@Nonnull final Object commandSender, - @Nonnull final List> currentChain) { + protected CommandParseException(@NonNull final Object commandSender, + @NonNull final List> currentChain) { this.commandSender = commandSender; this.currentChain = currentChain; } @@ -55,8 +55,7 @@ public class CommandParseException extends IllegalArgumentException { * * @return Command sender */ - @Nonnull - public Object getCommandSender() { + public @NonNull Object getCommandSender() { return this.commandSender; } @@ -65,8 +64,7 @@ public class CommandParseException extends IllegalArgumentException { * * @return Unmodifiable list of command arguments */ - @Nonnull - public List> getCurrentChain() { + public @NonNull List<@NonNull CommandArgument> getCurrentChain() { return Collections.unmodifiableList(this.currentChain); } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidCommandSenderException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidCommandSenderException.java index 6102c8e8..29db24a4 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidCommandSenderException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidCommandSenderException.java @@ -24,8 +24,8 @@ package cloud.commandframework.exceptions; import cloud.commandframework.arguments.CommandArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.List; /** @@ -42,9 +42,9 @@ public final class InvalidCommandSenderException extends CommandParseException { * @param requiredSender The sender type that is required * @param currentChain Chain leading up to the exception */ - public InvalidCommandSenderException(@Nonnull final Object commandSender, - @Nonnull final Class requiredSender, - @Nonnull final List> currentChain) { + public InvalidCommandSenderException(@NonNull final Object commandSender, + @NonNull final Class requiredSender, + @NonNull final List<@NonNull CommandArgument> currentChain) { super(commandSender, currentChain); this.requiredSender = requiredSender; } @@ -54,8 +54,7 @@ public final class InvalidCommandSenderException extends CommandParseException { * * @return Required sender type */ - @Nonnull - public Class getRequiredSender() { + public @NonNull Class getRequiredSender() { return this.requiredSender; } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidSyntaxException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidSyntaxException.java index d2f96681..a546e58e 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidSyntaxException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/InvalidSyntaxException.java @@ -24,8 +24,8 @@ package cloud.commandframework.exceptions; import cloud.commandframework.arguments.CommandArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.List; /** @@ -43,9 +43,9 @@ public class InvalidSyntaxException extends CommandParseException { * @param commandSender Sender that sent the command * @param currentChain Chain leading up to issue */ - public InvalidSyntaxException(@Nonnull final String correctSyntax, - @Nonnull final Object commandSender, - @Nonnull final List> currentChain) { + public InvalidSyntaxException(@NonNull final String correctSyntax, + @NonNull final Object commandSender, + @NonNull final List<@NonNull CommandArgument> currentChain) { super(commandSender, currentChain); this.correctSyntax = correctSyntax; } @@ -55,8 +55,7 @@ public class InvalidSyntaxException extends CommandParseException { * * @return Correct command syntax */ - @Nonnull - public String getCorrectSyntax() { + public @NonNull String getCorrectSyntax() { return this.correctSyntax; } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/NoCommandInLeafException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/NoCommandInLeafException.java index 7850488f..2be95ae1 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/NoCommandInLeafException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/NoCommandInLeafException.java @@ -25,8 +25,7 @@ package cloud.commandframework.exceptions; import cloud.commandframework.Command; import cloud.commandframework.arguments.CommandArgument; - -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * Thrown when a {@link CommandArgument} @@ -42,7 +41,7 @@ public final class NoCommandInLeafException extends IllegalStateException { * * @param commandArgument Command argument that caused the exception */ - public NoCommandInLeafException(@Nonnull final CommandArgument commandArgument) { + public NoCommandInLeafException(@NonNull final CommandArgument commandArgument) { super(String.format("Leaf node '%s' does not have associated owning command", commandArgument.getName())); this.commandArgument = commandArgument; } @@ -52,8 +51,7 @@ public final class NoCommandInLeafException extends IllegalStateException { * * @return Command argument */ - @Nonnull - public CommandArgument getCommandArgument() { + public @NonNull CommandArgument getCommandArgument() { return this.commandArgument; } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/NoPermissionException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/NoPermissionException.java index eaad39f0..0baafb1b 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/NoPermissionException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/NoPermissionException.java @@ -26,8 +26,8 @@ package cloud.commandframework.exceptions; import cloud.commandframework.Command; import cloud.commandframework.arguments.CommandArgument; import cloud.commandframework.permission.CommandPermission; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.List; /** @@ -46,9 +46,9 @@ public class NoPermissionException extends CommandParseException { * @param commandSender Command sender * @param currentChain Chain leading up to the exception */ - public NoPermissionException(@Nonnull final CommandPermission missingPermission, - @Nonnull final Object commandSender, - @Nonnull final List> currentChain) { + public NoPermissionException(@NonNull final CommandPermission missingPermission, + @NonNull final Object commandSender, + @NonNull final List<@NonNull CommandArgument> currentChain) { super(commandSender, currentChain); this.missingPermission = missingPermission; } @@ -63,8 +63,7 @@ public class NoPermissionException extends CommandParseException { * * @return Get the missing permission node */ - @Nonnull - public String getMissingPermission() { + public @NonNull String getMissingPermission() { return this.missingPermission.toString(); } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/NoSuchCommandException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/NoSuchCommandException.java index 53fba52c..ffd31303 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/NoSuchCommandException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/NoSuchCommandException.java @@ -24,8 +24,8 @@ package cloud.commandframework.exceptions; import cloud.commandframework.arguments.CommandArgument; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.List; /** @@ -44,9 +44,9 @@ public final class NoSuchCommandException extends CommandParseException { * @param currentChain Chain leading up to the exception * @param command Entered command (following the command chain) */ - public NoSuchCommandException(@Nonnull final Object commandSender, - @Nonnull final List> currentChain, - @Nonnull final String command) { + public NoSuchCommandException(@NonNull final Object commandSender, + @NonNull final List> currentChain, + @NonNull final String command) { super(commandSender, currentChain); this.suppliedCommand = command; } @@ -69,8 +69,7 @@ public final class NoSuchCommandException extends CommandParseException { * * @return Supplied command */ - @Nonnull - public String getSuppliedCommand() { + public @NonNull String getSuppliedCommand() { return this.suppliedCommand; } diff --git a/cloud-core/src/main/java/cloud/commandframework/exceptions/parsing/NumberParseException.java b/cloud-core/src/main/java/cloud/commandframework/exceptions/parsing/NumberParseException.java index d29dd326..4146b584 100644 --- a/cloud-core/src/main/java/cloud/commandframework/exceptions/parsing/NumberParseException.java +++ b/cloud-core/src/main/java/cloud/commandframework/exceptions/parsing/NumberParseException.java @@ -23,7 +23,7 @@ // package cloud.commandframework.exceptions.parsing; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; public abstract class NumberParseException extends IllegalArgumentException { @@ -38,7 +38,9 @@ public abstract class NumberParseException extends IllegalArgumentException { * @param min Maximum value * @param max Minimum value */ - public NumberParseException(@Nonnull final String input, @Nonnull final Number min, @Nonnull final Number max) { + public NumberParseException(@NonNull final String input, + @NonNull final Number min, + @NonNull final Number max) { this.input = input; this.min = min; this.max = max; @@ -63,8 +65,7 @@ public abstract class NumberParseException extends IllegalArgumentException { * * @return Number type */ - @Nonnull - public abstract String getNumberType(); + public abstract @NonNull String getNumberType(); /** * If the parser had a maximum value @@ -85,8 +86,7 @@ public abstract class NumberParseException extends IllegalArgumentException { * * @return Input */ - @Nonnull - public String getInput() { + public @NonNull String getInput() { return this.input; } diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/AsynchronousCommandExecutionCoordinator.java b/cloud-core/src/main/java/cloud/commandframework/execution/AsynchronousCommandExecutionCoordinator.java index 83ac985c..2480bebe 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/AsynchronousCommandExecutionCoordinator.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/AsynchronousCommandExecutionCoordinator.java @@ -28,9 +28,9 @@ import cloud.commandframework.CommandManager; import cloud.commandframework.CommandTree; import cloud.commandframework.context.CommandContext; import cloud.commandframework.services.State; +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.Optional; import java.util.Queue; import java.util.concurrent.CompletableFuture; @@ -52,7 +52,7 @@ public final class AsynchronousCommandExecutionCoordinator extends CommandExe private AsynchronousCommandExecutionCoordinator(@Nullable final Executor executor, final boolean synchronizeParsing, - @Nonnull final CommandTree commandTree) { + @NonNull final CommandTree commandTree) { super(commandTree); this.executor = executor; this.synchronizeParsing = synchronizeParsing; @@ -65,14 +65,13 @@ public final class AsynchronousCommandExecutionCoordinator extends CommandExe * @param Command sender type * @return Builder */ - @Nonnull - public static Builder newBuilder() { + public static @NonNull Builder newBuilder() { return new Builder<>(); } @Override - public CompletableFuture> coordinateExecution(@Nonnull final CommandContext commandContext, - @Nonnull final Queue input) { + public @NonNull CompletableFuture> coordinateExecution(@NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> input) { final Consumer> commandConsumer = command -> { if (this.commandManager.postprocessContext(commandContext, command) == State.ACCEPTED) { @@ -119,8 +118,7 @@ public final class AsynchronousCommandExecutionCoordinator extends CommandExe * * @return Builder instance */ - @Nonnull - public Builder withSynchronousParsing() { + public @NonNull Builder withSynchronousParsing() { this.synchronizeParsing = true; return this; } @@ -130,8 +128,7 @@ public final class AsynchronousCommandExecutionCoordinator extends CommandExe * * @return Builder instance */ - @Nonnull - public Builder withAsynchronousParsing() { + public @NonNull Builder withAsynchronousParsing() { this.synchronizeParsing = false; return this; } @@ -143,8 +140,7 @@ public final class AsynchronousCommandExecutionCoordinator extends CommandExe * @param executor Executor to use * @return Builder instance */ - @Nonnull - public Builder withExecutor(@Nonnull final Executor executor) { + public @NonNull Builder withExecutor(@NonNull final Executor executor) { this.executor = executor; return this; } @@ -155,8 +151,7 @@ public final class AsynchronousCommandExecutionCoordinator extends CommandExe * * @return Function that builds the coordinator */ - @Nonnull - public Function, CommandExecutionCoordinator> build() { + public @NonNull Function<@NonNull CommandTree, @NonNull CommandExecutionCoordinator> build() { return tree -> new AsynchronousCommandExecutionCoordinator<>(this.executor, this.synchronizeParsing, tree); } diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionCoordinator.java b/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionCoordinator.java index a8d90ddd..1b8abdb0 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionCoordinator.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionCoordinator.java @@ -26,8 +26,8 @@ package cloud.commandframework.execution; import cloud.commandframework.CommandTree; import cloud.commandframework.context.CommandContext; import cloud.commandframework.services.State; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Queue; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -49,7 +49,7 @@ public abstract class CommandExecutionCoordinator { * * @param commandTree Command tree */ - public CommandExecutionCoordinator(@Nonnull final CommandTree commandTree) { + public CommandExecutionCoordinator(@NonNull final CommandTree commandTree) { this.commandTree = commandTree; } @@ -59,8 +59,8 @@ public abstract class CommandExecutionCoordinator { * @param Command sender type * @return New coordinator instance */ - public static Function, - CommandExecutionCoordinator> simpleCoordinator() { + public static @NonNull Function<@NonNull CommandTree, + @NonNull CommandExecutionCoordinator> simpleCoordinator() { return SimpleCoordinator::new; } @@ -71,16 +71,15 @@ public abstract class CommandExecutionCoordinator { * @param input Command input * @return Future that completes with the result */ - public abstract CompletableFuture> coordinateExecution(@Nonnull CommandContext commandContext, - @Nonnull Queue input); + public abstract @NonNull CompletableFuture> coordinateExecution(@NonNull CommandContext commandContext, + @NonNull Queue<@NonNull String> input); /** * Get the command tree * * @return Command tree */ - @Nonnull - protected CommandTree getCommandTree() { + protected @NonNull CommandTree getCommandTree() { return this.commandTree; } @@ -93,13 +92,13 @@ public abstract class CommandExecutionCoordinator { public static final class SimpleCoordinator extends CommandExecutionCoordinator { - private SimpleCoordinator(@Nonnull final CommandTree commandTree) { + private SimpleCoordinator(@NonNull final CommandTree commandTree) { super(commandTree); } @Override - public CompletableFuture> coordinateExecution(@Nonnull final CommandContext commandContext, - @Nonnull final Queue input) { + public CompletableFuture> coordinateExecution(@NonNull final CommandContext commandContext, + @NonNull final Queue<@NonNull String> input) { final CompletableFuture> completableFuture = new CompletableFuture<>(); try { this.getCommandTree().parse(commandContext, input).ifPresent(command -> { diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionHandler.java b/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionHandler.java index 94e78a02..b97bfc9b 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionHandler.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/CommandExecutionHandler.java @@ -25,8 +25,7 @@ package cloud.commandframework.execution; import cloud.commandframework.Command; import cloud.commandframework.context.CommandContext; - -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * Handler that is invoked whenever a {@link Command} is executed @@ -42,7 +41,7 @@ public interface CommandExecutionHandler { * * @param commandContext Command context */ - void execute(@Nonnull CommandContext commandContext); + void execute(@NonNull CommandContext commandContext); /** @@ -53,7 +52,7 @@ public interface CommandExecutionHandler { class NullCommandExecutionHandler implements CommandExecutionHandler { @Override - public void execute(@Nonnull final CommandContext commandContext) { + public void execute(@NonNull final CommandContext commandContext) { } } diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/CommandResult.java b/cloud-core/src/main/java/cloud/commandframework/execution/CommandResult.java index b0911dba..045ff65a 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/CommandResult.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/CommandResult.java @@ -24,8 +24,7 @@ package cloud.commandframework.execution; import cloud.commandframework.context.CommandContext; - -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * The result of a command execution @@ -41,7 +40,7 @@ public class CommandResult { * * @param context Command context */ - public CommandResult(@Nonnull final CommandContext context) { + public CommandResult(@NonNull final CommandContext context) { this.commandContext = context; } @@ -50,8 +49,7 @@ public class CommandResult { * * @return Command context */ - @Nonnull - public CommandContext getCommandContext() { + public @NonNull CommandContext getCommandContext() { return this.commandContext; } diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/CommandSuggestionProcessor.java b/cloud-core/src/main/java/cloud/commandframework/execution/CommandSuggestionProcessor.java index c613ab72..cbfab95e 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/CommandSuggestionProcessor.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/CommandSuggestionProcessor.java @@ -24,6 +24,7 @@ package cloud.commandframework.execution; import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; +import org.checkerframework.checker.nullness.qual.NonNull; import java.util.List; import java.util.function.BiFunction; @@ -34,6 +35,6 @@ import java.util.function.BiFunction; * @param Command sender type */ public interface CommandSuggestionProcessor extends - BiFunction, List, List> { + BiFunction<@NonNull CommandPreprocessingContext, @NonNull List, @NonNull List> { } diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/FilteringCommandSuggestionProcessor.java b/cloud-core/src/main/java/cloud/commandframework/execution/FilteringCommandSuggestionProcessor.java index 8eedcba0..49ec8451 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/FilteringCommandSuggestionProcessor.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/FilteringCommandSuggestionProcessor.java @@ -24,8 +24,8 @@ package cloud.commandframework.execution; import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.LinkedList; import java.util.List; @@ -36,9 +36,9 @@ import java.util.List; */ public final class FilteringCommandSuggestionProcessor implements CommandSuggestionProcessor { - @Nonnull @Override - public List apply(@Nonnull final CommandPreprocessingContext context, @Nonnull final List strings) { + public @NonNull List<@NonNull String> apply(@NonNull final CommandPreprocessingContext context, + @NonNull final List<@NonNull String> strings) { final String input; if (context.getInputQueue().isEmpty()) { input = ""; diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/AcceptingCommandPreprocessor.java b/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/AcceptingCommandPreprocessor.java index 1c395823..662b25bd 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/AcceptingCommandPreprocessor.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/AcceptingCommandPreprocessor.java @@ -23,7 +23,7 @@ // package cloud.commandframework.execution.preprocessor; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; /** * {@link CommandPreprocessor} that does nothing besides indicating that the context @@ -39,7 +39,7 @@ public final class AcceptingCommandPreprocessor implements CommandPreprocesso public static final String PROCESSED_INDICATOR_KEY = "__COMMAND_PRE_PROCESSED__"; @Override - public void accept(@Nonnull final CommandPreprocessingContext context) { + public void accept(@NonNull final CommandPreprocessingContext context) { context.getCommandContext().store(PROCESSED_INDICATOR_KEY, "true"); } diff --git a/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/CommandPreprocessingContext.java b/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/CommandPreprocessingContext.java index 0de78db7..c1ed507b 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/CommandPreprocessingContext.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/preprocessor/CommandPreprocessingContext.java @@ -24,8 +24,8 @@ package cloud.commandframework.execution.preprocessor; import cloud.commandframework.context.CommandContext; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.LinkedList; import java.util.Objects; @@ -45,8 +45,8 @@ public final class CommandPreprocessingContext { * @param commandContext Command context * @param inputQueue Command input as supplied by sender */ - public CommandPreprocessingContext(@Nonnull final CommandContext commandContext, - @Nonnull final LinkedList inputQueue) { + public CommandPreprocessingContext(@NonNull final CommandContext commandContext, + @NonNull final LinkedList<@NonNull String> inputQueue) { this.commandContext = commandContext; this.inputQueue = inputQueue; } @@ -56,8 +56,7 @@ public final class CommandPreprocessingContext { * * @return Command context */ - @Nonnull - public CommandContext getCommandContext() { + public @NonNull CommandContext getCommandContext() { return this.commandContext; } @@ -67,8 +66,7 @@ public final class CommandPreprocessingContext { * * @return Input queue */ - @Nonnull - public LinkedList getInputQueue() { + public @NonNull LinkedList<@NonNull String> getInputQueue() { return this.inputQueue; } diff --git a/cloud-core/src/main/java/cloud/commandframework/extra/confirmation/CommandConfirmationManager.java b/cloud-core/src/main/java/cloud/commandframework/extra/confirmation/CommandConfirmationManager.java index ecf1bc26..422a81c7 100644 --- a/cloud-core/src/main/java/cloud/commandframework/extra/confirmation/CommandConfirmationManager.java +++ b/cloud-core/src/main/java/cloud/commandframework/extra/confirmation/CommandConfirmationManager.java @@ -30,8 +30,8 @@ import cloud.commandframework.execution.postprocessor.CommandPostprocessor; import cloud.commandframework.meta.SimpleCommandMeta; import cloud.commandframework.services.types.ConsumerService; import cloud.commandframework.types.tuples.Pair; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; @@ -73,9 +73,9 @@ public class CommandConfirmationManager { * @param errorNotifier Notifier that gets called when someone tries to confirm a command with nothing in the queue */ public CommandConfirmationManager(final long timeout, - @Nonnull final TimeUnit timeoutTimeUnit, - @Nonnull final Consumer> notifier, - @Nonnull final Consumer errorNotifier) { + @NonNull final TimeUnit timeoutTimeUnit, + @NonNull final Consumer<@NonNull CommandPostprocessingContext> notifier, + @NonNull final Consumer<@NonNull C> errorNotifier) { this.notifier = notifier; this.errorNotifier = errorNotifier; this.pendingCommands = new LinkedHashMap, Long>>() { @@ -87,11 +87,11 @@ public class CommandConfirmationManager { this.timeoutMillis = timeoutTimeUnit.toMillis(timeout); } - private void notifyConsumer(@Nonnull final CommandPostprocessingContext context) { + private void notifyConsumer(@NonNull final CommandPostprocessingContext context) { this.notifier.accept(context); } - private void addPending(@Nonnull final CommandPostprocessingContext context) { + private void addPending(@NonNull final CommandPostprocessingContext context) { this.pendingCommands.put(context.getCommandContext().getSender(), Pair.of(context, System.currentTimeMillis())); } @@ -101,8 +101,7 @@ public class CommandConfirmationManager { * @param sender Sender * @return Optional containing the post processing context if one has been stored, else {@link Optional#empty()} */ - @Nonnull - public Optional> getPending(@Nonnull final C sender) { + public @NonNull Optional> getPending(@NonNull final C sender) { final Pair, Long> pair = this.pendingCommands.remove(sender); if (pair != null) { if (System.currentTimeMillis() < pair.getSecond() + this.timeoutMillis) { @@ -118,8 +117,7 @@ public class CommandConfirmationManager { * @param builder Command meta builder * @return Builder instance */ - @Nonnull - public SimpleCommandMeta.Builder decorate(@Nonnull final SimpleCommandMeta.Builder builder) { + public SimpleCommandMeta.@NonNull Builder decorate(final SimpleCommandMeta.@NonNull Builder builder) { return builder.with(CONFIRMATION_REQUIRED_META, "true"); } @@ -128,7 +126,7 @@ public class CommandConfirmationManager { * * @param manager Command manager */ - public void registerConfirmationProcessor(@Nonnull final CommandManager manager) { + public void registerConfirmationProcessor(@NonNull final CommandManager manager) { manager.registerCommandPostProcessor(new CommandConfirmationPostProcessor()); } @@ -137,8 +135,7 @@ public class CommandConfirmationManager { * * @return Handler for a confirmation command */ - @Nonnull - public CommandExecutionHandler createConfirmationExecutionHandler() { + public @NonNull CommandExecutionHandler createConfirmationExecutionHandler() { return context -> { final Optional> pending = this.getPending(context.getSender()); if (pending.isPresent()) { @@ -156,7 +153,7 @@ public class CommandConfirmationManager { private final class CommandConfirmationPostProcessor implements CommandPostprocessor { @Override - public void accept(@Nonnull final CommandPostprocessingContext context) { + public void accept(@NonNull final CommandPostprocessingContext context) { if (!context.getCommand() .getCommandMeta() .getOrDefault(CONFIRMATION_REQUIRED_META, "false") diff --git a/cloud-core/src/main/java/cloud/commandframework/meta/CommandMeta.java b/cloud-core/src/main/java/cloud/commandframework/meta/CommandMeta.java index 68a9ab9a..5c6de6c7 100644 --- a/cloud-core/src/main/java/cloud/commandframework/meta/CommandMeta.java +++ b/cloud-core/src/main/java/cloud/commandframework/meta/CommandMeta.java @@ -24,8 +24,8 @@ package cloud.commandframework.meta; import cloud.commandframework.Command; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Map; import java.util.Optional; @@ -42,14 +42,12 @@ public abstract class CommandMeta { * * @return Builder instance */ - @Nonnull - public static SimpleCommandMeta.Builder simple() { + public static SimpleCommandMeta.@NonNull Builder simple() { return SimpleCommandMeta.builder(); } - @Nonnull @Override - public final String toString() { + public final @NonNull String toString() { return ""; } @@ -59,8 +57,7 @@ public abstract class CommandMeta { * @param key Key * @return Optional that may contain the associated value */ - @Nonnull - public abstract Optional getValue(@Nonnull String key); + public abstract @NonNull Optional getValue(@NonNull String key); /** * Get the value if it exists, else return the default value @@ -69,15 +66,13 @@ public abstract class CommandMeta { * @param defaultValue Default value * @return Value, or default value */ - @Nonnull - public abstract String getOrDefault(@Nonnull String key, @Nonnull String defaultValue); + public abstract @NonNull String getOrDefault(@NonNull String key, @NonNull String defaultValue); /** * Get a copy of the meta map * * @return Copy of meta map */ - @Nonnull - public abstract Map getAll(); + public abstract @NonNull Map<@NonNull String, @NonNull String> getAll(); } diff --git a/cloud-core/src/main/java/cloud/commandframework/meta/SimpleCommandMeta.java b/cloud-core/src/main/java/cloud/commandframework/meta/SimpleCommandMeta.java index bdc94d53..18ad155d 100644 --- a/cloud-core/src/main/java/cloud/commandframework/meta/SimpleCommandMeta.java +++ b/cloud-core/src/main/java/cloud/commandframework/meta/SimpleCommandMeta.java @@ -23,7 +23,8 @@ // package cloud.commandframework.meta; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -38,7 +39,7 @@ public class SimpleCommandMeta extends CommandMeta { private final Map metaMap; - protected SimpleCommandMeta(@Nonnull final Map metaMap) { + protected SimpleCommandMeta(@NonNull final Map<@NonNull String, @NonNull String> metaMap) { this.metaMap = Collections.unmodifiableMap(metaMap); } @@ -47,8 +48,7 @@ public class SimpleCommandMeta extends CommandMeta { * * @return Builder instance */ - @Nonnull - public static SimpleCommandMeta.Builder builder() { + public static SimpleCommandMeta.@NonNull Builder builder() { return new Builder(); } @@ -57,26 +57,22 @@ public class SimpleCommandMeta extends CommandMeta { * * @return Empty instance */ - @Nonnull - public static SimpleCommandMeta empty() { + public static @NonNull SimpleCommandMeta empty() { return SimpleCommandMeta.builder().build(); } @Override - @Nonnull - public final Optional getValue(@Nonnull final String key) { + public final @NonNull Optional getValue(@NonNull final String key) { return Optional.ofNullable(this.metaMap.get(key)); } @Override - @Nonnull - public final String getOrDefault(@Nonnull final String key, @Nonnull final String defaultValue) { + public final @NonNull String getOrDefault(@NonNull final String key, @NonNull final String defaultValue) { return this.getValue(key).orElse(defaultValue); } @Override - @Nonnull - public final Map getAll() { + public final @NonNull Map<@NonNull String, @NonNull String> getAll() { return new HashMap<>(this.metaMap); } @@ -113,8 +109,7 @@ public class SimpleCommandMeta extends CommandMeta { * @param commandMeta Existing instance * @return Builder instance */ - @Nonnull - public Builder with(@Nonnull final CommandMeta commandMeta) { + public @NonNull Builder with(@NonNull final CommandMeta commandMeta) { commandMeta.getAll().forEach(this::with); return this; } @@ -126,8 +121,8 @@ public class SimpleCommandMeta extends CommandMeta { * @param value Value * @return Builder instance */ - @Nonnull - public Builder with(@Nonnull final String key, @Nonnull final String value) { + public @NonNull Builder with(@NonNull final String key, + @NonNull final String value) { this.map.put(key, value); return this; } @@ -137,8 +132,7 @@ public class SimpleCommandMeta extends CommandMeta { * * @return Meta instance */ - @Nonnull - public SimpleCommandMeta build() { + public @NonNull SimpleCommandMeta build() { return new SimpleCommandMeta(this.map); } diff --git a/cloud-core/src/test/java/cloud/commandframework/ParserRegistryTest.java b/cloud-core/src/test/java/cloud/commandframework/ParserRegistryTest.java index 0b8b2009..59cbeaf2 100644 --- a/cloud-core/src/test/java/cloud/commandframework/ParserRegistryTest.java +++ b/cloud-core/src/test/java/cloud/commandframework/ParserRegistryTest.java @@ -24,17 +24,16 @@ package cloud.commandframework; import cloud.commandframework.annotations.specifier.Range; -import cloud.commandframework.arguments.standard.IntegerArgument; -import io.leangen.geantyref.TypeToken; import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.arguments.parser.ParserParameters; import cloud.commandframework.arguments.parser.ParserRegistry; import cloud.commandframework.arguments.parser.StandardParameters; import cloud.commandframework.arguments.parser.StandardParserRegistry; +import cloud.commandframework.arguments.standard.IntegerArgument; +import io.leangen.geantyref.TypeToken; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import javax.annotation.Nonnull; import java.lang.annotation.Annotation; import java.util.Collections; @@ -53,13 +52,11 @@ public class ParserRegistryTest { return Range.class; } - @Nonnull @Override public String min() { return Integer.toString(RANGE_MIN); } - @Nonnull @Override public String max() { return Integer.toString(RANGE_MAX);