Class BaseCommandGenerator
java.lang.Object
io.github.projectunified.craftcommand.processor.generator.BaseCommandGenerator
- All Implemented Interfaces:
CommandGenerator
- Direct Known Subclasses:
BukkitCommandGenerator,PaperCommandGenerator,StandaloneCommandGenerator
Base generator shared by every platform.
A platform only supplies its entry points and platform types; routing, parameter resolution and suggestions
live here. The generator reads CommandModels only and never parses annotations, so a new platform does
not need to know how the parser works.
To add a platform, extend this class, implement generateEntryMethods(com.palantir.javapoet.TypeSpec.Builder, io.github.projectunified.craftcommand.processor.model.CommandModel), getWrapperClassSuffix(),
getSenderTypeName(), and getManagerType(), then return it from
CommandGeneratorFactory.create(javax.annotation.processing.ProcessingEnvironment).
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseCommandGenerator(ProcessingEnvironment processingEnvironment) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConstructorStatements(com.palantir.javapoet.MethodSpec.Builder constructorBuilder, CommandModel model) Adds platform-specific constructor statements before the instance and manager are assigned.protected static booleananyMethod(CommandModel model, Predicate<ExecutableElement> predicate) Traverses the methods of a command tree.protected com.palantir.javapoet.CodeBlockprotected voidbuildCommandInfo(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) protected voidbuildSenderCastHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates the sender cast helpers needed by a command class.protected voidbuildSuggestionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model, String argsVar, CommandModel rootModel) Generates tab completion routing for a command class, delegating to the suggestion generator.protected voidbuildTypeSuggestionHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates the suggestion helpers of type-driven suggestions (boolean / platform built-ins).static com.palantir.javapoet.CodeBlockBuilds an instance method invocation, for exampleinstance.resolve(sender, arg).protected voidconfigureClass(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Configures the generated class declaration (superclass, interfaces).booleanfirstParamIsSender(ExecutableElement method) booleanfirstParamIsSender(ExecutableElement resolverMethod, MethodModel commandMethod) voidgenerate(CommandModel model) Writes the wrapper class of the given command model.protected abstract voidgenerateEntryMethods(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Adds the platform entry points (execute,tabComplete,getCommandNode, ...).voidgenerateExecuteMethodBody(com.palantir.javapoet.MethodSpec.Builder executeSpec, CommandModel model, String returnStatement) protected voidgenerateHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates the execution and suggestion routing plus the sender helpers of the whole command tree.protected voidgeneratePlatformHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Adds platform helper methods referenced from parameter types or entry points.voidgenerateResolverInvocation(com.palantir.javapoet.MethodSpec.Builder methodSpec, MethodModel resolverModel, CommandModel rootModel, com.palantir.javapoet.TypeName pTypeName, String varName, com.palantir.javapoet.CodeBlock senderExpr, List<String> resolverArgVarNames, boolean includeSender) Emits the call to a resolver method that produces a parameter value.voidgenerateSenderResolution(com.palantir.javapoet.MethodSpec.Builder spec, CommandModel rootModel, ParameterModel senderParam, com.palantir.javapoet.TypeName senderType, String senderVar) Emits the resolution of the command sender: a named@Resolvemethod, a registered sender resolver, or a platform cast.protected voidgenerateSubcommandClassExecutors(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, CommandModel rootModel) protected voidgenerateSubcommandFieldsAndConstructors(CommandModel model, com.palantir.javapoet.TypeSpec.Builder typeSpec, com.palantir.javapoet.MethodSpec.Builder constructor, String parentFieldName) protected voidgenerateUnknownSubcommandMessage(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model) Emits the message shown when a command without arguments has no default action.intgetBuiltInWidth(com.palantir.javapoet.TypeName typeName) getInstanceVarExpression(CommandModel classModel, CommandModel rootModel) intgetLocalResolverMaxWidth(MethodModel resolverModel, MethodModel commandMethod) intgetLocalResolverMinWidth(MethodModel resolverModel, MethodModel commandMethod) protected abstract com.palantir.javapoet.TypeNameTheCommandManagertype, including its sender type argument.protected StringgetParameterSuggestionMethodName(CommandModel classModel, MethodModel method, int index) getResolverInstanceExpr(MethodModel resolver, CommandModel rootModel) protected StringgetResolverParamSuggestionMethodName(CommandModel classModel, ParameterModel parameter) com.palantir.javapoet.CodeBlockgetResolverSenderExpression(ExecutableElement localResolver, String rawSourceExpr, String castSenderVar, com.palantir.javapoet.TypeName commandSenderType) protected com.palantir.javapoet.CodeBlockgetSenderExpression(String senderVar) Wraps the raw sender variable in the platform expression that yields the sender object.abstract com.palantir.javapoet.ClassNameThe platform's native sender type.protected Stringprotected static StringgetSubcommandNames(CommandModel model) protected abstract StringThe suffix appended to the command class name, for example"$BukkitCommand".protected static Stringprotected static booleanbooleanisSenderBaseType(com.palantir.javapoet.TypeName typeName) booleanisSenderParam(com.palantir.javapoet.TypeName typeName, MethodModel method) booleanisSenderType(com.palantir.javapoet.TypeName typeName) protected voidonBeforeExecute(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element, String returnStatement) Runs before a command method is executed, for example a permission check.voidrunParameterAnnotationHandlers(ParameterModel param, String varName, String instanceExpr, String senderVar, com.palantir.javapoet.MethodSpec.Builder methodSpec) Runs the SPI parameter handlers of a resolved parameter.protected SenderTypeRegistry
-
Field Details
-
PERMISSION_KEY
- See Also:
-
DEFAULT_PERMISSION_MESSAGE
- See Also:
-
-
Constructor Details
-
BaseCommandGenerator
-
-
Method Details
-
generate
Description copied from interface:CommandGeneratorWrites the wrapper class of the given command model.- Specified by:
generatein interfaceCommandGenerator- Parameters:
model- the parsed command tree- Throws:
IOException- when the source file cannot be written
-
getWrapperClassSuffix
The suffix appended to the command class name, for example"$BukkitCommand". -
getSenderTypeName
public abstract com.palantir.javapoet.ClassName getSenderTypeName()The platform's native sender type. -
getManagerType
protected abstract com.palantir.javapoet.TypeName getManagerType()TheCommandManagertype, including its sender type argument. -
configureClass
Configures the generated class declaration (superclass, interfaces). -
addConstructorStatements
protected void addConstructorStatements(com.palantir.javapoet.MethodSpec.Builder constructorBuilder, CommandModel model) Adds platform-specific constructor statements before the instance and manager are assigned. -
generateEntryMethods
protected abstract void generateEntryMethods(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Adds the platform entry points (execute,tabComplete,getCommandNode, ...). -
generatePlatformHelpers
protected void generatePlatformHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Adds platform helper methods referenced from parameter types or entry points. -
onBeforeExecute
protected void onBeforeExecute(com.palantir.javapoet.MethodSpec.Builder methodSpec, Element element, String returnStatement) Runs before a command method is executed, for example a permission check. -
generateUnknownSubcommandMessage
protected void generateUnknownSubcommandMessage(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model) Emits the message shown when a command without arguments has no default action. -
getSenderExpression
Wraps the raw sender variable in the platform expression that yields the sender object. -
generateHelpers
Generates the execution and suggestion routing plus the sender helpers of the whole command tree. -
generateSubcommandFieldsAndConstructors
protected void generateSubcommandFieldsAndConstructors(CommandModel model, com.palantir.javapoet.TypeSpec.Builder typeSpec, com.palantir.javapoet.MethodSpec.Builder constructor, String parentFieldName) -
getSubcommandFieldName
-
getInstanceVarExpression
-
getResolverInstanceExpr
-
generateSenderResolution
public void generateSenderResolution(com.palantir.javapoet.MethodSpec.Builder spec, CommandModel rootModel, ParameterModel senderParam, com.palantir.javapoet.TypeName senderType, String senderVar) Emits the resolution of the command sender: a named@Resolvemethod, a registered sender resolver, or a platform cast. -
generateExecuteMethodBody
public void generateExecuteMethodBody(com.palantir.javapoet.MethodSpec.Builder executeSpec, CommandModel model, String returnStatement) -
generateSubcommandClassExecutors
protected void generateSubcommandClassExecutors(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model, CommandModel rootModel) -
buildSuggestionRouting
protected void buildSuggestionRouting(com.palantir.javapoet.MethodSpec.Builder methodSpec, CommandModel model, String argsVar, CommandModel rootModel) Generates tab completion routing for a command class, delegating to the suggestion generator. -
buildSenderCastHelpers
protected void buildSenderCastHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates the sender cast helpers needed by a command class. -
buildTypeSuggestionHelpers
protected void buildTypeSuggestionHelpers(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) Generates the suggestion helpers of type-driven suggestions (boolean / platform built-ins). Platforms that inline custom providers call this from their helper step. -
getParameterSuggestionMethodName
protected String getParameterSuggestionMethodName(CommandModel classModel, MethodModel method, int index) -
getResolverParamSuggestionMethodName
protected String getResolverParamSuggestionMethodName(CommandModel classModel, ParameterModel parameter) -
buildCommandInfo
protected void buildCommandInfo(com.palantir.javapoet.TypeSpec.Builder typeSpec, CommandModel model) -
typeSupport
-
getBuiltInWidth
public int getBuiltInWidth(com.palantir.javapoet.TypeName typeName) -
isSenderType
public boolean isSenderType(com.palantir.javapoet.TypeName typeName) -
isSenderBaseType
public boolean isSenderBaseType(com.palantir.javapoet.TypeName typeName) -
isSenderParam
-
senderTypeRegistry
-
firstParamIsSender
-
firstParamIsSender
-
getLocalResolverMinWidth
-
getLocalResolverMaxWidth
-
getResolverSenderExpression
public com.palantir.javapoet.CodeBlock getResolverSenderExpression(ExecutableElement localResolver, String rawSourceExpr, String castSenderVar, com.palantir.javapoet.TypeName commandSenderType) -
buildAliasesExpression
-
anyMethod
Traverses the methods of a command tree. -
call
public static com.palantir.javapoet.CodeBlock call(String instance, String method, com.palantir.javapoet.CodeBlock... args) Builds an instance method invocation, for exampleinstance.resolve(sender, arg). -
getSubcommandNames
-
isI18nKey
-
i18nKey
-
runParameterAnnotationHandlers
public void runParameterAnnotationHandlers(ParameterModel param, String varName, String instanceExpr, String senderVar, com.palantir.javapoet.MethodSpec.Builder methodSpec) Runs the SPI parameter handlers of a resolved parameter. -
generateResolverInvocation
public void generateResolverInvocation(com.palantir.javapoet.MethodSpec.Builder methodSpec, MethodModel resolverModel, CommandModel rootModel, com.palantir.javapoet.TypeName pTypeName, String varName, com.palantir.javapoet.CodeBlock senderExpr, List<String> resolverArgVarNames, boolean includeSender) Emits the call to a resolver method that produces a parameter value.
-