Skip to content

Commit

Permalink
chore(core): add @This annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Jun 6, 2022
1 parent 8cfc80e commit c3c920f
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<C> command(final @NonNull Command<C> command) {
public @NonNull @This CommandManager<C> command(final @NonNull Command<C> 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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -378,7 +379,7 @@ public boolean isRequired() {
* @param preprocessor Preprocessor
* @return {@code this}
*/
public @NonNull CommandArgument<C, T> addPreprocessor(
public @NonNull @This CommandArgument<C, T> addPreprocessor(
final @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<String>,
@NonNull ArgumentParseResult<Boolean>> preprocessor
) {
Expand Down Expand Up @@ -595,7 +596,7 @@ protected Builder(
* @param manager Command manager
* @return Builder instance
*/
public @NonNull Builder<@NonNull C, @NonNull T> manager(final @NonNull CommandManager<C> manager) {
public @NonNull @This Builder<@NonNull C, @NonNull T> manager(final @NonNull CommandManager<C> manager) {
this.manager = manager;
return this;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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<C>,
@NonNull String, @NonNull List<String>> suggestionsProvider
) {
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -135,7 +136,7 @@ private ParseSuccess(final @NonNull T value) {
}

@Override
public @NonNull ArgumentParseResult<T> mapFailure(final Function<Throwable, Throwable> mapper) {
public @NonNull @This ArgumentParseResult<T> mapFailure(final Function<Throwable, Throwable> mapper) {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Boolean> {
Expand Down Expand Up @@ -129,7 +130,7 @@ private Builder(final @NonNull String name) {
* @param liberal liberal value
* @return Builder instance
*/
public @NonNull Builder<C> withLiberal(final boolean liberal) {
public @NonNull @This Builder<C> withLiberal(final boolean liberal) {
this.liberal = liberal;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Byte> {
Expand Down Expand Up @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) {
* @param min Minimum value
* @return Builder instance
*/
public @NonNull Builder<C> withMin(final byte min) {
public @NonNull @This Builder<C> withMin(final byte min) {
this.min = min;
return this;
}
Expand All @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) {
* @param max Maximum value
* @return Builder instance
*/
public @NonNull Builder<C> withMax(final byte max) {
public @NonNull @This Builder<C> withMax(final byte max) {
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Double> {
Expand Down Expand Up @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) {
* @param min Minimum value
* @return Builder instance
*/
public @NonNull Builder<C> withMin(final int min) {
public @NonNull @This Builder<C> withMin(final int min) {
this.min = min;
return this;
}
Expand All @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) {
* @param max Maximum value
* @return Builder instance
*/
public @NonNull Builder<C> withMax(final int max) {
public @NonNull @This Builder<C> withMax(final int max) {
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Float> {
Expand Down Expand Up @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) {
* @param min Minimum value
* @return Builder instance
*/
public @NonNull Builder<C> withMin(final int min) {
public @NonNull @This Builder<C> withMin(final int min) {
this.min = min;
return this;
}
Expand All @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) {
* @param max Maximum value
* @return Builder instance
*/
public @NonNull Builder<C> withMax(final int max) {
public @NonNull @This Builder<C> withMax(final int max) {
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Integer> {
Expand Down Expand Up @@ -151,7 +152,7 @@ private Builder(final @NonNull String name) {
* @param min Minimum value
* @return Builder instance
*/
public @NonNull Builder<C> withMin(final int min) {
public @NonNull @This Builder<C> withMin(final int min) {
this.min = min;
return this;
}
Expand All @@ -162,7 +163,7 @@ private Builder(final @NonNull String name) {
* @param max Maximum value
* @return Builder instance
*/
public @NonNull Builder<C> withMax(final int max) {
public @NonNull @This Builder<C> withMax(final int max) {
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Long> {
Expand Down Expand Up @@ -139,7 +140,7 @@ private Builder(final @NonNull String name) {
* @param min Minimum value
* @return Builder instance
*/
public @NonNull Builder<C> withMin(final long min) {
public @NonNull @This Builder<C> withMin(final long min) {
this.min = min;
return this;
}
Expand All @@ -150,7 +151,7 @@ private Builder(final @NonNull String name) {
* @param max Maximum value
* @return Builder instance
*/
public @NonNull Builder<C> withMax(final long max) {
public @NonNull @This Builder<C> withMax(final long max) {
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, Short> {
Expand Down Expand Up @@ -136,7 +137,7 @@ private Builder(final @NonNull String name) {
* @param min Minimum value
* @return Builder instance
*/
public @NonNull Builder<C> withMin(final short min) {
public @NonNull @This Builder<C> withMin(final short min) {
this.min = min;
return this;
}
Expand All @@ -147,7 +148,7 @@ private Builder(final @NonNull String name) {
* @param max Maximum value
* @return Builder instance
*/
public @NonNull Builder<C> withMax(final short max) {
public @NonNull @This Builder<C> withMax(final short max) {
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> extends CommandArgument<C, String> {
Expand Down Expand Up @@ -208,7 +209,7 @@ private Builder(final @NonNull String name) {
* @param stringMode String mode to parse with
* @return Builder instance
*/
private @NonNull Builder<C> withMode(final @NonNull StringMode stringMode) {
private @NonNull @This Builder<C> withMode(final @NonNull StringMode stringMode) {
this.stringMode = stringMode;
return this;
}
Expand All @@ -218,7 +219,7 @@ private Builder(final @NonNull String name) {
*
* @return Builder instance
*/
public @NonNull Builder<C> greedy() {
public @NonNull @This Builder<C> greedy() {
this.stringMode = StringMode.GREEDY;
return this;
}
Expand All @@ -228,7 +229,7 @@ private Builder(final @NonNull String name) {
*
* @return Builder instance
*/
public @NonNull Builder<C> single() {
public @NonNull @This Builder<C> single() {
this.stringMode = StringMode.SINGLE;
return this;
}
Expand All @@ -238,7 +239,7 @@ private Builder(final @NonNull String name) {
*
* @return Builder instance
*/
public @NonNull Builder<C> quoted() {
public @NonNull @This Builder<C> quoted() {
this.stringMode = StringMode.QUOTED;
return this;
}
Expand All @@ -250,7 +251,7 @@ private Builder(final @NonNull String name) {
* @return Builder instance
*/
@Override
public @NonNull Builder<C> withSuggestionsProvider(
public @NonNull @This Builder<C> withSuggestionsProvider(
final @NonNull BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,7 +142,7 @@ private Builder() {
*
* @return Builder instance
*/
public @NonNull Builder<C> withSynchronousParsing() {
public @NonNull @This Builder<C> withSynchronousParsing() {
this.synchronizeParsing = true;
return this;
}
Expand All @@ -151,19 +152,19 @@ private Builder() {
*
* @return Builder instance
*/
public @NonNull Builder<C> withAsynchronousParsing() {
public @NonNull @This Builder<C> 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<C> withExecutor(final @NonNull Executor executor) {
public @NonNull @This Builder<C> withExecutor(final @NonNull Executor executor) {
this.executor = executor;
return this;
}
Expand Down
Loading

0 comments on commit c3c920f

Please sign in to comment.