Skip to content

Commit

Permalink
Allow returning ? extends Suggestion or `? extends Iterable<? exten…
Browse files Browse the repository at this point in the history
…ds Suggestion>>` from suggestion providers
  • Loading branch information
jpenilla committed Feb 20, 2024
1 parent ad23f93 commit 148d0a5
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
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

0 comments on commit 148d0a5

Please sign in to comment.