Add parameter injectors (#104)

This commit is contained in:
Alexander Söderberg 2020-10-25 05:45:38 +01:00
parent e4efffe577
commit c2065aabd1
11 changed files with 469 additions and 17 deletions

View file

@ -61,6 +61,11 @@ class AnnotationParserTest {
"some-name",
(context, input) -> NAMED_SUGGESTIONS
);
/* Register a parameter injector */
annotationParser.getParameterInjectorRegistry().registerInjector(
InjectableValue.class,
(context, annotations) -> new InjectableValue("Hello World!")
);
}
@Test
@ -109,6 +114,11 @@ class AnnotationParserTest {
final Regex regex = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod, Regex.class);
}
@Test
void testParameterInjection() {
manager.executeCommand(new TestCommandSender(), "inject").join();
}
@ProxiedBy("proxycommand")
@CommandMethod("test|t literal <int> [string]")
public void testCommand(
@ -136,6 +146,12 @@ class AnnotationParserTest {
) {
}
@CommandMethod("inject")
public void testInjectedParameters(
final InjectableValue injectableValue
) {
System.out.printf("Injected value: %s\n", injectableValue.toString());
}
@CommandPermission("some.permission")
@Target(ElementType.METHOD)
@ -169,4 +185,20 @@ class AnnotationParserTest {
private @interface Bad2 {
}
private static final class InjectableValue {
private final String value;
private InjectableValue(final String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
}
}