From c3c920f1e2b8a4d5c6d8cc764bb8f34799a9f521 Mon Sep 17 00:00:00 2001 From: Citymonstret Date: Mon, 6 Jun 2022 07:42:23 +0200 Subject: [PATCH] chore(core): add `@This` annotations --- .../cloud/commandframework/CommandManager.java | 3 ++- .../arguments/CommandArgument.java | 17 +++++++++-------- .../arguments/parser/ArgumentParseResult.java | 3 ++- .../arguments/standard/BooleanArgument.java | 3 ++- .../arguments/standard/ByteArgument.java | 5 +++-- .../arguments/standard/DoubleArgument.java | 5 +++-- .../arguments/standard/FloatArgument.java | 5 +++-- .../arguments/standard/IntegerArgument.java | 5 +++-- .../arguments/standard/LongArgument.java | 5 +++-- .../arguments/standard/ShortArgument.java | 5 +++-- .../arguments/standard/StringArgument.java | 11 ++++++----- ...AsynchronousCommandExecutionCoordinator.java | 9 +++++---- .../meta/SimpleCommandMeta.java | 7 ++++--- 13 files changed, 48 insertions(+), 35 deletions(-) diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java index d886bea5f..c0ab371e8 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java @@ -77,6 +77,7 @@ import java.util.function.Predicate; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; /** * The manager is responsible for command registration, parsing delegation, etc. @@ -222,7 +223,7 @@ protected CommandManager( * @return The command manager instance. This is returned so that these method calls may be chained. This will always * return {@code this}. */ - public @NonNull CommandManager command(final @NonNull Command command) { + public @NonNull @This CommandManager command(final @NonNull Command command) { if (!(this.transitionIfPossible(RegistrationState.BEFORE_REGISTRATION, RegistrationState.REGISTERING) || this.isCommandRegistrationAllowed())) { throw new IllegalStateException("Unable to register commands because the manager is no longer in a registration " 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 b98f4c7d3..fb18fac0b 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/CommandArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/CommandArgument.java @@ -44,6 +44,7 @@ import java.util.regex.Pattern; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; /** * A argument that belongs to a command @@ -378,7 +379,7 @@ public boolean isRequired() { * @param preprocessor Preprocessor * @return {@code this} */ - public @NonNull CommandArgument addPreprocessor( + public @NonNull @This CommandArgument addPreprocessor( final @NonNull BiFunction<@NonNull CommandContext, @NonNull Queue, @NonNull ArgumentParseResult> preprocessor ) { @@ -595,7 +596,7 @@ protected Builder( * @param manager Command manager * @return Builder instance */ - public @NonNull Builder<@NonNull C, @NonNull T> manager(final @NonNull CommandManager manager) { + public @NonNull @This Builder<@NonNull C, @NonNull T> manager(final @NonNull CommandManager manager) { this.manager = manager; return this; } @@ -609,7 +610,7 @@ protected Builder( * * @return Builder instance */ - public @NonNull Builder<@NonNull C, @NonNull T> asRequired() { + public @NonNull @This Builder<@NonNull C, @NonNull T> asRequired() { this.required = true; return this; } @@ -623,7 +624,7 @@ protected Builder( * * @return Builder instance */ - public @NonNull Builder<@NonNull C, @NonNull T> asOptional() { + public @NonNull @This Builder<@NonNull C, @NonNull T> asOptional() { this.required = false; return this; } @@ -638,7 +639,7 @@ protected Builder( * @param defaultValue Default value that will be used if none was supplied * @return Builder instance */ - public @NonNull Builder<@NonNull C, @NonNull T> asOptionalWithDefault(final @NonNull String defaultValue) { + public @NonNull @This Builder<@NonNull C, @NonNull T> asOptionalWithDefault(final @NonNull String defaultValue) { this.defaultValue = defaultValue; this.required = false; return this; @@ -650,7 +651,7 @@ protected Builder( * @param parser Argument parser * @return Builder instance */ - public @NonNull Builder<@NonNull C, @NonNull T> withParser(final @NonNull ArgumentParser<@NonNull C, @NonNull T> parser) { + public @NonNull @This Builder<@NonNull C, @NonNull T> withParser(final @NonNull ArgumentParser<@NonNull C, @NonNull T> parser) { this.parser = Objects.requireNonNull(parser, "Parser may not be null"); return this; } @@ -661,7 +662,7 @@ protected Builder( * @param suggestionsProvider Suggestions provider * @return Builder instance */ - public @NonNull Builder<@NonNull C, @NonNull T> withSuggestionsProvider( + public @NonNull @This Builder<@NonNull C, @NonNull T> withSuggestionsProvider( final @NonNull BiFunction<@NonNull CommandContext, @NonNull String, @NonNull List> suggestionsProvider ) { @@ -678,7 +679,7 @@ protected Builder( * @return Builder instance * @since 1.4.0 */ - public @NonNull Builder<@NonNull C, @NonNull T> withDefaultDescription( + public @NonNull @This Builder<@NonNull C, @NonNull T> withDefaultDescription( final @NonNull ArgumentDescription defaultDescription ) { this.defaultDescription = Objects.requireNonNull(defaultDescription, "Default description may not be null"); 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 ad4fa8f0a..882778425 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 @@ -26,6 +26,7 @@ import java.util.Optional; import java.util.function.Function; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.common.returnsreceiver.qual.This; /** * Result of the parsing done by a {@link ArgumentParser} @@ -135,7 +136,7 @@ private ParseSuccess(final @NonNull T value) { } @Override - public @NonNull ArgumentParseResult mapFailure(final Function mapper) { + public @NonNull @This ArgumentParseResult mapFailure(final Function mapper) { return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/BooleanArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/BooleanArgument.java index 947af4bc2..546c1fae2 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/BooleanArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/BooleanArgument.java @@ -39,6 +39,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class BooleanArgument extends CommandArgument { @@ -129,7 +130,7 @@ private Builder(final @NonNull String name) { * @param liberal liberal value * @return Builder instance */ - public @NonNull Builder withLiberal(final boolean liberal) { + public @NonNull @This Builder withLiberal(final boolean liberal) { this.liberal = liberal; return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ByteArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ByteArgument.java index 86ba5389e..810ecfcc1 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ByteArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/ByteArgument.java @@ -36,6 +36,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class ByteArgument extends CommandArgument { @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) { * @param min Minimum value * @return Builder instance */ - public @NonNull Builder withMin(final byte min) { + public @NonNull @This Builder withMin(final byte min) { this.min = min; return this; } @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) { * @param max Maximum value * @return Builder instance */ - public @NonNull Builder withMax(final byte max) { + public @NonNull @This Builder withMax(final byte max) { this.max = max; return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/DoubleArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/DoubleArgument.java index d4fc4a47a..3d8061d84 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/DoubleArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/DoubleArgument.java @@ -36,6 +36,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class DoubleArgument extends CommandArgument { @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) { * @param min Minimum value * @return Builder instance */ - public @NonNull Builder withMin(final int min) { + public @NonNull @This Builder withMin(final int min) { this.min = min; return this; } @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) { * @param max Maximum value * @return Builder instance */ - public @NonNull Builder withMax(final int max) { + public @NonNull @This Builder withMax(final int max) { this.max = max; return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/FloatArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/FloatArgument.java index 516b61620..9159f86eb 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/FloatArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/FloatArgument.java @@ -36,6 +36,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class FloatArgument extends CommandArgument { @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) { * @param min Minimum value * @return Builder instance */ - public @NonNull Builder withMin(final int min) { + public @NonNull @This Builder withMin(final int min) { this.min = min; return this; } @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) { * @param max Maximum value * @return Builder instance */ - public @NonNull Builder withMax(final int max) { + public @NonNull @This Builder withMax(final int max) { this.max = max; return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/IntegerArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/IntegerArgument.java index e14f09769..e67b4787a 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/IntegerArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/IntegerArgument.java @@ -40,6 +40,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class IntegerArgument extends CommandArgument { @@ -151,7 +152,7 @@ private Builder(final @NonNull String name) { * @param min Minimum value * @return Builder instance */ - public @NonNull Builder withMin(final int min) { + public @NonNull @This Builder withMin(final int min) { this.min = min; return this; } @@ -162,7 +163,7 @@ private Builder(final @NonNull String name) { * @param max Maximum value * @return Builder instance */ - public @NonNull Builder withMax(final int max) { + public @NonNull @This Builder withMax(final int max) { this.max = max; return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/LongArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/LongArgument.java index d67c6acb6..15f1ec9e2 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/LongArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/LongArgument.java @@ -36,6 +36,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class LongArgument extends CommandArgument { @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) { * @param min Minimum value * @return Builder instance */ - public @NonNull Builder withMin(final long min) { + public @NonNull @This Builder withMin(final long min) { this.min = min; return this; } @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) { * @param max Maximum value * @return Builder instance */ - public @NonNull Builder withMax(final long max) { + public @NonNull @This Builder withMax(final long max) { this.max = max; return this; } 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 a7cc3a0b5..ea72edc56 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 @@ -36,6 +36,7 @@ import java.util.function.BiFunction; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class ShortArgument extends CommandArgument { @@ -136,7 +137,7 @@ private Builder(final @NonNull String name) { * @param min Minimum value * @return Builder instance */ - public @NonNull Builder withMin(final short min) { + public @NonNull @This Builder withMin(final short min) { this.min = min; return this; } @@ -147,7 +148,7 @@ private Builder(final @NonNull String name) { * @param max Maximum value * @return Builder instance */ - public @NonNull Builder withMax(final short max) { + public @NonNull @This Builder withMax(final short max) { this.max = max; return this; } diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/StringArgument.java b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/StringArgument.java index f2fe2885f..023bb5abc 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/standard/StringArgument.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/standard/StringArgument.java @@ -41,6 +41,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.common.returnsreceiver.qual.This; @SuppressWarnings("unused") public final class StringArgument extends CommandArgument { @@ -208,7 +209,7 @@ private Builder(final @NonNull String name) { * @param stringMode String mode to parse with * @return Builder instance */ - private @NonNull Builder withMode(final @NonNull StringMode stringMode) { + private @NonNull @This Builder withMode(final @NonNull StringMode stringMode) { this.stringMode = stringMode; return this; } @@ -218,7 +219,7 @@ private Builder(final @NonNull String name) { * * @return Builder instance */ - public @NonNull Builder greedy() { + public @NonNull @This Builder greedy() { this.stringMode = StringMode.GREEDY; return this; } @@ -228,7 +229,7 @@ private Builder(final @NonNull String name) { * * @return Builder instance */ - public @NonNull Builder single() { + public @NonNull @This Builder single() { this.stringMode = StringMode.SINGLE; return this; } @@ -238,7 +239,7 @@ private Builder(final @NonNull String name) { * * @return Builder instance */ - public @NonNull Builder quoted() { + public @NonNull @This Builder quoted() { this.stringMode = StringMode.QUOTED; return this; } @@ -250,7 +251,7 @@ private Builder(final @NonNull String name) { * @return Builder instance */ @Override - public @NonNull Builder withSuggestionsProvider( + public @NonNull @This Builder withSuggestionsProvider( final @NonNull BiFunction<@NonNull CommandContext, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider ) { 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 c4ca3d8bc..203f41b56 100644 --- a/cloud-core/src/main/java/cloud/commandframework/execution/AsynchronousCommandExecutionCoordinator.java +++ b/cloud-core/src/main/java/cloud/commandframework/execution/AsynchronousCommandExecutionCoordinator.java @@ -38,6 +38,7 @@ import java.util.function.Function; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; /** * Execution coordinator parses and/or executes commands on a separate thread from the calling thread @@ -141,7 +142,7 @@ private Builder() { * * @return Builder instance */ - public @NonNull Builder withSynchronousParsing() { + public @NonNull @This Builder withSynchronousParsing() { this.synchronizeParsing = true; return this; } @@ -151,19 +152,19 @@ private Builder() { * * @return Builder instance */ - public @NonNull Builder withAsynchronousParsing() { + public @NonNull @This Builder withAsynchronousParsing() { this.synchronizeParsing = false; return this; } /** * Specify an executor that will be used to coordinate tasks. - * By default the executor uses {@link java.util.concurrent.ForkJoinPool#commonPool()} + * By default, the executor uses {@link java.util.concurrent.ForkJoinPool#commonPool()} * * @param executor Executor to use * @return Builder instance */ - public @NonNull Builder withExecutor(final @NonNull Executor executor) { + public @NonNull @This Builder withExecutor(final @NonNull Executor executor) { this.executor = executor; return this; } 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 8f0c40faa..c7456803c 100644 --- a/cloud-core/src/main/java/cloud/commandframework/meta/SimpleCommandMeta.java +++ b/cloud-core/src/main/java/cloud/commandframework/meta/SimpleCommandMeta.java @@ -31,6 +31,7 @@ import java.util.Optional; import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.common.returnsreceiver.qual.This; /** * A simple immutable string-string map containing command meta @@ -163,7 +164,7 @@ private Builder() { * @param commandMeta Existing instance * @return Builder instance */ - public @NonNull Builder with(final @NonNull CommandMeta commandMeta) { + public @NonNull @This Builder with(final @NonNull CommandMeta commandMeta) { if (commandMeta instanceof SimpleCommandMeta) { this.map.putAll(((SimpleCommandMeta) commandMeta).metaMap); } else { @@ -181,7 +182,7 @@ private Builder() { * @deprecated For removal since 1.3.0, use {@link #with(Key, Object) the typesafe alternative} instead */ @Deprecated - public @NonNull Builder with( + public @NonNull @This Builder with( final @NonNull String key, final @NonNull String value ) { @@ -198,7 +199,7 @@ private Builder() { * @return Builder instance * @since 1.3.0 */ - public @NonNull Builder with( + public @NonNull @This Builder with( final @NonNull Key key, final @NonNull V value ) {