Skip to content

Commit a8c5e9f

Browse files
committed
Add support for custom argument node types
1 parent b2728f2 commit a8c5e9f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/main/java/io/github/hedgehog1029/frame/dispatcher/bindings/BoundMethod.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.hedgehog1029.frame.dispatcher.bindings;
22

3-
import io.github.hedgehog1029.frame.annotation.Text;
43
import io.github.hedgehog1029.frame.dispatcher.arguments.CommandArgumentsDeque;
54
import io.github.hedgehog1029.frame.dispatcher.exception.DispatcherException;
65
import io.github.hedgehog1029.frame.dispatcher.exception.NotEnoughArgumentsException;
@@ -81,17 +80,11 @@ public List<ExecutionPlan> getExecutionPlans() {
8180
int i = 0;
8281
while (arity > 0) {
8382
ParameterWrapper pw = visibleParams.get(i++);
84-
boolean isGreedy = pw.isAnnotationPresent(Text.class);
8583

8684
for (int n = 0; n < pw.getWillConsume(); n++) {
8785
String name = pw.getName() + (n == 0 ? "" : n);
8886

89-
if (isGreedy) {
90-
nodes.add(new ArgumentNode.GreedyString(name));
91-
// do we assert that getWillConsume() == 1 here?
92-
} else {
93-
nodes.add(new ArgumentNode.SingleString(name));
94-
}
87+
nodes.add(pw.getProvider().makeNode(name, pw));
9588
}
9689

9790
arity -= pw.getWillConsume();

src/main/java/io/github/hedgehog1029/frame/dispatcher/provider/Provider.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.github.hedgehog1029.frame.dispatcher.provider;
22

3+
import io.github.hedgehog1029.frame.annotation.Text;
34
import io.github.hedgehog1029.frame.dispatcher.arguments.ICommandArguments;
45
import io.github.hedgehog1029.frame.dispatcher.exception.DispatcherException;
6+
import io.github.hedgehog1029.frame.dispatcher.pipeline.ArgumentNode;
57
import io.github.hedgehog1029.frame.module.wrappers.ParameterWrapper;
68
import io.github.hedgehog1029.frame.util.Namespace;
79

@@ -18,4 +20,18 @@ public interface Provider<T> {
1820

1921
List<String> getSuggestions(int index, String partial, Namespace namespace);
2022
int argsWanted(ParameterWrapper param);
23+
24+
/**
25+
* Called when the execution planner wants an argument node.
26+
* @param name Name to use for this argument. Use this rather than {@link ParameterWrapper#getName}!
27+
* @param param Parameter this is operating on
28+
* @return An argument node for this parameter, used by implementors for hinting
29+
*/
30+
default ArgumentNode makeNode(String name, ParameterWrapper param) {
31+
if (param.isAnnotationPresent(Text.class)) {
32+
return new ArgumentNode.GreedyString(name);
33+
} else {
34+
return new ArgumentNode.SingleString(name);
35+
}
36+
}
2137
}

0 commit comments

Comments
 (0)