Class MethodInvocationCompleter

java.lang.Object
com.ultikits.ultitools.commands.tabcomplete.MethodInvocationCompleter
All Implemented Interfaces:
TabCompleter

public class MethodInvocationCompleter extends Object implements TabCompleter
Completer that invokes suggestion methods annotated with @CmdSuggest.
Since:
6.2.0
Version:
1.0.0
Author:
wisdomme
  • Field Details

    • logger

      private static final Logger logger
  • Constructor Details

    • MethodInvocationCompleter

      public MethodInvocationCompleter()
  • Method Details

    • complete

      public List<String> complete(TabCompletionContext context)
      Description copied from interface: TabCompleter
      Generates completion suggestions based on the given context.
      Specified by:
      complete in interface TabCompleter
      Parameters:
      context - the tab completion context containing command state
      Returns:
      list of suggestions, never null
    • getSuggestName

      private String getSuggestName(Method method, String paramName)
      Gets the suggest method name for a parameter.
    • getSuggestMethodsByName

      public static Method[] getSuggestMethodsByName(Object executor, String suggestName)
      Gets suggest methods by name from the executor class or @CmdSuggest classes.

      public static (not private) so PluginManager'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 nor findMethodsByName(Class, String) reads instance state, so both are static.

      Parameters:
      executor - the executor instance whose class (and @CmdSuggest-referenced classes) is searched
      suggestName - the @CmdParam.suggest() value, a plain method name (with or without a trailing "()")
      Returns:
      the matching methods, or null if none found
    • findMethodsByName

      private static Method[] findMethodsByName(Class<?> clazz, String methodName)
      Finds methods by name in a class.
    • invokeSuggestMethod

      private List<String> invokeSuggestMethod(TabCompletionContext context, Method suggestMethod)
      Invokes the suggest method and returns the results.
    • classifySuggestSignature

      private static MethodInvocationCompleter.SuggestSignatureShape classifySuggestSignature(Class<?>[] paramTypes)
      Classifies paramTypes into the signature shape invokeSuggestMethod(TabCompletionContext, Method) dispatches on. This is the SINGLE decision point both invocation and load-time validation (via isInvocableSuggestSignature(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.UNSUPPORTED if 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

      public static boolean isInvocableSuggestSignature(Class<?>[] paramTypes)
      Whether invokeSuggestMethod(TabCompletionContext, Method) can invoke a method with exactly paramTypes. Exposed so PluginManager'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:
      true if this completer knows how to invoke a method with this exact parameter list