|
25 | 25 | package org.spongepowered.api.command.parameter;
|
26 | 26 |
|
27 | 27 | import com.google.common.reflect.TypeToken;
|
| 28 | +import org.checkerframework.checker.nullness.qual.NonNull; |
28 | 29 | import org.checkerframework.checker.nullness.qual.Nullable;
|
29 | 30 | import org.spongepowered.api.CatalogType;
|
30 | 31 | import org.spongepowered.api.Sponge;
|
@@ -738,41 +739,22 @@ static <T> Parameter.Value.Builder<T> literal(Class<T> returnType, T returnedVal
|
738 | 739 | }
|
739 | 740 |
|
740 | 741 | /**
|
741 |
| - * Parses the next element(s) in the {@link CommandContext} |
| 742 | + * Gets whether this parameter can be considered terminal. |
742 | 743 | *
|
743 |
| - * @param reader The {@link ArgumentReader.Mutable} containing the strings |
744 |
| - * that need to be parsed |
745 |
| - * @param context The {@link CommandContext.Builder} that contains the |
746 |
| - * current state of the execution |
747 |
| - * @throws ArgumentParseException thrown if the parameter could not be |
748 |
| - * parsed |
749 |
| - */ |
750 |
| - void parse(ArgumentReader.Mutable reader, CommandContext.Builder context) throws ArgumentParseException; |
751 |
| - |
752 |
| - /** |
753 |
| - * Returns potential completions of the current tokenized argument. |
754 |
| - * |
755 |
| - * @param reader The {@link ArgumentReader} containing the strings that need |
756 |
| - * to be parsed |
757 |
| - * @param context The {@link CommandContext} that contains the |
758 |
| - * current state of the execution. |
759 |
| - * @return The potential completions. |
760 |
| - * @throws ArgumentParseException thrown if the parameter could not be |
761 |
| - * parsed |
762 |
| - */ |
763 |
| - List<String> complete(ArgumentReader.Immutable reader, CommandContext context) throws ArgumentParseException; |
764 |
| - |
765 |
| - /** |
766 |
| - * Gets the usage of this parameter. |
| 744 | + * <p>A terminal parameter will pass control to the command's associated |
| 745 | + * {@link CommandExecutor} if the parameter consumes the end of an input |
| 746 | + * string.</p> |
767 | 747 | *
|
768 |
| - * @param cause The {@link CommandCause} that requested the usage |
769 |
| - * @return The usage |
| 748 | + * @return true if terminal, else false. |
770 | 749 | */
|
771 |
| - Text getUsage(CommandCause cause); |
| 750 | + boolean isTerminal(); |
772 | 751 |
|
773 | 752 | /**
|
774 | 753 | * Gets whether this parameter is optional.
|
775 | 754 | *
|
| 755 | + * <p>An optional parameter will not throw an exception if it cannot parse |
| 756 | + * an input, instead passing control to another parameter.</p> |
| 757 | + * |
776 | 758 | * @return true if optional, else false.
|
777 | 759 | */
|
778 | 760 | boolean isOptional();
|
@@ -814,7 +796,7 @@ interface Builder extends ResettableBuilder<Key<?>, Builder> {
|
814 | 796 | * @param <T> The type of the value represented by the key
|
815 | 797 | * @return The built {@link Key}
|
816 | 798 | */
|
817 |
| - <T> Key<T> build(String key, TypeToken<T> typeToken); |
| 799 | + <T> Key<T> build(@NonNull String key, @NonNull TypeToken<T> typeToken); |
818 | 800 | }
|
819 | 801 |
|
820 | 802 | }
|
@@ -868,6 +850,39 @@ interface Value<T> extends Parameter {
|
868 | 850 | */
|
869 | 851 | Predicate<CommandCause> getRequirement();
|
870 | 852 |
|
| 853 | + /** |
| 854 | + * Parses the next element(s) in the {@link CommandContext} |
| 855 | + * |
| 856 | + * @param reader The {@link ArgumentReader.Mutable} containing the strings |
| 857 | + * that need to be parsed |
| 858 | + * @param context The {@link CommandContext.Builder} that contains the |
| 859 | + * current state of the execution |
| 860 | + * @throws ArgumentParseException thrown if the parameter could not be |
| 861 | + * parsed |
| 862 | + */ |
| 863 | + void parse(ArgumentReader.@NonNull Mutable reader, CommandContext.@NonNull Builder context) throws ArgumentParseException; |
| 864 | + |
| 865 | + /** |
| 866 | + * Returns potential completions of the current tokenized argument. |
| 867 | + * |
| 868 | + * @param reader The {@link ArgumentReader} containing the strings that need |
| 869 | + * to be parsed |
| 870 | + * @param context The {@link CommandContext} that contains the |
| 871 | + * current state of the execution. |
| 872 | + * @return The potential completions. |
| 873 | + * @throws ArgumentParseException thrown if the parameter could not be |
| 874 | + * parsed |
| 875 | + */ |
| 876 | + List<String> complete(ArgumentReader.@NonNull Immutable reader, @NonNull CommandContext context) throws ArgumentParseException; |
| 877 | + |
| 878 | + /** |
| 879 | + * Gets the usage of this parameter. |
| 880 | + * |
| 881 | + * @param cause The {@link CommandCause} that requested the usage |
| 882 | + * @return The usage |
| 883 | + */ |
| 884 | + Text getUsage(CommandCause cause); |
| 885 | + |
871 | 886 | /**
|
872 | 887 | * Builds a {@link Parameter} from constituent components.
|
873 | 888 | */
|
@@ -1159,15 +1174,15 @@ interface SequenceBuilder extends ResettableBuilder<Parameter, SequenceBuilder>
|
1159 | 1174 | *
|
1160 | 1175 | * @return This builder, for chaining
|
1161 | 1176 | */
|
1162 |
| - SequenceBuilder optional(); |
| 1177 | + SequenceBuilder terminal(); |
1163 | 1178 |
|
1164 | 1179 | /**
|
1165 | 1180 | * Sets that this parameter is weak optional and will be ignored if it
|
1166 | 1181 | * cannot parse the next element(s).
|
1167 | 1182 | *
|
1168 | 1183 | * @return This builder, for chaining
|
1169 | 1184 | */
|
1170 |
| - SequenceBuilder optionalWeak(); |
| 1185 | + SequenceBuilder optional(); |
1171 | 1186 |
|
1172 | 1187 | /**
|
1173 | 1188 | * Defines the next parameter in the parameter sequence.
|
@@ -1228,15 +1243,15 @@ interface FirstOfBuilder extends ResettableBuilder<Parameter, FirstOfBuilder> {
|
1228 | 1243 | *
|
1229 | 1244 | * @return This builder, for chaining
|
1230 | 1245 | */
|
1231 |
| - FirstOfBuilder optional(); |
| 1246 | + FirstOfBuilder terminal(); |
1232 | 1247 |
|
1233 | 1248 | /**
|
1234 | 1249 | * Sets that this parameter is weak optional and will be ignored if it
|
1235 | 1250 | * cannot parse the next element(s).
|
1236 | 1251 | *
|
1237 | 1252 | * @return This builder, for chaining
|
1238 | 1253 | */
|
1239 |
| - FirstOfBuilder optionalWeak(); |
| 1254 | + FirstOfBuilder optional(); |
1240 | 1255 |
|
1241 | 1256 | /**
|
1242 | 1257 | * Adds a parameter that can be used to parse an argument. Parameters
|
|
0 commit comments