Class ParameterModel
java.lang.Object
io.github.projectunified.craftcommand.processor.model.ParameterModel
Model representing a command method parameter.
All annotation-derived facts are resolved once at parse time: the resolver declared by
@Resolve and the suggestion provider declared by @Suggest are linked here, so
code generation never re-reads annotations from the parameter element.
-
Constructor Summary
ConstructorsConstructorDescriptionParameterModel(String name, TypeMirror type, boolean greedy, boolean optional, String defaultValue, String suggestProvider, String resolveName, MethodModel resolverMethod, MethodModel suggestMethod, VariableElement element) Constructs a ParameterModel. -
Method Summary
Modifier and TypeMethodDescriptionasOptional(String inheritedDefault) Creates an optional copy of this parameter using the default value of a parent parameter.Gets the default value string.Gets the underlying VariableElement.getName()Gets the parameter name.Gets the raw@Resolvevalue of this parameter.Gets the resolver method linked by a named@Resolve.Gets the suggest provider method linked by@Suggest.Gets the custom suggestion provider name.getType()Gets the Java TypeMirror of this parameter.booleanisGreedy()Checks if this parameter is greedy.booleanChecks if this parameter is optional.Creates a copy of this parameter using the Java identifier as its name.
-
Constructor Details
-
ParameterModel
public ParameterModel(String name, TypeMirror type, boolean greedy, boolean optional, String defaultValue, String suggestProvider, String resolveName, MethodModel resolverMethod, MethodModel suggestMethod, VariableElement element) Constructs a ParameterModel.- Parameters:
name- the parameter name (from@Nameor reflection)type- the Java type of the parametergreedy-trueif marked with@Greedyoptional-trueif marked with@DefaultdefaultValue- the default value string when optional, ornullsuggestProvider- the custom suggest provider name, ornullresolveName- the raw@Resolvevalue,nullwhen@Resolveis absent and empty when it is present without a resolver nameresolverMethod- the resolver method model referenced by a named@Resolve, ornullsuggestMethod- the suggest provider method model when@Suggestnames a valid method, ornullwhen absent, a field, or an invalid signatureelement- the underlying VariableElement
-
-
Method Details
-
getName
Gets the parameter name.- Returns:
- the parameter name
-
getType
Gets the Java TypeMirror of this parameter.- Returns:
- the parameter type
-
isGreedy
public boolean isGreedy()Checks if this parameter is greedy.- Returns:
trueif greedy
-
isOptional
public boolean isOptional()Checks if this parameter is optional.- Returns:
trueif optional
-
getDefaultValue
Gets the default value string.- Returns:
- the default value, or
null
-
getSuggestProvider
Gets the custom suggestion provider name.- Returns:
- the suggestion provider name, or
null
-
getResolveName
Gets the raw@Resolvevalue of this parameter.- Returns:
- the resolver name,
nullwhen@Resolveis absent, empty when present without a name
-
getResolverMethod
Gets the resolver method linked by a named@Resolve.- Returns:
- the resolver method model, or
nullwhen there is no named resolver
-
getSuggestMethod
Gets the suggest provider method linked by@Suggest.- Returns:
- the suggest method model, or
nullwhen there is none
-
getElement
Gets the underlying VariableElement.- Returns:
- the variable element
-
withName
Creates a copy of this parameter using the Java identifier as its name.Used when handing the parameter to SPI handlers, which report source-level parameter names.
- Parameters:
name- the replacement name- Returns:
- a parameter model with the given name
-
asOptional
Creates an optional copy of this parameter using the default value of a parent parameter.- Parameters:
inheritedDefault- the default value inherited from the parent parameter- Returns:
- a parameter model marked optional with the inherited default
-