🚚 More removal of javax annotations
This commit is contained in:
parent
4556b392b0
commit
26f11e3a7e
47 changed files with 594 additions and 691 deletions
|
|
@ -36,9 +36,9 @@ import cloud.commandframework.meta.CommandMeta;
|
|||
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
|
|
@ -75,9 +75,9 @@ public final class AnnotationParser<C> {
|
|||
* {@link ParserParameter}. Mappers for the
|
||||
* parser parameters can be registered using {@link #registerAnnotationMapper(Class, Function)}
|
||||
*/
|
||||
public AnnotationParser(@Nonnull final CommandManager<C> manager,
|
||||
@Nonnull final Class<C> commandSenderClass,
|
||||
@Nonnull final Function<ParserParameters, CommandMeta> metaMapper) {
|
||||
public AnnotationParser(@NonNull final CommandManager<C> manager,
|
||||
@NonNull final Class<C> commandSenderClass,
|
||||
@NonNull final Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) {
|
||||
this.commandSenderClass = commandSenderClass;
|
||||
this.manager = manager;
|
||||
this.metaFactory = new MetaFactory(this, metaMapper);
|
||||
|
|
@ -93,8 +93,9 @@ public final class AnnotationParser<C> {
|
|||
* @param mapper Mapping function
|
||||
* @param <A> Annotation type
|
||||
*/
|
||||
public <A extends Annotation> void registerAnnotationMapper(@Nonnull final Class<A> annotation,
|
||||
@Nonnull final Function<A, ParserParameters> mapper) {
|
||||
public <A extends Annotation> void registerAnnotationMapper(@NonNull final Class<A> annotation,
|
||||
@NonNull final Function<@NonNull A,
|
||||
@NonNull ParserParameters> mapper) {
|
||||
this.annotationMappers.put(annotation, mapper);
|
||||
}
|
||||
|
||||
|
|
@ -106,8 +107,7 @@ public final class AnnotationParser<C> {
|
|||
* @param <T> Type of the instance
|
||||
* @return Collection of parsed annotations
|
||||
*/
|
||||
@Nonnull
|
||||
public <T> Collection<Command<C>> parse(@Nonnull final T instance) {
|
||||
public <T> @NonNull Collection<@NonNull Command<C>> parse(@NonNull final T instance) {
|
||||
final Method[] methods = instance.getClass().getDeclaredMethods();
|
||||
final Collection<CommandMethodPair> commandMethodPairs = new ArrayList<>();
|
||||
for (final Method method : methods) {
|
||||
|
|
@ -133,10 +133,10 @@ public final class AnnotationParser<C> {
|
|||
return commands;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<Command<C>> construct(@Nonnull final Object instance,
|
||||
@Nonnull final Collection<CommandMethodPair> methodPairs) {
|
||||
private @NonNull Collection<@NonNull Command<C>> construct(
|
||||
@NonNull final Object instance,
|
||||
@NonNull final Collection<@NonNull CommandMethodPair> methodPairs) {
|
||||
final Collection<Command<C>> commands = new ArrayList<>();
|
||||
for (final CommandMethodPair commandMethodPair : methodPairs) {
|
||||
final CommandMethod commandMethod = commandMethodPair.getCommandMethod();
|
||||
|
|
@ -239,11 +239,10 @@ public final class AnnotationParser<C> {
|
|||
return commands;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@SuppressWarnings("unchecked")
|
||||
private CommandArgument<C, ?> buildArgument(@Nonnull final Method method,
|
||||
@Nullable final SyntaxFragment syntaxFragment,
|
||||
@Nonnull final ArgumentParameterPair argumentPair) {
|
||||
private @NonNull CommandArgument<C, ?> buildArgument(@NonNull final Method method,
|
||||
@Nullable final SyntaxFragment syntaxFragment,
|
||||
@NonNull final ArgumentParameterPair argumentPair) {
|
||||
final Parameter parameter = argumentPair.getParameter();
|
||||
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
|
||||
final TypeToken<?> token = TypeToken.get(parameter.getParameterizedType());
|
||||
|
|
@ -291,8 +290,8 @@ public final class AnnotationParser<C> {
|
|||
return argumentBuilder.manager(this.manager).withParser(parser).build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
Map<Class<? extends Annotation>, Function<? extends Annotation, ParserParameters>> getAnnotationMappers() {
|
||||
@NonNull Map<@NonNull Class<@NonNull ? extends Annotation>,
|
||||
@NonNull Function<@NonNull ? extends Annotation, @NonNull ParserParameters>> getAnnotationMappers() {
|
||||
return this.annotationMappers;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.annotations;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -34,10 +35,10 @@ import java.util.function.Function;
|
|||
* Utility that extract {@link Argument arguments} from
|
||||
* {@link java.lang.reflect.Method method} {@link java.lang.reflect.Parameter parameters}
|
||||
*/
|
||||
class ArgumentExtractor implements Function<Method, Collection<ArgumentParameterPair>> {
|
||||
class ArgumentExtractor implements Function<@NonNull Method, Collection<@NonNull ArgumentParameterPair>> {
|
||||
|
||||
@Override
|
||||
public Collection<ArgumentParameterPair> apply(@Nonnull final Method method) {
|
||||
public @NonNull Collection<@NonNull ArgumentParameterPair> apply(@NonNull final Method method) {
|
||||
final Collection<ArgumentParameterPair> arguments = new ArrayList<>();
|
||||
for (final Parameter parameter : method.getParameters()) {
|
||||
if (!parameter.isAnnotationPresent(Argument.class)) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.annotations;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
final class ArgumentParameterPair {
|
||||
|
|
@ -31,18 +32,17 @@ final class ArgumentParameterPair {
|
|||
private final Parameter parameter;
|
||||
private final Argument argument;
|
||||
|
||||
ArgumentParameterPair(@Nonnull final Parameter parameter, @Nonnull final Argument argument) {
|
||||
ArgumentParameterPair(@NonNull final Parameter parameter,
|
||||
@NonNull final Argument argument) {
|
||||
this.parameter = parameter;
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
Parameter getParameter() {
|
||||
@NonNull Parameter getParameter() {
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
Argument getArgument() {
|
||||
@NonNull Argument getArgument() {
|
||||
return this.argument;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.annotations;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
final class CommandMethodPair {
|
||||
|
|
@ -31,18 +32,17 @@ final class CommandMethodPair {
|
|||
private final Method method;
|
||||
private final CommandMethod commandMethod;
|
||||
|
||||
CommandMethodPair(@Nonnull final Method method, @Nonnull final CommandMethod commandMethod) {
|
||||
CommandMethodPair(@NonNull final Method method,
|
||||
@NonNull final CommandMethod commandMethod) {
|
||||
this.method = method;
|
||||
this.commandMethod = commandMethod;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
Method getMethod() {
|
||||
@NonNull Method getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
CommandMethod getCommandMethod() {
|
||||
@NonNull CommandMethod getCommandMethod() {
|
||||
return this.commandMethod;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,24 +25,24 @@ package cloud.commandframework.annotations;
|
|||
|
||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||
import cloud.commandframework.meta.CommandMeta;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.function.Function;
|
||||
|
||||
class MetaFactory implements Function<Annotation[], CommandMeta> {
|
||||
class MetaFactory implements Function<@NonNull Annotation @NonNull [], @NonNull CommandMeta> {
|
||||
|
||||
private final AnnotationParser<?> annotationParser;
|
||||
private final Function<ParserParameters, CommandMeta> metaMapper;
|
||||
|
||||
MetaFactory(@Nonnull final AnnotationParser<?> annotationParser,
|
||||
@Nonnull final Function<ParserParameters, CommandMeta> metaMapper) {
|
||||
MetaFactory(@NonNull final AnnotationParser<?> annotationParser,
|
||||
@NonNull final Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) {
|
||||
this.annotationParser = annotationParser;
|
||||
this.metaMapper = metaMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandMeta apply(@Nonnull final Annotation[] annotations) {
|
||||
public @NonNull CommandMeta apply(@NonNull final Annotation @NonNull [] annotations) {
|
||||
final ParserParameters parameters = ParserParameters.empty();
|
||||
for (final Annotation annotation : annotations) {
|
||||
@SuppressWarnings("ALL") final Function function = this.annotationParser.getAnnotationMappers()
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.annotations;
|
|||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.execution.CommandExecutionHandler;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -42,9 +42,10 @@ class MethodCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
|
|||
private final MethodHandle methodHandle;
|
||||
private final Map<String, CommandArgument<C, ?>> commandArguments;
|
||||
|
||||
MethodCommandExecutionHandler(@Nonnull final Object instance,
|
||||
@Nonnull final Map<String, CommandArgument<C, ?>> commandArguments,
|
||||
@Nonnull final Method method) throws Exception {
|
||||
MethodCommandExecutionHandler(@NonNull final Object instance,
|
||||
@NonNull final Map<@NonNull String,
|
||||
@NonNull CommandArgument<@NonNull C, @NonNull ?>> commandArguments,
|
||||
@NonNull final Method method) throws Exception {
|
||||
this.commandArguments = commandArguments;
|
||||
method.setAccessible(true);
|
||||
this.methodHandle = MethodHandles.lookup().unreflect(method).bindTo(instance);
|
||||
|
|
@ -52,7 +53,7 @@ class MethodCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void execute(@Nonnull final CommandContext<C> commandContext) {
|
||||
public void execute(@NonNull final CommandContext<C> commandContext) {
|
||||
final List<Object> arguments = new ArrayList<>(this.parameters.length);
|
||||
|
||||
/* Bind parameters to context */
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@
|
|||
package cloud.commandframework.annotations;
|
||||
|
||||
import cloud.commandframework.Command;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
|
@ -44,7 +44,7 @@ public @interface ProxiedBy {
|
|||
*
|
||||
* @return Proxy syntax
|
||||
*/
|
||||
@Nonnull String value();
|
||||
@NonNull String value();
|
||||
|
||||
/**
|
||||
* Whether or not the proxying command should be {@link Hidden}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.annotations;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
final class SyntaxFragment {
|
||||
|
|
@ -32,26 +33,23 @@ final class SyntaxFragment {
|
|||
private final List<String> minor;
|
||||
private final ArgumentMode argumentMode;
|
||||
|
||||
SyntaxFragment(@Nonnull final String major,
|
||||
@Nonnull final List<String> minor,
|
||||
@Nonnull final ArgumentMode argumentMode) {
|
||||
SyntaxFragment(@NonNull final String major,
|
||||
@NonNull final List<@NonNull String> minor,
|
||||
@NonNull final ArgumentMode argumentMode) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.argumentMode = argumentMode;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
String getMajor() {
|
||||
@NonNull String getMajor() {
|
||||
return this.major;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
List<String> getMinor() {
|
||||
@NonNull List<@NonNull String> getMinor() {
|
||||
return this.minor;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
ArgumentMode getArgumentMode() {
|
||||
@NonNull ArgumentMode getArgumentMode() {
|
||||
return this.argumentMode;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
//
|
||||
package cloud.commandframework.annotations;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
|
|
@ -36,7 +37,7 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
* Parses command syntax into syntax fragments
|
||||
*/
|
||||
final class SyntaxParser implements Function<String, LinkedHashMap<String, SyntaxFragment>> {
|
||||
final class SyntaxParser implements Function<@NonNull String, @NonNull LinkedHashMap<@NonNull String, @NonNull SyntaxFragment>> {
|
||||
|
||||
private static final Predicate<String> PATTERN_ARGUMENT_LITERAL = Pattern.compile("([A-Za-z0-9]+)(|([A-Za-z0-9]+))*")
|
||||
.asPredicate();
|
||||
|
|
@ -46,7 +47,7 @@ final class SyntaxParser implements Function<String, LinkedHashMap<String, Synta
|
|||
.asPredicate();
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<String, SyntaxFragment> apply(@Nonnull final String syntax) {
|
||||
public @NonNull LinkedHashMap<@NonNull String, @NonNull SyntaxFragment> apply(@NonNull final String syntax) {
|
||||
final StringTokenizer stringTokenizer = new StringTokenizer(syntax, " ");
|
||||
final LinkedHashMap<String, SyntaxFragment> map = new LinkedHashMap<>();
|
||||
while (stringTokenizer.hasMoreTokens()) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import org.junit.jupiter.api.Assertions;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CompletionException;
|
||||
|
|
@ -63,9 +62,9 @@ class AnnotationParserTest {
|
|||
|
||||
@ProxiedBy("proxycommand")
|
||||
@CommandMethod("test|t literal <int> [string]")
|
||||
public void testCommand(@Nonnull final TestCommandSender sender,
|
||||
public void testCommand(final TestCommandSender sender,
|
||||
@Argument("int") @Range(max = "100") final int argument,
|
||||
@Nonnull @Argument(value = "string", defaultValue = "potato", parserName = "potato")
|
||||
@Argument(value = "string", defaultValue = "potato", parserName = "potato")
|
||||
final String string) {
|
||||
System.out.printf("Received int: %d and string '%s'\n", argument, string);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,23 +28,20 @@ import cloud.commandframework.execution.CommandExecutionCoordinator;
|
|||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class TestCommandManager extends CommandManager<TestCommandSender> {
|
||||
|
||||
protected TestCommandManager() {
|
||||
super(CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final SimpleCommandMeta createDefaultCommandMeta() {
|
||||
return SimpleCommandMeta.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasPermission(@Nonnull final TestCommandSender sender,
|
||||
@Nonnull final String permission) {
|
||||
public final boolean hasPermission(final TestCommandSender sender,
|
||||
final String permission) {
|
||||
return !permission.equalsIgnoreCase("no");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue