File tree 2 files changed +17
-8
lines changed
src/main/java/io/github/hedgehog1029/frame/dispatcher
2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 1
1
package io .github .hedgehog1029 .frame .dispatcher .bindings ;
2
2
3
- import io .github .hedgehog1029 .frame .annotation .Text ;
4
3
import io .github .hedgehog1029 .frame .dispatcher .arguments .CommandArgumentsDeque ;
5
4
import io .github .hedgehog1029 .frame .dispatcher .exception .DispatcherException ;
6
5
import io .github .hedgehog1029 .frame .dispatcher .exception .NotEnoughArgumentsException ;
@@ -81,17 +80,11 @@ public List<ExecutionPlan> getExecutionPlans() {
81
80
int i = 0 ;
82
81
while (arity > 0 ) {
83
82
ParameterWrapper pw = visibleParams .get (i ++);
84
- boolean isGreedy = pw .isAnnotationPresent (Text .class );
85
83
86
84
for (int n = 0 ; n < pw .getWillConsume (); n ++) {
87
85
String name = pw .getName () + (n == 0 ? "" : n );
88
86
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 ));
95
88
}
96
89
97
90
arity -= pw .getWillConsume ();
Original file line number Diff line number Diff line change 1
1
package io .github .hedgehog1029 .frame .dispatcher .provider ;
2
2
3
+ import io .github .hedgehog1029 .frame .annotation .Text ;
3
4
import io .github .hedgehog1029 .frame .dispatcher .arguments .ICommandArguments ;
4
5
import io .github .hedgehog1029 .frame .dispatcher .exception .DispatcherException ;
6
+ import io .github .hedgehog1029 .frame .dispatcher .pipeline .ArgumentNode ;
5
7
import io .github .hedgehog1029 .frame .module .wrappers .ParameterWrapper ;
6
8
import io .github .hedgehog1029 .frame .util .Namespace ;
7
9
@@ -18,4 +20,18 @@ public interface Provider<T> {
18
20
19
21
List <String > getSuggestions (int index , String partial , Namespace namespace );
20
22
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
+ }
21
37
}
You can’t perform that action at this time.
0 commit comments