forked from Revxrsal/Lamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoCompleter.java
165 lines (149 loc) · 6.62 KB
/
AutoCompleter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* This file is part of lamp, licensed under the MIT License.
*
* Copysecond (c) Revxrsal <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the seconds
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copysecond notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package revxrsal.commands.autocomplete;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.CommandHandler;
import revxrsal.commands.annotation.AutoComplete;
import revxrsal.commands.command.ArgumentStack;
import revxrsal.commands.command.CommandActor;
import java.util.Collection;
import java.util.List;
/**
* Represents the handler for registering and providing auto-completion
* suggestions.
*/
public interface AutoCompleter {
/**
* Registers a {@link SuggestionProvider} for the specified ID, for use in commands
* through the {@link AutoComplete} annotation.
*
* @param providerID The tab suggestion id
* @param provider The provider for this suggestion
* @return This auto-completer
*/
AutoCompleter registerSuggestion(@NotNull String providerID, @NotNull SuggestionProvider provider);
/**
* Registers static completions for the specified ID, for use in commands
* through the {@link AutoComplete} annotation.
*
* @param providerID The tab suggestion id
* @param completions The static list of suggestion. These will be copied and
* will no longer be modifiable
* @return This auto-completer
*/
AutoCompleter registerSuggestion(@NotNull String providerID, @NotNull Collection<String> completions);
/**
* Registers static completions for the specified ID, for use in commands
* through the {@link AutoComplete} annotation.
*
* @param providerID The tab suggestion id
* @param completions The static list of suggestion. These will be copied and
* will no longer be modifiable
* @return This auto-completer
*/
AutoCompleter registerSuggestion(@NotNull String providerID, @NotNull String... completions);
/**
* Registers a {@link SuggestionProvider} for a specific parameter type. This way,
* if the parameter is requested in the command, it will automatically be tab-completed
* without having to be explicitly defined by an {@link AutoComplete}.
*
* @param parameterType The parameter type to complete
* @param provider The tab suggestion provider
* @return This auto-completer
*/
AutoCompleter registerParameterSuggestions(@NotNull Class<?> parameterType, @NotNull SuggestionProvider provider);
/**
* Registers a {@link SuggestionProvider} for a specific parameter type. This way,
* if the parameter is requested in the command, it will automatically be tab-completed
* without having to be explicitly defined by an {@link AutoComplete}.
*
* @param parameterType The parameter type to complete
* @param providerID The tab suggestion provider id. Must be registered with
* either {@link #registerSuggestion(String, SuggestionProvider)}
* or {@link #registerSuggestion(String, String...)}.
* @return This auto-completer
*/
AutoCompleter registerParameterSuggestions(@NotNull Class<?> parameterType, @NotNull String providerID);
/**
* Registers a {@link SuggestionProviderFactory} that creates suggestion providers
* dynamically for parameters. This allows for checking against custom annotations
* in parameters.
*
* @param factory Factory to register
* @return This auto-completer
*/
AutoCompleter registerSuggestionFactory(@NotNull SuggestionProviderFactory factory);
/**
* Registers a {@link SuggestionProviderFactory} that creates suggestion providers
* dynamically for parameters. This allows for checking against custom annotations
* in parameters.
*
* @param priority The resolver priority. Zero represents the highest.
* @param factory Factory to register
* @return This auto-completer
*/
AutoCompleter registerSuggestionFactory(int priority, @NotNull SuggestionProviderFactory factory);
/**
* Returns the suggestion provider that maps to the specified ID.
* <p>
* This may return null if no such ID is registered.
*
* @param id ID to retrieve from
* @return The provider, or null if none is registered
*/
SuggestionProvider getSuggestionProvider(@NotNull String id);
/**
* Generates a list of suggestions for the given actor and argument list
*
* @param actor Actor to generate for
* @param arguments The argument stack. This can contain empty values.
* @return The suggestions list.
*/
List<String> complete(@NotNull CommandActor actor, @NotNull ArgumentStack arguments);
/**
* Generates a list of suggestions for the given actor and buffer
*
* @param actor Actor to generate for
* @param buffer The current string input
* @return The suggestions list.
*/
List<String> complete(@NotNull CommandActor actor, @NotNull String buffer);
/**
* Sets whether should this auto-completer filter suggestions
* to include only the closest suggestions to the user input.
* <p>
* By default, this is true.
*
* @param filterToClosestInput Whether should suggestions be
* filtered to the closest input
*/
void filterToClosestInput(boolean filterToClosestInput);
/**
* Returns the containing {@link CommandHandler} of this auto completer.
* This will allow for writing fluent and readable code.
*
* @return The parent command handler
*/
CommandHandler and();
}