chore(core): deprecate prefixed accessors/mutators in CommandManager (#377)

chore(core): deprecate prefixed accessors/mutators in CommandManager.java

All prefixed (actual) getters/setters in CommandManager have been deprecated, and non-prefixed alternatives have been introduced. I've also put some effort into improving the JavaDocs of these methods.
This commit is contained in:
Alexander Söderberg 2022-06-13 10:57:12 +02:00 committed by Jason
parent 687cd4c536
commit 296539d56c
48 changed files with 400 additions and 157 deletions

View file

@ -439,7 +439,7 @@ public final class AnnotationParser<C> {
));
}
try {
this.manager.getParserRegistry().registerSuggestionProvider(
this.manager.parserRegistry().registerSuggestionProvider(
this.processString(suggestions.value()),
new MethodSuggestionsProvider<>(instance, method)
);
@ -476,7 +476,7 @@ public final class AnnotationParser<C> {
if (suggestions.isEmpty()) {
suggestionsProvider = (context, input) -> Collections.emptyList();
} else {
suggestionsProvider = this.manager.getParserRegistry().getSuggestionProvider(suggestions)
suggestionsProvider = this.manager.parserRegistry().getSuggestionProvider(suggestions)
.orElseThrow(() -> new NullPointerException(
String.format(
"Cannot find the suggestions provider with name '%s'",
@ -493,12 +493,12 @@ public final class AnnotationParser<C> {
parameters -> methodArgumentParser;
final String name = this.processString(parser.name());
if (name.isEmpty()) {
this.manager.getParserRegistry().registerParserSupplier(
this.manager.parserRegistry().registerParserSupplier(
TypeToken.get(method.getGenericReturnType()),
parserFunction
);
} else {
this.manager.getParserRegistry().registerNamedParserSupplier(
this.manager.parserRegistry().registerNamedParserSupplier(
name,
parserFunction
);
@ -687,12 +687,12 @@ public final class AnnotationParser<C> {
final Parameter parameter = argumentPair.getParameter();
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
final TypeToken<?> token = TypeToken.get(parameter.getParameterizedType());
final ParserParameters parameters = this.manager.getParserRegistry()
final ParserParameters parameters = this.manager.parserRegistry()
.parseAnnotations(token, annotations);
/* Create the argument parser */
final ArgumentParser<C, ?> parser;
if (argumentPair.getArgument().parserName().isEmpty()) {
parser = this.manager.getParserRegistry()
parser = this.manager.parserRegistry()
.createParser(token, parameters)
.orElseThrow(() -> new IllegalArgumentException(
String.format("Parameter '%s' in method '%s' "
@ -702,7 +702,7 @@ public final class AnnotationParser<C> {
token.getType().getTypeName()
)));
} else {
parser = this.manager.getParserRegistry()
parser = this.manager.parserRegistry()
.createParser(argumentPair.getArgument().parserName(), parameters)
.orElseThrow(() -> new IllegalArgumentException(
String.format("Parameter '%s' in method '%s' "
@ -745,7 +745,7 @@ public final class AnnotationParser<C> {
} else if (!argument.suggestions().isEmpty()) { /* Check whether or not a suggestion provider should be set */
final String suggestionProviderName = argument.suggestions();
final Optional<BiFunction<CommandContext<C>, String, List<String>>> suggestionsFunction =
this.manager.getParserRegistry().getSuggestionProvider(suggestionProviderName);
this.manager.parserRegistry().getSuggestionProvider(suggestionProviderName);
argumentBuilder.withSuggestionsProvider(
suggestionsFunction.orElseThrow(() ->
new IllegalArgumentException(String.format(

View file

@ -65,7 +65,7 @@ public @interface Argument {
* <p>
* For this to work, the suggestion needs to be registered in the parser registry. To do this, use
* {@link cloud.commandframework.arguments.parser.ParserRegistry#registerSuggestionProvider(String, BiFunction)}.
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#getParserRegistry()}.
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#parserRegistry()}.
*
* @return The name of the suggestion provider, or {@code ""} if the default suggestion provider for the argument parser
* should be used instead

View file

@ -72,7 +72,7 @@ public @interface Flag {
* <p>
* For this to work, the suggestion needs to be registered in the parser registry. To do this, use
* {@link cloud.commandframework.arguments.parser.ParserRegistry#registerSuggestionProvider(String, BiFunction)}.
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#getParserRegistry()}.
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#parserRegistry()}.
*
* @return The name of the suggestion provider, or {@code ""} if the default suggestion provider for the argument parser
* should be used instead

View file

@ -75,7 +75,7 @@ final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNu
} else {
final TypeToken<?> token = TypeToken.get(parameter.getType());
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
final ParserRegistry<?> registry = this.commandManager.getParserRegistry();
final ParserRegistry<?> registry = this.commandManager.parserRegistry();
final ArgumentParser<?, ?> parser;
final String parserName = this.annotationParser.processString(flag.parserName());
if (parserName.isEmpty()) {

View file

@ -61,7 +61,7 @@ public @interface Parser {
* <p>
* For this to work, the suggestion needs to be registered in the parser registry. To do this, use
* {@link cloud.commandframework.arguments.parser.ParserRegistry#registerSuggestionProvider(String, BiFunction)}.
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#getParserRegistry()}.
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#parserRegistry()}.
*
* @return The name of the suggestion provider, or {@code ""}
*/

View file

@ -72,10 +72,10 @@ class AnnotationParserTest {
void setup() {
manager = new TestCommandManager();
annotationParser = new AnnotationParser<>(manager, TestCommandSender.class, p -> SimpleCommandMeta.empty());
manager.getParserRegistry().registerNamedParserSupplier("potato", p -> new StringArgument.StringParser<>(
manager.parserRegistry().registerNamedParserSupplier("potato", p -> new StringArgument.StringParser<>(
StringArgument.StringMode.SINGLE, (c, s) -> Collections.singletonList("potato")));
/* Register a suggestion provider */
manager.getParserRegistry().registerSuggestionProvider(
manager.parserRegistry().registerSuggestionProvider(
"some-name",
(context, input) -> NAMED_SUGGESTIONS
);
@ -156,7 +156,7 @@ class AnnotationParserTest {
@Test
void testAnnotatedSuggestionsProviders() {
final BiFunction<CommandContext<TestCommandSender>, String, List<String>> suggestionsProvider =
this.manager.getParserRegistry().getSuggestionProvider("cows").orElse(null);
this.manager.parserRegistry().getSuggestionProvider("cows").orElse(null);
Assertions.assertNotNull(suggestionsProvider);
Assertions.assertTrue(suggestionsProvider.apply(new CommandContext<>(new TestCommandSender(), manager), "")
.contains("Stella"));
@ -164,7 +164,7 @@ class AnnotationParserTest {
@Test
void testAnnotatedArgumentParser() {
final ArgumentParser<TestCommandSender, CustomType> parser = this.manager.getParserRegistry().createParser(
final ArgumentParser<TestCommandSender, CustomType> parser = this.manager.parserRegistry().createParser(
TypeToken.get(CustomType.class),
ParserParameters.empty()
).orElseThrow(() -> new NullPointerException("Could not find CustomType parser"));

View file

@ -27,6 +27,7 @@ import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.internal.CommandRegistrationHandler;
import cloud.commandframework.meta.SimpleCommandMeta;
import org.checkerframework.checker.nullness.qual.NonNull;
public class TestCommandManager extends CommandManager<TestCommandSender> {
@ -41,8 +42,8 @@ public class TestCommandManager extends CommandManager<TestCommandSender> {
@Override
public final boolean hasPermission(
final TestCommandSender sender,
final String permission
final @NonNull TestCommandSender sender,
final @NonNull String permission
) {
return !permission.equalsIgnoreCase("no");
}

View file

@ -97,7 +97,7 @@ class StringProcessingTest {
this.annotationParser.parse(testClassA);
// Assert
final List<Command<TestCommandSender>> commands = new ArrayList<>(this.commandManager.getCommands());
final List<Command<TestCommandSender>> commands = new ArrayList<>(this.commandManager.commands());
assertThat(commands).hasSize(1);
final Command<TestCommandSender> command = commands.get(0);

View file

@ -54,7 +54,7 @@ class Issue262 {
@BeforeEach
void setup() {
this.manager = new TestCommandManager();
this.commandHelpHandler = this.manager.getCommandHelpHandler();
this.commandHelpHandler = this.manager.createCommandHelpHandler();
this.annotationParser = new AnnotationParser<>(
this.manager,
TestCommandSender.class,