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
Re-structured, highly readable base class for command annotation processors.
Supports custom validation annotations, parameter resolvers, deep subcommand nesting, and compiler extensions via SPI.
-
Field Summary
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildAdditionalHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates additional platform-independent helper methods (like suggestBoolean and sender casting helpers).protected com.palantir.javapoet.CodeBlockprotected voidbuildBuiltInParameter(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) protected abstract voidbuildEntryMethods(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, TypeElement typeElement) Generates platform-specific main wrapper entry methods (e.g. onCommand or execute).protected voidbuildExecutionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model, String argsVar, String instanceVar, CommandModel rootModel, String returnStatement) protected voidbuildLocalResolverParameter(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) protected voidbuildMethodExecution(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, String instanceVar, CommandModel rootModel, ExecutionSource source) protected voidbuildMethodExecution(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, String argsVar, String instanceVar, CommandModel rootModel) protected com.palantir.javapoet.MethodSpecbuildParameterSuggestionHelper(CommandModel classModel, MethodModel method, ParameterModel p, int index, CommandModel rootModel) protected voidbuildParameterSuggestions(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, CommandModel rootModel) protected voidbuildSenderResolution(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, CommandModel rootModel, String senderVarName, ParameterModel senderParam, com.palantir.javapoet.TypeName senderParamTypeName) protected voidbuildSubcommandSuggestionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel classModel, MethodModel method, String argsVar) protected voidbuildSuggestionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model, String argsVar, String instanceVar, CommandModel rootModel) protected voidbuildWrapperClass(CommandModel model, TypeElement typeElement) Generates the wrapper class for the command model using JavaPoet.protected voidconfigureConstructor(com.palantir.javapoet.MethodSpec.Builder constructorBuilder, CommandModel model) Configures the constructor for platform-specific statements (e.g., registering command).protected abstract voidconfigureSuperType(com.palantir.javapoet.TypeSpec.Builder typeSpec) Configures the super interfaces/classes that the generated wrapper should implement/extend.findLocalResolver(CommandModel classModel, ParameterModel p, CommandModel rootModel) findModelForClass(CommandModel current, TypeElement targetClass) protected ExecutableElementfindSuggestMethod(TypeElement typeElement, String name) booleanfirstParamIsSender(ExecutableElement method) protected voidgenerateDefaultSenderCastForSuggestion(com.palantir.javapoet.MethodSpec.Builder methodSpec) Helper statement generator to cast general Object sender to platform-specific sender.protected voidgenerateExecuteMethodBody(com.palantir.javapoet.MethodSpec.Builder executeSpec, CommandModel model, String returnStatement) protected voidgenerateFieldsAndConstructorStatements(CommandModel model, com.palantir.javapoet.TypeSpec.Builder typeSpec, com.palantir.javapoet.MethodSpec.Builder constructor, String parentFieldName) protected StringgenerateLocalResolverInvocation(ExecutableElement resolverMethod, String instanceExpr, String senderVar, String argsVar, String currentVar) protected voidgeneratePlatformParamSuggestions(com.palantir.javapoet.MethodSpec.Builder methodSpec, com.palantir.javapoet.TypeName typeName, String senderCastVar, String argsVar, String currentVar, int tempIdx) protected voidgenerateSubcommandClassExecutors(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, CommandModel rootModel) protected voidgenerateUnknownSubcommandMessage(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model) Generates statements to handle cases where an unknown subcommand is typed.com.palantir.javapoet.CodeBlockgetAssignmentValueForType(com.palantir.javapoet.TypeName typeName, String defaultValue) static StringUtility method to get the default literal value expression for a primitive type.protected Set<com.palantir.javapoet.TypeName> Recursively retrieves all unique custom parameter types requiring dynamic/global resolvers across the entire command hierarchy (main class, nested subcommand classes, and methods).getInstanceVarExpression(CommandModel classModel, CommandModel rootModel) protected intgetLocalResolverMaxWidth(ExecutableElement resolverMethod) protected intgetLocalResolverMinWidth(ExecutableElement resolverMethod) protected abstract com.palantir.javapoet.TypeNameReturns the platform-specific command manager type.protected StringgetParameterSuggestionMethodName(CommandModel classModel, MethodModel method, int index) protected intgetPlatformBuiltInWidth(com.palantir.javapoet.TypeName typeName) getResolverMethodName(com.palantir.javapoet.TypeName typeName) Constructs a unique, valid Java helper method name for resolving a given type.protected com.palantir.javapoet.CodeBlockgetSenderExpression(String senderVar) protected abstract com.palantir.javapoet.ClassNameReturns the platform-specific command sender type name (e.g.static StringgetSimpleName(com.palantir.javapoet.TypeName typeName) Utility method to get the simple name of a type.protected Stringprotected static StringgetSubcommandNames(CommandModel model) Utility method to format a list of all subcommand names defined in a command model.protected static StringgetUsage(MethodModel method) Utility method to build the command usage syntax string for a command method.protected abstract StringReturns the wrapper class suffix specific to the platform.voidinit(ProcessingEnvironment processingEnv) booleanisBuiltInType(com.palantir.javapoet.TypeName typeName) protected booleanisField(TypeElement typeElement, String name) protected booleanisPlatformBuiltInType(com.palantir.javapoet.TypeName typeName) protected booleanisSenderBaseType(com.palantir.javapoet.TypeName typeName) protected booleanisSenderType(com.palantir.javapoet.TypeName typeName) Checks if the sender type is supportedprotected voidonBeforeExecute(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element, String returnStatement) Hook run prior to execution routing of a subcommand or command method.protected voidonBeforeSuggest(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element) Hook run before tab-completion routing of a subcommand or method.protected voidonSuggestionAdd(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element, Runnable addSuggestions) Hook to decide if a subcommand/method should be suggested during tab-completion.booleanprocess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Main entry point for the compiler annotation processing round.protected voidresolvePlatformMultiParameter(com.palantir.javapoet.MethodSpec.Builder methodSpec, com.palantir.javapoet.TypeName typeName, String varName, String argsVar, String argIdxVar, String senderVar, int i) protected voidresolvePlatformParameter(com.palantir.javapoet.MethodSpec.Builder methodSpec, com.palantir.javapoet.TypeName typeName, String varName, String argStrVar) Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, isInitialized
-
Constructor Details
-
BaseCommandProcessor
public BaseCommandProcessor()
-
-
Method Details
-
getSimpleName
Utility method to get the simple name of a type.- Parameters:
typeName- the full type name- Returns:
- the simple type name
-
getDefaultPrimitiveValue
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
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
Utility method to build the command usage syntax string for a command method.- Parameters:
method- the method model- Returns:
- the usage string
-
init
- Specified by:
initin interfaceProcessor- Overrides:
initin classAbstractProcessor
-
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
Main entry point for the compiler annotation processing round. Searches for types annotated with@Command, parses their structure, and generates the wrappers.- Specified by:
processin interfaceProcessor- Specified by:
processin classAbstractProcessor
-
buildWrapperClass
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
-
generateExecuteMethodBody
protected void generateExecuteMethodBody(com.palantir.javapoet.MethodSpec.Builder executeSpec, CommandModel model, String returnStatement) -
getSubcommandFieldName
-
getInstanceVarExpression
-
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
-
getLocalResolverMaxWidth
-
firstParamIsSender
-
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
-
findSuggestMethod
-
isField
-
findModelForClass
-
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
-
resolvePlatformMultiParameter
-
generatePlatformParamSuggestions
-
getResolverMethodName
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
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
-
buildAdditionalHelpers
protected void buildAdditionalHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates additional platform-independent helper methods (like suggestBoolean and sender casting helpers).
-