Class DefaultBuilderCreatorProvider
java.lang.Object
io.helidon.builder.processor.tools.DefaultBuilderCreatorProvider
- All Implemented Interfaces:
BuilderCreatorProvider
Default implementation for
BuilderCreatorProvider.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendAnnotations(StringBuilder builder, List<AnnotationAndValue> annotations, String prefix) AppendAnnotatedannotations if any.protected voidappendBasicGetters(StringBuilder builder, BodyContext ctx) Adds the basic getters to the generated builder output.protected voidappendBuilderBuildPreSteps(StringBuilder builder, BodyContext ctx, String builderTag) Adds extra builder build() method pre-steps prior to the builder being built into the target.protected voidappendCtorCodeBody(StringBuilder builder, BodyContext ctx, String builderTag) Appends the constructor body.protected voidappendDirectNonOptionalSetter(StringBuilder builder, BodyContext ctx, String beanAttributeName, TypedElementName method, String methodName, TypeName genericType) Append the setters for the given bean attribute name.protected voidappendExtraBuilderFields(StringBuilder builder, BodyContext ctx) Adds extra builder methods.protected voidappendExtraBuilderMethods(StringBuilder builder, BodyContext ctx) Adds extra builder methods.protected voidappendExtraCtorCode(StringBuilder builder, BodyContext ctx, String builderTag) Adds extra default ctor code.protected voidappendExtraFields(StringBuilder builder, BodyContext ctx) Adds extra fields on the main generated class.protected voidappendExtraImports(StringBuilder builder, BodyContext ctx) Adds extra imports to the generated builder.protected voidappendExtraInnerClasses(StringBuilder builder, BodyContext ctx) Adds extra inner classes to write on the builder.protected voidappendExtraMethods(StringBuilder builder, BodyContext ctx) Adds extra methods to the generated builder.protected voidappendExtraPostCtorCode(StringBuilder builder, BodyContext ctx) Adds extra code following the ctor decl.protected voidappendExtraToBuilderBuilderFunctions(StringBuilder builder, BodyContext ctx, String decl) Adds extra toBuilder() methods.protected voidappendFields(StringBuilder builder, BodyContext ctx) Adds the fields part of the generated builder.protected voidappendFooter(StringBuilder builder, BodyContext ctx) Appends the footer of the generated class.protected voidappendHeader(StringBuilder builder, BodyContext ctx) Adds the header part of the generated builder.protected voidappendMetaAttributes(StringBuilder builder, BodyContext ctx) Appends meta attribute related methods.protected voidappendMetaProps(StringBuilder builder, BodyContext ctx, String tag, AtomicBoolean needsCustomMapOf) Adds extra meta properties to the generated code.protected voidappendRequiredVisitor(StringBuilder builder, BodyContext ctx, String builderTag) Appends the simpleConfiguredOption.required()validation inside the build() method.protected voidappendSetter(StringBuilder mainBuilder, BodyContext ctx, String beanAttributeName, String methodName, TypedElementName method) Append the setters for the given bean attribute name.protected voidappendToStringMethod(StringBuilder builder, BodyContext ctx) Generated the toString method on the generated builder.protected voidappendVisitAttributes(StringBuilder builder, BodyContext ctx, String extraTabs, boolean beanNameRef) Appends the visitAttributes() method on the generated class.Returns any extra 'extends' type name that should be on the main generated builder type at the base level.Returns any extra 'extends' type name that should be on the main generated type at the base level.create(TypeInfo typeInfo, AnnotationAndValue builderAnnotation) protected BodyContextcreateBodyContext(boolean doingConcreteType, TypeName typeName, TypeInfo typeInfo, AnnotationAndValue builderAnnotation) Creates the context for the class being built.Returns any extra 'implements' contract types that should be on the main generated builder type.Returns any extra 'implements' contract types that should be on the main generated type.protected StringReturns the "final" field modifier by default.protected StringReturns the copyright level header comment.protected StringReturns theGeneratedsticker to be added.protected StringReturns theGeneratedversion identifier.protected StringinstanceIdRef(BodyContext ctx) The nuanced instance id for theappendToStringMethod(StringBuilder, BodyContext).protected voidmaybeAppendInterceptor(StringBuilder builder, BodyContext ctx, String builderTag) Appends any interceptor on the builder.protected voidmaybeAppendSingularSetter(StringBuilder builder, BodyContext ctx, TypedElementName method, String beanAttributeName, boolean isList, boolean isMap, boolean isSet) Appends the singular setter methods on the builder.protected static StringmaybeSingularFormOf(String beanAttributeName) If the provided name ends in an "s" then this will return the base name with the s stripped off.protected static StringnameOf(TypedElementName elem) Attempts to use the singular name of the element, defaulting to the element name if no singular annotation exists.protected StringnormalizeConfiguredOptionKey(String key, String name, boolean isAttribute) Normalize the configured option key.protected booleanReturn true if the visitAttributes() methods is being overridden.protected List<TypeAndBody>postValidate(List<TypeAndBody> builds) Can be overridden to validate the result before it is returned to the framework.protected voidpreValidate(TypeName implTypeName, TypeInfo typeInfo, AnnotationAndValue builderAnnotation) Validates the integrity of the provided arguments in the context of what is being code generated.Set<Class<? extends Annotation>>protected TypeNametoAbstractImplTypeName(TypeName typeName, AnnotationAndValue builderAnnotation) Constructs the abstract implementation type name for what is code generated.protected StringtoBody(BodyContext ctx) Generates the body of the generated builder class.static TypeNametoBuilderImplTypeName(TypeName typeName, AnnotationAndValue builderAnnotation) Returns the default implementation Builder's class name for what is code generated.protected StringtoConfigKey(String name, boolean isAttribute) Applicable if this builder is intended for config beans.toConfiguredOptionValue(TypedElementName method, boolean wantTypeElementDefaults, boolean avoidBlanks) Extracts the value from the method, ignoringConfiguredOption.UNCONFIGURED.protected static StringtoGenerics(TypedElementName method, boolean upLevelToCollection) Produces the generic descriptor decl for the method.protected static StringtoGenerics(TypeName typeName, boolean upLevelToCollection) Produces the generic descriptor decl for the method.protected static StringtoString(Collection<?> coll) Walk the collection to build a separator-delimited string value.protected static <T> StringWalk the collection to build a separator-delimited string value.toValue(Class<? extends Annotation> annoType, TypedElementName method, boolean wantTypeElementDefaults, boolean avoidBlanks) Retrieves the default value of the method to a string value.
-
Constructor Details
-
DefaultBuilderCreatorProvider
Deprecated.Default constructor.
-
-
Method Details
-
supportedAnnotationTypes
- Specified by:
supportedAnnotationTypesin interfaceBuilderCreatorProvider
-
create
- Specified by:
createin interfaceBuilderCreatorProvider
-
preValidate
protected void preValidate(TypeName implTypeName, TypeInfo typeInfo, AnnotationAndValue builderAnnotation) Validates the integrity of the provided arguments in the context of what is being code generated.- Parameters:
implTypeName- the implementation type nametypeInfo- the type infobuilderAnnotation- the builder annotation triggering the code generation
-
postValidate
Can be overridden to validate the result before it is returned to the framework.- Parameters:
builds- the builds of the TypeAndBody that will be code generated by this creator- Returns:
- the validated list
-
toAbstractImplTypeName
Constructs the abstract implementation type name for what is code generated.- Parameters:
typeName- the target interface that the builder applies tobuilderAnnotation- the builder annotation triggering the build- Returns:
- the abstract type name of the implementation
-
toBuilderImplTypeName
public static TypeName toBuilderImplTypeName(TypeName typeName, AnnotationAndValue builderAnnotation) Returns the default implementation Builder's class name for what is code generated.- Parameters:
typeName- the target interface that the builder applies tobuilderAnnotation- the builder annotation triggering the build- Returns:
- the type name of the implementation
-
createBodyContext
protected BodyContext createBodyContext(boolean doingConcreteType, TypeName typeName, TypeInfo typeInfo, AnnotationAndValue builderAnnotation) Creates the context for the class being built.- Parameters:
doingConcreteType- true if the concrete type is being generated, otherwise the abstract classtypeName- the type name that will be code generatedtypeInfo- the type info describing the target interfacebuilderAnnotation- the builder annotation that triggered the builder being created- Returns:
- the context describing what is being built
-
toBody
Generates the body of the generated builder class.- Parameters:
ctx- the context for what is being built- Returns:
- the string representation of the class being built
-
maybeAppendInterceptor
Appends any interceptor on the builder.- Parameters:
builder- the builderctx- the contextbuilderTag- the tag (variable name) used for the builder arg
-
appendRequiredVisitor
Appends the simpleConfiguredOption.required()validation inside the build() method.- Parameters:
builder- the builderctx- the contextbuilderTag- the tag (variable name) used for the builder arg
-
appendBasicGetters
Adds the basic getters to the generated builder output.- Parameters:
builder- the builderctx- the context
-
appendMetaAttributes
Appends meta attribute related methods.- Parameters:
builder- the builderctx- the context
-
appendFields
Adds the fields part of the generated builder.- Parameters:
builder- the builderctx- the context
-
appendHeader
Adds the header part of the generated builder.- Parameters:
builder- the builderctx- the context
-
generatedCopyrightHeaderFor
Returns the copyright level header comment.- Parameters:
ctx- the context- Returns:
- the copyright level header
-
generatedStickerFor
Returns theGeneratedsticker to be added.- Parameters:
ctx- the context- Returns:
- the generated sticker
-
generatedVersionFor
Returns theGeneratedversion identifier.- Parameters:
ctx- the context- Returns:
- the generated version identifier
-
baseExtendsTypeName
Returns any extra 'extends' type name that should be on the main generated type at the base level.- Parameters:
ctx- the context- Returns:
- extra contracts implemented
-
baseExtendsBuilderTypeName
Returns any extra 'extends' type name that should be on the main generated builder type at the base level.- Parameters:
ctx- the context- Returns:
- extra contracts implemented
-
extraImplementedTypeNames
Returns any extra 'implements' contract types that should be on the main generated type.- Parameters:
ctx- the context- Returns:
- extra contracts implemented
-
extraImplementedBuilderContracts
Returns any extra 'implements' contract types that should be on the main generated builder type.- Parameters:
ctx- the context- Returns:
- extra contracts implemented
-
appendExtraImports
Adds extra imports to the generated builder.- Parameters:
builder- the builderctx- the context
-
appendToStringMethod
Generated the toString method on the generated builder.- Parameters:
builder- the builderctx- the context
-
instanceIdRef
The nuanced instance id for theappendToStringMethod(StringBuilder, BodyContext).- Parameters:
ctx- the context- Returns:
- the instance id
-
appendExtraMethods
Adds extra methods to the generated builder. This base implementation will generate the visitAttributes() for the main generated class.- Parameters:
builder- the builderctx- the context
-
appendExtraInnerClasses
Adds extra inner classes to write on the builder. This default implementation will write theAttributeVisitorandRequiredAttributeVisitorinner classes on the base abstract parent (ie, hasParent is false).- Parameters:
builder- the builderctx- the context
-
fieldModifier
Returns the "final" field modifier by default.- Returns:
- the field modifier
-
appendVisitAttributes
protected void appendVisitAttributes(StringBuilder builder, BodyContext ctx, String extraTabs, boolean beanNameRef) Appends the visitAttributes() method on the generated class.- Parameters:
builder- the builderctx- the contextextraTabs- spacingbeanNameRef- refer to bean name? otherwise refer to the element name
-
overridesVisitAttributes
Return true if the visitAttributes() methods is being overridden.- Parameters:
ctx- the context- Returns:
- true if overriding visitAttributes();
-
appendExtraCtorCode
Adds extra default ctor code.- Parameters:
builder- the builderctx- the contextbuilderTag- the tag (variable name) used for the builder arg
-
appendExtraPostCtorCode
Adds extra code following the ctor decl.- Parameters:
builder- the builderctx- the context
-
appendExtraFields
Adds extra fields on the main generated class.- Parameters:
builder- the builderctx- the context
-
appendExtraToBuilderBuilderFunctions
protected void appendExtraToBuilderBuilderFunctions(StringBuilder builder, BodyContext ctx, String decl) Adds extra toBuilder() methods.- Parameters:
builder- the builderctx- the contextdecl- the declaration template for the toBuilder method
-
appendExtraBuilderFields
Adds extra builder methods.- Parameters:
builder- the builderctx- the context
-
appendBuilderBuildPreSteps
protected void appendBuilderBuildPreSteps(StringBuilder builder, BodyContext ctx, String builderTag) Adds extra builder build() method pre-steps prior to the builder being built into the target.- Parameters:
builder- the builderctx- the contextbuilderTag- the tag (variable name) used for the builder arg
-
appendExtraBuilderMethods
Adds extra builder methods. This base implementation will write the visitAttributes() method on the generated builder class.- Parameters:
builder- the builderctx- the context
-
appendMetaProps
protected void appendMetaProps(StringBuilder builder, BodyContext ctx, String tag, AtomicBoolean needsCustomMapOf) Adds extra meta properties to the generated code.- Parameters:
builder- the builderctx- the contexttag- the tag used to represent the meta props variable on the generated codeneedsCustomMapOf- will be set to true if a custom map.of() function needs to be generated (i.e., if over 9 tuples)
-
normalizeConfiguredOptionKey
Normalize the configured option key.- Parameters:
key- the key attributename- the nameisAttribute- if the name represents an attribute value (otherwise is a config bean name)- Returns:
- the key to write on the generated output
-
toConfigKey
Applicable if this builder is intended for config beans.- Parameters:
name- the nameisAttribute- if the name represents an attribute value (otherwise is a config bean name)- Returns:
- the config key
-
maybeAppendSingularSetter
protected void maybeAppendSingularSetter(StringBuilder builder, BodyContext ctx, TypedElementName method, String beanAttributeName, boolean isList, boolean isMap, boolean isSet) Appends the singular setter methods on the builder.- Parameters:
builder- the builderctx- the contextmethod- the methodbeanAttributeName- the bean attribute nameisList- true if the output involves List typeisMap- true if the output involves Map typeisSet- true if the output involves Set type
-
maybeSingularFormOf
If the provided name ends in an "s" then this will return the base name with the s stripped off.- Parameters:
beanAttributeName- the name- Returns:
- the name stripped with any "s" suffix
-
nameOf
Attempts to use the singular name of the element, defaulting to the element name if no singular annotation exists.- Parameters:
elem- the element- Returns:
- the (singular) name of the element
-
appendSetter
protected void appendSetter(StringBuilder mainBuilder, BodyContext ctx, String beanAttributeName, String methodName, TypedElementName method) Append the setters for the given bean attribute name.- Parameters:
mainBuilder- the builderctx- the body contextbeanAttributeName- the bean attribute namemethodName- the method namemethod- the method
-
appendDirectNonOptionalSetter
protected void appendDirectNonOptionalSetter(StringBuilder builder, BodyContext ctx, String beanAttributeName, TypedElementName method, String methodName, TypeName genericType) Append the setters for the given bean attribute name.- Parameters:
builder- the builderctx- the body contextbeanAttributeName- the bean attribute namemethod- the methodmethodName- the method namegenericType- the generic return type name of the method
-
appendAnnotations
protected void appendAnnotations(StringBuilder builder, List<AnnotationAndValue> annotations, String prefix) AppendAnnotatedannotations if any.- Parameters:
builder- the builderannotations- the list of annotationsprefix- the spacing prefix
-
toGenerics
Produces the generic descriptor decl for the method.- Parameters:
method- the methodupLevelToCollection- true if the generics should be "up leveled"- Returns:
- the generic decl
-
toGenerics
Produces the generic descriptor decl for the method.- Parameters:
typeName- the type nameupLevelToCollection- true if the generics should be "up leveled"- Returns:
- the generic decl
-
toString
Walk the collection to build a separator-delimited string value.- Parameters:
coll- the collection- Returns:
- the string representation
-
toString
protected static <T> String toString(Collection<T> coll, Optional<Function<T, String>> optFnc, Optional<String> optSeparator) Walk the collection to build a separator-delimited string value.- Type Parameters:
T- the types held by the collection- Parameters:
coll- the collectionoptFnc- the optional function to apply, defaulting toString.valueOf(java.lang.Object)optSeparator- the optional separator, defaulting to ", "- Returns:
- the string representation
-
toConfiguredOptionValue
protected static Optional<String> toConfiguredOptionValue(TypedElementName method, boolean wantTypeElementDefaults, boolean avoidBlanks) Extracts the value from the method, ignoringConfiguredOption.UNCONFIGURED.- Parameters:
method- the methodwantTypeElementDefaults- flag indicating whether the method passed can be used to obtain the default valuesavoidBlanks- flag indicating whether blank values should be ignored- Returns:
- the default value, or empty if there is no default value applicable for the given arguments
-
toValue
protected static Optional<String> toValue(Class<? extends Annotation> annoType, TypedElementName method, boolean wantTypeElementDefaults, boolean avoidBlanks) Retrieves the default value of the method to a string value.- Parameters:
annoType- the annotation that is being applied, that might have the default valuemethod- the methodwantTypeElementDefaults- flag indicating whether the method passed can be used to obtain the default valuesavoidBlanks- flag indicating whether blank values should be ignored- Returns:
- the default value, or empty if there is no default value applicable for the given arguments
-
appendCtorCodeBody
Appends the constructor body.- Parameters:
builder- the builderctx- the contextbuilderTag- the tag (variable name) used for the builder arg
-