Class BaseCommandProcessor

java.lang.Object
javax.annotation.processing.AbstractProcessor
io.github.projectunified.craftcommand.processor.BaseCommandProcessor
All Implemented Interfaces:
Processor
Direct Known Subclasses:
BukkitCommandProcessor, PaperBasicCommandProcessor, PaperCommandProcessor, StandaloneCommandProcessor

public abstract class BaseCommandProcessor extends AbstractProcessor
Re-structured, highly readable base class for command annotation processors. Supports custom validation annotations, parameter resolvers, deep subcommand nesting, and compiler extensions via SPI.
  • Constructor Details

    • BaseCommandProcessor

      public BaseCommandProcessor()
  • Method Details

    • getSimpleName

      public static String getSimpleName(com.palantir.javapoet.TypeName typeName)
      Utility method to get the simple name of a type.
      Parameters:
      typeName - the full type name
      Returns:
      the simple type name
    • getDefaultPrimitiveValue

      public static String getDefaultPrimitiveValue(TypeMirror type)
      Utility method to get the default literal value expression for a primitive type.
      Parameters:
      type - the primitive type mirror
      Returns:
      the default value literal string
    • getSubcommandNames

      protected static String getSubcommandNames(CommandModel model)
      Utility method to format a list of all subcommand names defined in a command model.
      Parameters:
      model - the command model
      Returns:
      a formatted string of subcommand names
    • getUsage

      protected static String getUsage(MethodModel method)
      Utility method to build the command usage syntax string for a command method.
      Parameters:
      method - the method model
      Returns:
      the usage string
    • init

      public void init(ProcessingEnvironment processingEnv)
      Specified by:
      init in interface Processor
      Overrides:
      init in class AbstractProcessor
    • getWrapperClassSuffix

      protected abstract String getWrapperClassSuffix()
      Returns the wrapper class suffix specific to the platform.
      Returns:
      the class name suffix (e.g. "_Executor" or "_Standalone")
    • configureSuperType

      protected abstract void configureSuperType(com.palantir.javapoet.TypeSpec.Builder typeSpec)
      Configures the super interfaces/classes that the generated wrapper should implement/extend.
      Parameters:
      typeSpec - the class definition builder
    • getSenderTypeName

      protected abstract com.palantir.javapoet.ClassName getSenderTypeName()
      Returns the platform-specific command sender type name (e.g. Bukkit CommandSender or Object).
    • getManagerType

      protected abstract com.palantir.javapoet.TypeName getManagerType()
      Returns the platform-specific command manager type.
    • buildEntryMethods

      protected abstract void buildEntryMethods(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, TypeElement typeElement)
      Generates platform-specific main wrapper entry methods (e.g. onCommand or execute).
    • configureConstructor

      protected void configureConstructor(com.palantir.javapoet.MethodSpec.Builder constructorBuilder, CommandModel model)
      Configures the constructor for platform-specific statements (e.g., registering command).
    • onBeforeExecute

      protected void onBeforeExecute(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element, String returnStatement)
      Hook run prior to execution routing of a subcommand or command method.
    • generateUnknownSubcommandMessage

      protected void generateUnknownSubcommandMessage(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model)
      Generates statements to handle cases where an unknown subcommand is typed.
    • onSuggestionAdd

      protected void onSuggestionAdd(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element, Runnable addSuggestions)
      Hook to decide if a subcommand/method should be suggested during tab-completion.
    • onBeforeSuggest

      protected void onBeforeSuggest(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element)
      Hook run before tab-completion routing of a subcommand or method.
    • isSenderType

      protected boolean isSenderType(com.palantir.javapoet.TypeName typeName)
      Checks if the sender type is supported
    • isSenderBaseType

      protected boolean isSenderBaseType(com.palantir.javapoet.TypeName typeName)
    • generateDefaultSenderCastForSuggestion

      protected void generateDefaultSenderCastForSuggestion(com.palantir.javapoet.MethodSpec.Builder methodSpec)
      Helper statement generator to cast general Object sender to platform-specific sender.
    • process

      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
      Main entry point for the compiler annotation processing round. Searches for types annotated with @Command, parses their structure, and generates the wrappers.
      Specified by:
      process in interface Processor
      Specified by:
      process in class AbstractProcessor
    • buildWrapperClass

      protected void buildWrapperClass(CommandModel model, TypeElement typeElement) throws IOException
      Generates the wrapper class for the command model using JavaPoet. Setting up fields, constructor, entry routing methods, sub-executors, and custom resolvers.
      Throws:
      IOException
    • generateFieldsAndConstructorStatements

      protected void generateFieldsAndConstructorStatements(CommandModel model, com.palantir.javapoet.TypeSpec.Builder typeSpec, com.palantir.javapoet.MethodSpec.Builder constructor, String parentFieldName)
    • buildAliasesExpression

      protected com.palantir.javapoet.CodeBlock buildAliasesExpression(CommandModel model)
    • generateExecuteMethodBody

      protected void generateExecuteMethodBody(com.palantir.javapoet.MethodSpec.Builder executeSpec, CommandModel model, String returnStatement)
    • getSubcommandFieldName

      protected String getSubcommandFieldName(CommandModel child)
    • getInstanceVarExpression

      public String getInstanceVarExpression(CommandModel classModel, CommandModel rootModel)
    • getParameterSuggestionMethodName

      protected String getParameterSuggestionMethodName(CommandModel classModel, MethodModel method, int index)
    • generateSubcommandClassExecutors

      protected void generateSubcommandClassExecutors(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, CommandModel rootModel)
    • buildExecutionRouting

      protected void buildExecutionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model, String argsVar, String instanceVar, CommandModel rootModel, String returnStatement)
    • getLocalResolverMinWidth

      protected int getLocalResolverMinWidth(ExecutableElement resolverMethod)
    • getLocalResolverMaxWidth

      protected int getLocalResolverMaxWidth(ExecutableElement resolverMethod)
    • firstParamIsSender

      public boolean firstParamIsSender(ExecutableElement method)
    • getAssignmentValueForType

      public com.palantir.javapoet.CodeBlock getAssignmentValueForType(com.palantir.javapoet.TypeName typeName, String defaultValue)
    • buildMethodExecution

      protected void buildMethodExecution(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, String argsVar, String instanceVar, CommandModel rootModel)
    • buildMethodExecution

      protected void buildMethodExecution(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, String instanceVar, CommandModel rootModel, ExecutionSource source)
    • buildSenderResolution

      protected void buildSenderResolution(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, CommandModel rootModel, String senderVarName, ParameterModel senderParam, com.palantir.javapoet.TypeName senderParamTypeName)
    • buildLocalResolverParameter

      protected void buildLocalResolverParameter(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, ParameterModel p, com.palantir.javapoet.TypeName pTypeName, String varName, ExecutableElement localResolver, CommandModel rootModel, String senderVarName, String argsVar, String argIdxVar, boolean hasDynamic, int i)
    • buildBuiltInParameter

      protected void buildBuiltInParameter(com.palantir.javapoet.MethodSpec.Builder methodSpec, ParameterModel p, com.palantir.javapoet.TypeName pTypeName, String varName, String argsVar, String argIdxVar, String senderVarName, boolean hasDynamic, int i)
    • buildSuggestionRouting

      protected void buildSuggestionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model, String argsVar, String instanceVar, CommandModel rootModel)
    • buildSubcommandSuggestionRouting

      protected void buildSubcommandSuggestionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, String argsVar)
    • buildParameterSuggestions

      protected void buildParameterSuggestions(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, CommandModel rootModel)
    • buildParameterSuggestionHelper

      protected com.palantir.javapoet.MethodSpec buildParameterSuggestionHelper(CommandModel classModel, MethodModel method, ParameterModel p, int index, CommandModel rootModel)
    • findLocalResolver

      public ExecutableElement findLocalResolver(CommandModel classModel, ParameterModel p, CommandModel rootModel)
    • generateLocalResolverInvocation

      protected String generateLocalResolverInvocation(ExecutableElement resolverMethod, String instanceExpr, String senderVar, String argsVar, String currentVar)
    • findSuggestMethod

      protected ExecutableElement findSuggestMethod(TypeElement typeElement, String name)
    • isField

      protected boolean isField(TypeElement typeElement, String name)
    • findModelForClass

      public CommandModel findModelForClass(CommandModel current, TypeElement targetClass)
    • isBuiltInType

      public boolean isBuiltInType(com.palantir.javapoet.TypeName typeName)
    • isPlatformBuiltInType

      protected boolean isPlatformBuiltInType(com.palantir.javapoet.TypeName typeName)
    • getPlatformBuiltInWidth

      protected int getPlatformBuiltInWidth(com.palantir.javapoet.TypeName typeName)
    • resolvePlatformParameter

      protected void resolvePlatformParameter(com.palantir.javapoet.MethodSpec.Builder methodSpec, com.palantir.javapoet.TypeName typeName, String varName, String argStrVar)
    • resolvePlatformMultiParameter

      protected void resolvePlatformMultiParameter(com.palantir.javapoet.MethodSpec.Builder methodSpec, com.palantir.javapoet.TypeName typeName, String varName, String argsVar, String argIdxVar, String senderVar, int i)
    • generatePlatformParamSuggestions

      protected void generatePlatformParamSuggestions(com.palantir.javapoet.MethodSpec.Builder methodSpec, com.palantir.javapoet.TypeName typeName, String senderCastVar, String argsVar, String currentVar, int tempIdx)
    • getResolverMethodName

      public String getResolverMethodName(com.palantir.javapoet.TypeName typeName)
      Constructs a unique, valid Java helper method name for resolving a given type. Combines nested simple class names to ensure readability (e.g. TestCommand_TestEnum).
      Parameters:
      typeName - the parameter type name
      Returns:
      the resolver method name starting with "resolve_"
    • getDynamicResolverTypes

      protected Set<com.palantir.javapoet.TypeName> getDynamicResolverTypes(CommandModel model)
      Recursively retrieves all unique custom parameter types requiring dynamic/global resolvers across the entire command hierarchy (main class, nested subcommand classes, and methods).
      Parameters:
      model - the command model
      Returns:
      a set of unique TypeNames for the dynamic resolvers
    • getSenderExpression

      protected com.palantir.javapoet.CodeBlock getSenderExpression(String senderVar)
    • buildAdditionalHelpers

      protected void buildAdditionalHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model)
      Generates additional platform-independent helper methods (like suggestBoolean and sender casting helpers).