Class MethodInvocationCompleter
java.lang.Object
com.ultikits.ultitools.commands.tabcomplete.MethodInvocationCompleter
- All Implemented Interfaces:
TabCompleter
Completer that invokes suggestion methods annotated with @CmdSuggest.
- Since:
- 6.2.0
- Version:
- 1.0.0
- Author:
- wisdomme
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumThe signature shapesinvokeSuggestMethod(TabCompletionContext, Method)knows how to invoke a@CmdParam.suggest()method-name target with. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static MethodInvocationCompleter.SuggestSignatureShapeclassifyPlayerAndStringShape(Class<?>[] paramTypes) private static MethodInvocationCompleter.SuggestSignatureShapeclassifyPlayerCommandArgsShape(Class<?>[] paramTypes) private static MethodInvocationCompleter.SuggestSignatureShapeclassifySingleParamShape(Class<?> paramType) private static MethodInvocationCompleter.SuggestSignatureShapeclassifySuggestSignature(Class<?>[] paramTypes) ClassifiesparamTypesinto the signature shapeinvokeSuggestMethod(TabCompletionContext, Method)dispatches on.complete(TabCompletionContext context) Generates completion suggestions based on the given context.private static Method[]findMethodsByName(Class<?> clazz, String methodName) Finds methods by name in a class.static Method[]getSuggestMethodsByName(Object executor, String suggestName) Gets suggest methods by name from the executor class or @CmdSuggest classes.private StringgetSuggestName(Method method, String paramName) Gets the suggest method name for a parameter.invokeSuggestMethod(TabCompletionContext context, Method suggestMethod) Invokes the suggest method and returns the results.static booleanisInvocableSuggestSignature(Class<?>[] paramTypes) WhetherinvokeSuggestMethod(TabCompletionContext, Method)can invoke a method with exactlyparamTypes.
-
Field Details
-
logger
-
-
Constructor Details
-
MethodInvocationCompleter
public MethodInvocationCompleter()
-
-
Method Details
-
complete
Description copied from interface:TabCompleterGenerates completion suggestions based on the given context.- Specified by:
completein interfaceTabCompleter- Parameters:
context- the tab completion context containing command state- Returns:
- list of suggestions, never null
-
getSuggestName
Gets the suggest method name for a parameter. -
getSuggestMethodsByName
Gets suggest methods by name from the executor class or @CmdSuggest classes.public static(notprivate) soPluginManager's load-time contract validation (T-05-fix Part 2) can resolve exactly the method this completer would invoke at completion time -- own class first, then@CmdSuggest-referenced classes -- without a second, independently-maintained lookup implementation. Neither this method norfindMethodsByName(Class, String)reads instance state, so both arestatic.- Parameters:
executor- the executor instance whose class (and@CmdSuggest-referenced classes) is searchedsuggestName- the@CmdParam.suggest()value, a plain method name (with or without a trailing"()")- Returns:
- the matching methods, or
nullif none found
-
findMethodsByName
Finds methods by name in a class. -
invokeSuggestMethod
Invokes the suggest method and returns the results. -
classifySuggestSignature
private static MethodInvocationCompleter.SuggestSignatureShape classifySuggestSignature(Class<?>[] paramTypes) ClassifiesparamTypesinto the signature shapeinvokeSuggestMethod(TabCompletionContext, Method)dispatches on. This is the SINGLE decision point both invocation and load-time validation (viaisInvocableSuggestSignature(Class[])) consult -- there is deliberately no second, independently-maintained list of "which signatures are supported" for the two to drift out of sync (T-05-fix Part 1 + Part 2).- Parameters:
paramTypes- the candidate suggest method's parameter types- Returns:
- the matching shape, or
MethodInvocationCompleter.SuggestSignatureShape.UNSUPPORTEDif none match
-
classifySingleParamShape
private static MethodInvocationCompleter.SuggestSignatureShape classifySingleParamShape(Class<?> paramType) -
classifyPlayerAndStringShape
private static MethodInvocationCompleter.SuggestSignatureShape classifyPlayerAndStringShape(Class<?>[] paramTypes) -
classifyPlayerCommandArgsShape
private static MethodInvocationCompleter.SuggestSignatureShape classifyPlayerCommandArgsShape(Class<?>[] paramTypes) -
isInvocableSuggestSignature
WhetherinvokeSuggestMethod(TabCompletionContext, Method)can invoke a method with exactlyparamTypes. Exposed soPluginManager's load-time contract check (T-05-fix Part 2) can refuse a module whose@CmdParam.suggest()method-name value resolves to a signature this completer cannot call -- naming the class, the mapping method and the offending signature at load time, rather than invoking it with the wrong arity the first time a player presses Tab.- Parameters:
paramTypes- the candidate suggest method's parameter types- Returns:
trueif this completer knows how to invoke a method with this exact parameter list
-