Class DefaultBuilderCreatorProvider

java.lang.Object
io.helidon.builder.processor.tools.DefaultBuilderCreatorProvider
All Implemented Interfaces:
BuilderCreatorProvider

public class DefaultBuilderCreatorProvider extends Object implements BuilderCreatorProvider
Default implementation for BuilderCreatorProvider.
  • Constructor Details

    • DefaultBuilderCreatorProvider

      @Deprecated public DefaultBuilderCreatorProvider()
      Deprecated.
      Default constructor.
  • Method Details

    • supportedAnnotationTypes

      public Set<Class<? extends Annotation>> supportedAnnotationTypes()
      Specified by:
      supportedAnnotationTypes in interface BuilderCreatorProvider
    • create

      public List<TypeAndBody> create(TypeInfo typeInfo, AnnotationAndValue builderAnnotation)
      Specified by:
      create in interface BuilderCreatorProvider
    • 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 name
      typeInfo - the type info
      builderAnnotation - the builder annotation triggering the code generation
    • postValidate

      protected List<TypeAndBody> postValidate(List<TypeAndBody> builds)
      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

      protected TypeName toAbstractImplTypeName(TypeName typeName, AnnotationAndValue builderAnnotation)
      Constructs the abstract implementation type name for what is code generated.
      Parameters:
      typeName - the target interface that the builder applies to
      builderAnnotation - 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 to
      builderAnnotation - 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 class
      typeName - the type name that will be code generated
      typeInfo - the type info describing the target interface
      builderAnnotation - the builder annotation that triggered the builder being created
      Returns:
      the context describing what is being built
    • toBody

      protected String toBody(BodyContext ctx)
      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
    • appendFooter

      protected void appendFooter(StringBuilder builder, BodyContext ctx)
      Appends the footer of the generated class.
      Parameters:
      builder - the builder
      ctx - the context
    • maybeAppendInterceptor

      protected void maybeAppendInterceptor(StringBuilder builder, BodyContext ctx, String builderTag)
      Appends any interceptor on the builder.
      Parameters:
      builder - the builder
      ctx - the context
      builderTag - the tag (variable name) used for the builder arg
    • appendRequiredVisitor

      protected void appendRequiredVisitor(StringBuilder builder, BodyContext ctx, String builderTag)
      Appends the simple ConfiguredOption.required() validation inside the build() method.
      Parameters:
      builder - the builder
      ctx - the context
      builderTag - the tag (variable name) used for the builder arg
    • appendBasicGetters

      protected void appendBasicGetters(StringBuilder builder, BodyContext ctx)
      Adds the basic getters to the generated builder output.
      Parameters:
      builder - the builder
      ctx - the context
    • appendMetaAttributes

      protected void appendMetaAttributes(StringBuilder builder, BodyContext ctx)
      Appends meta attribute related methods.
      Parameters:
      builder - the builder
      ctx - the context
    • appendFields

      protected void appendFields(StringBuilder builder, BodyContext ctx)
      Adds the fields part of the generated builder.
      Parameters:
      builder - the builder
      ctx - the context
    • appendHeader

      protected void appendHeader(StringBuilder builder, BodyContext ctx)
      Adds the header part of the generated builder.
      Parameters:
      builder - the builder
      ctx - the context
    • generatedCopyrightHeaderFor

      protected String generatedCopyrightHeaderFor(BodyContext ctx)
      Returns the copyright level header comment.
      Parameters:
      ctx - the context
      Returns:
      the copyright level header
    • generatedStickerFor

      protected String generatedStickerFor(BodyContext ctx)
      Returns the Generated sticker to be added.
      Parameters:
      ctx - the context
      Returns:
      the generated sticker
    • generatedVersionFor

      protected String generatedVersionFor(BodyContext ctx)
      Returns the Generated version identifier.
      Parameters:
      ctx - the context
      Returns:
      the generated version identifier
    • baseExtendsTypeName

      protected Optional<TypeName> baseExtendsTypeName(BodyContext ctx)
      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

      protected Optional<TypeName> baseExtendsBuilderTypeName(BodyContext ctx)
      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

      protected List<TypeName> extraImplementedTypeNames(BodyContext ctx)
      Returns any extra 'implements' contract types that should be on the main generated type.
      Parameters:
      ctx - the context
      Returns:
      extra contracts implemented
    • extraImplementedBuilderContracts

      protected List<TypeName> extraImplementedBuilderContracts(BodyContext ctx)
      Returns any extra 'implements' contract types that should be on the main generated builder type.
      Parameters:
      ctx - the context
      Returns:
      extra contracts implemented
    • appendExtraImports

      protected void appendExtraImports(StringBuilder builder, BodyContext ctx)
      Adds extra imports to the generated builder.
      Parameters:
      builder - the builder
      ctx - the context
    • appendToStringMethod

      protected void appendToStringMethod(StringBuilder builder, BodyContext ctx)
      Generated the toString method on the generated builder.
      Parameters:
      builder - the builder
      ctx - the context
    • instanceIdRef

      protected String instanceIdRef(BodyContext ctx)
      The nuanced instance id for the appendToStringMethod(StringBuilder, BodyContext).
      Parameters:
      ctx - the context
      Returns:
      the instance id
    • appendExtraMethods

      protected void appendExtraMethods(StringBuilder builder, BodyContext ctx)
      Adds extra methods to the generated builder. This base implementation will generate the visitAttributes() for the main generated class.
      Parameters:
      builder - the builder
      ctx - the context
    • appendExtraInnerClasses

      protected void appendExtraInnerClasses(StringBuilder builder, BodyContext ctx)
      Adds extra inner classes to write on the builder. This default implementation will write the AttributeVisitor and RequiredAttributeVisitor inner classes on the base abstract parent (ie, hasParent is false).
      Parameters:
      builder - the builder
      ctx - the context
    • fieldModifier

      protected String 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 builder
      ctx - the context
      extraTabs - spacing
      beanNameRef - refer to bean name? otherwise refer to the element name
    • overridesVisitAttributes

      protected boolean overridesVisitAttributes(BodyContext ctx)
      Return true if the visitAttributes() methods is being overridden.
      Parameters:
      ctx - the context
      Returns:
      true if overriding visitAttributes();
    • appendExtraCtorCode

      protected void appendExtraCtorCode(StringBuilder builder, BodyContext ctx, String builderTag)
      Adds extra default ctor code.
      Parameters:
      builder - the builder
      ctx - the context
      builderTag - the tag (variable name) used for the builder arg
    • appendExtraPostCtorCode

      protected void appendExtraPostCtorCode(StringBuilder builder, BodyContext ctx)
      Adds extra code following the ctor decl.
      Parameters:
      builder - the builder
      ctx - the context
    • appendExtraFields

      protected void appendExtraFields(StringBuilder builder, BodyContext ctx)
      Adds extra fields on the main generated class.
      Parameters:
      builder - the builder
      ctx - the context
    • appendExtraToBuilderBuilderFunctions

      protected void appendExtraToBuilderBuilderFunctions(StringBuilder builder, BodyContext ctx, String decl)
      Adds extra toBuilder() methods.
      Parameters:
      builder - the builder
      ctx - the context
      decl - the declaration template for the toBuilder method
    • appendExtraBuilderFields

      protected void appendExtraBuilderFields(StringBuilder builder, BodyContext ctx)
      Adds extra builder methods.
      Parameters:
      builder - the builder
      ctx - 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 builder
      ctx - the context
      builderTag - the tag (variable name) used for the builder arg
    • appendExtraBuilderMethods

      protected void appendExtraBuilderMethods(StringBuilder builder, BodyContext ctx)
      Adds extra builder methods. This base implementation will write the visitAttributes() method on the generated builder class.
      Parameters:
      builder - the builder
      ctx - 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 builder
      ctx - the context
      tag - the tag used to represent the meta props variable on the generated code
      needsCustomMapOf - will be set to true if a custom map.of() function needs to be generated (i.e., if over 9 tuples)
    • normalizeConfiguredOptionKey

      protected String normalizeConfiguredOptionKey(String key, String name, boolean isAttribute)
      Normalize the configured option key.
      Parameters:
      key - the key attribute
      name - the name
      isAttribute - if the name represents an attribute value (otherwise is a config bean name)
      Returns:
      the key to write on the generated output
    • toConfigKey

      protected String toConfigKey(String name, boolean isAttribute)
      Applicable if this builder is intended for config beans.
      Parameters:
      name - the name
      isAttribute - 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 builder
      ctx - the context
      method - the method
      beanAttributeName - the bean attribute name
      isList - true if the output involves List type
      isMap - true if the output involves Map type
      isSet - true if the output involves Set type
    • maybeSingularFormOf

      protected static String maybeSingularFormOf(String beanAttributeName)
      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

      protected static String nameOf(TypedElementName elem)
      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 builder
      ctx - the body context
      beanAttributeName - the bean attribute name
      methodName - the method name
      method - 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 builder
      ctx - the body context
      beanAttributeName - the bean attribute name
      method - the method
      methodName - the method name
      genericType - the generic return type name of the method
    • appendAnnotations

      protected void appendAnnotations(StringBuilder builder, List<AnnotationAndValue> annotations, String prefix)
      Append Annotated annotations if any.
      Parameters:
      builder - the builder
      annotations - the list of annotations
      prefix - the spacing prefix
    • toGenerics

      protected static String toGenerics(TypedElementName method, boolean upLevelToCollection)
      Produces the generic descriptor decl for the method.
      Parameters:
      method - the method
      upLevelToCollection - true if the generics should be "up leveled"
      Returns:
      the generic decl
    • toGenerics

      protected static String toGenerics(TypeName typeName, boolean upLevelToCollection)
      Produces the generic descriptor decl for the method.
      Parameters:
      typeName - the type name
      upLevelToCollection - true if the generics should be "up leveled"
      Returns:
      the generic decl
    • toString

      protected static String toString(Collection<?> coll)
      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 collection
      optFnc - the optional function to apply, defaulting to String.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, ignoring ConfiguredOption.UNCONFIGURED.
      Parameters:
      method - the method
      wantTypeElementDefaults - flag indicating whether the method passed can be used to obtain the default values
      avoidBlanks - 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 value
      method - the method
      wantTypeElementDefaults - flag indicating whether the method passed can be used to obtain the default values
      avoidBlanks - 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

      protected void appendCtorCodeBody(StringBuilder builder, BodyContext ctx, String builderTag)
      Appends the constructor body.
      Parameters:
      builder - the builder
      ctx - the context
      builderTag - the tag (variable name) used for the builder arg