Skip to content

Commit 4e4fb57

Browse files
author
Alexander Söderberg
committed
Merge branch '2.0.0-dev' into feature/2.0.0/generic-suggestions
# Conflicts: # cloud-minecraft/cloud-brigadier/src/main/java/cloud/commandframework/brigadier/CloudBrigadierManager.java
2 parents 0aa2d95 + aa297bf commit 4e4fb57

94 files changed

Lines changed: 2064 additions & 742 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import cloud.commandframework.arguments.parser.ArgumentParser;
3838
import cloud.commandframework.arguments.parser.ParserParameter;
3939
import cloud.commandframework.arguments.parser.ParserParameters;
40-
import cloud.commandframework.arguments.parser.StandardParameters;
4140
import cloud.commandframework.arguments.preprocessor.RegexPreprocessor;
4241
import cloud.commandframework.arguments.suggestion.SuggestionProvider;
4342
import cloud.commandframework.captions.Caption;
@@ -77,6 +76,8 @@
7776
import org.checkerframework.checker.nullness.qual.NonNull;
7877
import org.checkerframework.checker.nullness.qual.Nullable;
7978

79+
import static cloud.commandframework.CommandDescription.commandDescription;
80+
8081
/**
8182
* Parser that parses class instances {@link Command commands}
8283
*
@@ -125,6 +126,19 @@ public AnnotationParser(
125126
this(manager, TypeToken.get(commandSenderClass), metaMapper);
126127
}
127128

129+
/**
130+
* Construct a new annotation parser
131+
*
132+
* @param manager Command manager instance
133+
* @param commandSenderClass Command sender class
134+
*/
135+
public AnnotationParser(
136+
final @NonNull CommandManager<C> manager,
137+
final @NonNull Class<C> commandSenderClass
138+
) {
139+
this(manager, TypeToken.get(commandSenderClass), parameters -> SimpleCommandMeta.empty());
140+
}
141+
128142
/**
129143
* Construct a new annotation parser
130144
*
@@ -156,8 +170,11 @@ public AnnotationParser(
156170
this.argumentAssembler = new ArgumentAssemblerImpl<>(this);
157171
this.commandExtractor = new CommandExtractorImpl(this);
158172
this.suggestionProviderFactory = SuggestionProviderFactory.defaultFactory();
159-
this.registerAnnotationMapper(CommandDescription.class, d ->
160-
ParserParameters.single(StandardParameters.DESCRIPTION, this.processString(d.value())));
173+
// TODO(City): Add mapper so that we can map this to rich descriptions easily.
174+
this.registerBuilderModifier(
175+
CommandDescription.class,
176+
(description, builder) -> builder.commandDescription(commandDescription(this.processString(description.value())))
177+
);
161178
this.registerPreprocessorMapper(Regex.class, annotation -> RegexPreprocessor.of(
162179
this.processString(annotation.value()),
163180
Caption.of(this.processString(annotation.failureCaption()))

cloud-annotations/src/main/java/cloud/commandframework/annotations/ArgumentDescriptor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//
2424
package cloud.commandframework.annotations;
2525

26-
import cloud.commandframework.ArgumentDescription;
26+
import cloud.commandframework.Description;
2727
import cloud.commandframework.arguments.suggestion.SuggestionProvider;
2828
import java.lang.reflect.Parameter;
2929
import java.util.Objects;
@@ -39,7 +39,7 @@ public final class ArgumentDescriptor implements Descriptor {
3939
private final String parserName;
4040
private final String suggestions;
4141
private final String defaultValue;
42-
private final ArgumentDescription description;
42+
private final Description description;
4343

4444
/**
4545
* Creates a new builder.
@@ -56,7 +56,7 @@ private ArgumentDescriptor(
5656
final @Nullable String parserName,
5757
final @Nullable String suggestions,
5858
final @Nullable String defaultValue,
59-
final @Nullable ArgumentDescription description
59+
final @Nullable Description description
6060
) {
6161
this.parameter = parameter;
6262
this.name = name;
@@ -127,7 +127,7 @@ private ArgumentDescriptor(
127127
*
128128
* @return the argument description, or {@code null}
129129
*/
130-
public @Nullable ArgumentDescription description() {
130+
public @Nullable Description description() {
131131
return this.description;
132132
}
133133

@@ -161,15 +161,15 @@ public static final class Builder {
161161
private final String parserName;
162162
private final String suggestions;
163163
private final String defaultValue;
164-
private final ArgumentDescription description;
164+
private final Description description;
165165

166166
private Builder(
167167
final @Nullable Parameter parameter,
168168
final @Nullable String name,
169169
final @Nullable String parserName,
170170
final @Nullable String suggestions,
171171
final @Nullable String defaultValue,
172-
final @Nullable ArgumentDescription description
172+
final @Nullable Description description
173173
) {
174174
this.parameter = parameter;
175175
this.name = name;
@@ -260,7 +260,7 @@ private Builder() {
260260
* @param description the new description
261261
* @return the builder containing the updated description
262262
*/
263-
public @NonNull Builder description(final @Nullable ArgumentDescription description) {
263+
public @NonNull Builder description(final @Nullable Description description) {
264264
return new Builder(this.parameter, this.name, this.parserName, this.suggestions, this.defaultValue, description);
265265
}
266266

cloud-annotations/src/main/java/cloud/commandframework/annotations/ArgumentExtractorImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//
2424
package cloud.commandframework.annotations;
2525

26-
import cloud.commandframework.ArgumentDescription;
26+
import cloud.commandframework.Description;
2727
import java.lang.reflect.Method;
2828
import java.lang.reflect.Parameter;
2929
import java.util.ArrayList;
@@ -39,10 +39,10 @@
3939
*/
4040
class ArgumentExtractorImpl implements ArgumentExtractor {
4141

42-
private final Function<@NonNull Argument, @Nullable ArgumentDescription> descriptionMapper;
42+
private final Function<@NonNull Argument, @Nullable Description> descriptionMapper;
4343

4444
ArgumentExtractorImpl() {
45-
this.descriptionMapper = argument -> ArgumentDescription.of(argument.description());
45+
this.descriptionMapper = argument -> Description.of(argument.description());
4646
}
4747

4848
@Override

cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandDescription.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
//
2424
package cloud.commandframework.annotations;
2525

26-
import cloud.commandframework.arguments.parser.StandardParameters;
26+
import cloud.commandframework.Command;
2727
import java.lang.annotation.ElementType;
2828
import java.lang.annotation.Retention;
2929
import java.lang.annotation.RetentionPolicy;
3030
import java.lang.annotation.Target;
3131
import org.checkerframework.checker.nullness.qual.NonNull;
3232

3333
/**
34-
* Maps to {@link StandardParameters#DESCRIPTION}
34+
* Annotation that modifies the command builder
35+
* to invoke {@link Command.Builder#commandDescription(cloud.commandframework.CommandDescription)}
36+
* using {@link cloud.commandframework.CommandDescription#commandDescription(String)}.
3537
*/
3638
@Retention(RetentionPolicy.RUNTIME)
3739
@Target({ElementType.METHOD, ElementType.TYPE})

cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagAssemblerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
//
2424
package cloud.commandframework.annotations;
2525

26-
import cloud.commandframework.ArgumentDescription;
2726
import cloud.commandframework.CommandComponent;
2827
import cloud.commandframework.CommandManager;
28+
import cloud.commandframework.Description;
2929
import cloud.commandframework.arguments.flags.CommandFlag;
3030
import cloud.commandframework.arguments.parser.ArgumentParser;
3131
import cloud.commandframework.arguments.parser.ParserRegistry;
@@ -50,9 +50,9 @@ final class FlagAssemblerImpl implements FlagAssembler {
5050
@Override
5151
@SuppressWarnings({"unchecked", "rawtypes"})
5252
public @NonNull CommandFlag<?> assembleFlag(@NonNull final FlagDescriptor descriptor) {
53-
final ArgumentDescription description;
53+
final Description description;
5454
if (descriptor.description() == null) {
55-
description = ArgumentDescription.empty();
55+
description = Description.empty();
5656
} else {
5757
description = descriptor.description();
5858
}

cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagDescriptor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//
2424
package cloud.commandframework.annotations;
2525

26-
import cloud.commandframework.ArgumentDescription;
26+
import cloud.commandframework.Description;
2727
import cloud.commandframework.arguments.suggestion.SuggestionProvider;
2828
import cloud.commandframework.permission.CommandPermission;
2929
import java.lang.reflect.Parameter;
@@ -45,7 +45,7 @@ public final class FlagDescriptor implements Descriptor {
4545
private final String parserName;
4646
private final String suggestions;
4747
private final CommandPermission permission;
48-
private final ArgumentDescription description;
48+
private final Description description;
4949
private final boolean repeatable;
5050

5151
/**
@@ -64,7 +64,7 @@ private FlagDescriptor(
6464
final @Nullable String parserName,
6565
final @Nullable String suggestions,
6666
final @Nullable CommandPermission permission,
67-
final @Nullable ArgumentDescription description,
67+
final @Nullable Description description,
6868
final boolean repeatable
6969
) {
7070
this.parameter = parameter;
@@ -147,7 +147,7 @@ private FlagDescriptor(
147147
*
148148
* @return the flag description, or {@code null}
149149
*/
150-
public @Nullable ArgumentDescription description() {
150+
public @Nullable Description description() {
151151
return this.description;
152152
}
153153

@@ -203,7 +203,7 @@ public static final class Builder {
203203
private final String parserName;
204204
private final String suggestions;
205205
private final CommandPermission permission;
206-
private final ArgumentDescription description;
206+
private final Description description;
207207
private final boolean repeatable;
208208

209209
private Builder(
@@ -213,7 +213,7 @@ private Builder(
213213
final @Nullable String parserName,
214214
final @Nullable String suggestions,
215215
final @Nullable CommandPermission permission,
216-
final @Nullable ArgumentDescription description,
216+
final @Nullable Description description,
217217
final boolean repeatable
218218
) {
219219
this.parameter = parameter;
@@ -365,7 +365,7 @@ private Builder() {
365365
* @param description the new description
366366
* @return the builder containing the updated description
367367
*/
368-
public @NonNull Builder description(final @Nullable ArgumentDescription description) {
368+
public @NonNull Builder description(final @Nullable Description description) {
369369
return new Builder(
370370
this.parameter,
371371
this.name,

cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagExtractorImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//
2424
package cloud.commandframework.annotations;
2525

26-
import cloud.commandframework.ArgumentDescription;
26+
import cloud.commandframework.Description;
2727
import cloud.commandframework.permission.Permission;
2828
import java.lang.reflect.Method;
2929
import java.lang.reflect.Parameter;
@@ -53,7 +53,7 @@ final class FlagExtractorImpl implements FlagExtractor {
5353
final FlagDescriptor flagDescriptor = FlagDescriptor.builder()
5454
.parameter(parameter)
5555
.name(flagName)
56-
.description(ArgumentDescription.of(this.annotationParser.processString(flag.description())))
56+
.description(Description.of(this.annotationParser.processString(flag.description())))
5757
.aliases(this.annotationParser.processStrings(Arrays.asList(flag.aliases())))
5858
.permission(Permission.of(this.annotationParser.processString(flag.permission())))
5959
.repeatable(flag.repeatable())

cloud-annotations/src/test/java/cloud/commandframework/annotations/feature/StringProcessingTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import cloud.commandframework.annotations.TestCommandSender;
3737
import cloud.commandframework.arguments.flags.CommandFlag;
3838
import cloud.commandframework.arguments.flags.CommandFlagParser;
39-
import cloud.commandframework.arguments.parser.StandardParameters;
4039
import cloud.commandframework.meta.CommandMeta;
4140
import com.google.common.collect.ImmutableMap;
4241
import java.util.ArrayList;
@@ -61,9 +60,7 @@ void setup() {
6160
this.annotationParser = new AnnotationParser<>(
6261
this.commandManager,
6362
TestCommandSender.class,
64-
p -> CommandMeta.simple()
65-
.with(CommandMeta.DESCRIPTION, p.get(StandardParameters.DESCRIPTION, "No description"))
66-
.build()
63+
p -> CommandMeta.simple().build()
6764
);
6865
}
6966

@@ -103,7 +100,7 @@ void testStringProcessing() {
103100
final Command<TestCommandSender> command = commands.get(0);
104101
assertThat(command.toString()).isEqualTo(String.format("%s argument flags", testProperty));
105102
assertThat(command.commandPermission().toString()).isEqualTo(testProperty);
106-
assertThat(command.commandMeta().get(CommandMeta.DESCRIPTION)).hasValue(testProperty);
103+
assertThat(command.commandDescription().description().textDescription()).isEqualTo(testProperty);
107104

108105
final List<CommandComponent<TestCommandSender>> components = command.components();
109106
assertThat(components).hasSize(3);

cloud-annotations/src/test/java/cloud/commandframework/annotations/issue/Issue262.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void queryForCommandAliasesWorks() {
7575

7676
final CommandHelpHandler.VerboseHelpTopic<TestCommandSender> topic =
7777
(CommandHelpHandler.VerboseHelpTopic<TestCommandSender>) result;
78-
assertThat(topic.getCommand().toString()).isEqualTo("cloudcommand sub2 argument");
78+
assertThat(topic.command().toString()).isEqualTo("cloudcommand sub2 argument");
7979
}
8080

8181
@Test
@@ -91,7 +91,7 @@ void queryForCommandChildAliasesWorks() {
9191

9292
final CommandHelpHandler.VerboseHelpTopic<TestCommandSender> topic =
9393
(CommandHelpHandler.VerboseHelpTopic<TestCommandSender>) result;
94-
assertThat(topic.getCommand().toString()).isEqualTo("cloudcommand sub2 argument");
94+
assertThat(topic.command().toString()).isEqualTo("cloudcommand sub2 argument");
9595
}
9696

9797
@Test
@@ -109,7 +109,7 @@ void queryForRootCommandWorks() {
109109

110110
final CommandHelpHandler.VerboseHelpTopic<TestCommandSender> topic =
111111
(CommandHelpHandler.VerboseHelpTopic<TestCommandSender>) result;
112-
assertThat(topic.getCommand().toString()).isEqualTo("cloudcommand sub2 argument");
112+
assertThat(topic.command().toString()).isEqualTo("cloudcommand sub2 argument");
113113
}
114114

115115
@Test
@@ -127,7 +127,7 @@ void queryForRootCommandWorks2() {
127127

128128
final CommandHelpHandler.VerboseHelpTopic<TestCommandSender> topic =
129129
(CommandHelpHandler.VerboseHelpTopic<TestCommandSender>) result;
130-
assertThat(topic.getCommand().toString()).isEqualTo("cloudcommand sub1 argument");
130+
assertThat(topic.command().toString()).isEqualTo("cloudcommand sub1 argument");
131131
}
132132

133133
@Test

0 commit comments

Comments
 (0)