Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow returning ? extends Suggestion or ? extends Iterable<? extends Suggestion>> from suggestion providers #690

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void testSuggestions(final @NonNull Object instance) {
);

// Act
final Iterable<Suggestion> suggestions =
final Iterable<? extends Suggestion> suggestions =
this.commandManager.parserRegistry()
.getSuggestionProvider("suggestions")
.orElseThrow(NullPointerException::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public SuggestionContext(
*
* @param suggestions the suggestions to add
*/
public void addSuggestions(final @NonNull Iterable<@NonNull Suggestion> suggestions) {
public void addSuggestions(final @NonNull Iterable<? extends @NonNull Suggestion> suggestions) {
suggestions.forEach(this::addSuggestion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public EitherParser(final @NonNull ParserDescriptor<C, U> primary, final @NonNul

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public @NonNull CompletableFuture<@NonNull Iterable<@NonNull Suggestion>> suggestionsFuture(
public @NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(
final @NonNull CommandContext<C> context,
final @NonNull CommandInput input
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ interface BlockingSuggestionProvider<C> extends SuggestionProvider<C> {
* @param input the current input
* @return the suggestions
*/
@NonNull Iterable<@NonNull Suggestion> suggestions(@NonNull CommandContext<C> context, @NonNull CommandInput input);
@NonNull Iterable<? extends @NonNull Suggestion> suggestions(@NonNull CommandContext<C> context, @NonNull CommandInput input);

@Override
default @NonNull CompletableFuture<@NonNull Iterable<@NonNull Suggestion>> suggestionsFuture(
default @NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(
final @NonNull CommandContext<C> context,
final @NonNull CommandInput input
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface SuggestionProvider<C> {
* @param input the current input
* @return the suggestions
*/
@NonNull CompletableFuture<@NonNull Iterable<@NonNull Suggestion>> suggestionsFuture(
@NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(
@NonNull CommandContext<C> context,
@NonNull CommandInput input
);
Expand Down Expand Up @@ -132,7 +132,7 @@ static <C> SuggestionProvider<C> noSuggestions() {
* @return suggestion provider
*/
static <C> @NonNull SuggestionProvider<C> suggesting(
final @NonNull Iterable<@NonNull Suggestion> suggestions
final @NonNull Iterable<? extends @NonNull Suggestion> suggestions
) {
return blocking((ctx, input) -> suggestions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void testSuggestionsFirstArgument() {
.build();

// Act
final Iterable<Suggestion> suggestions = parser.suggestionProvider()
final Iterable<? extends Suggestion> suggestions = parser.suggestionProvider()
.suggestionsFuture(this.commandContext, CommandInput.empty()).join();

// Assert
Expand Down Expand Up @@ -172,7 +172,7 @@ void testSuggestionsSecondArgument() {
.build();

// Act
final Iterable<Suggestion> suggestions = parser.suggestionProvider()
final Iterable<? extends Suggestion> suggestions = parser.suggestionProvider()
.suggestionsFuture(this.commandContext, CommandInput.of("123 ")).join();

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testParsingFailing() {
@Test
void testSuggestions() {
// Act
final Iterable<Suggestion> suggestions = this.parser.suggestionsFuture(this.context, CommandInput.empty()).join();
final Iterable<? extends Suggestion> suggestions = this.parser.suggestionsFuture(this.context, CommandInput.empty()).join();

// Assert
assertThat(suggestions).containsExactly(
Expand Down
Loading