Class CodeBuilderBase
java.lang.Object
org.tquadrat.foundation.config.ap.impl.codebuilders.CodeBuilderBase
- All Implemented Interfaces:
CodeBuilder
- Direct Known Subclasses:
CLIBeanBuilder
,ConfigBeanBuilder
,I18nSupportBuilder
,INIBeanBuilder
,MapImplementor
,PreferencesBeanBuilder
,SessionBeanBuilder
@ClassVersion(sourceVersion="$Id: CodeBuilderBase.java 1105 2024-02-28 12:58:46Z tquadrat $")
@API(status=INTERNAL,
since="0.1.0")
abstract sealed class CodeBuilderBase
extends Object
implements CodeBuilder
permits CLIBeanBuilder, ConfigBeanBuilder, I18nSupportBuilder, INIBeanBuilder, MapImplementor, PreferencesBeanBuilder, SessionBeanBuilder
The abstract base class for all the code builders.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: CodeBuilderBase.java 1105 2024-02-28 12:58:46Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.config.ap.impl.codebuilders.CodeBuilderBase"
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The various type to instantiate aStringConverter
class.Nested classes/interfaces inherited from interface org.tquadrat.foundation.config.ap.impl.CodeBuilder
CodeBuilder.StandardField, CodeBuilder.StandardMethod
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TypeSpec.Builder
The class builder.private final JavaComposer
The composer.private final CodeGenerationConfiguration
The configuration for the code generation.private final CodeBlock.Builder
The builder for body of the constructor.private final CodeGeneratorContext
The code generator context.The registry for the known implementations ofStringConverter
implementations.private final boolean
The synchronised flag.private static final Map
<CodeBuilder.StandardField, FieldSpec> The standard fields.private static final Map
<CodeBuilder.StandardMethod, MethodSpec> The standard methods. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CodeBuilderBase
(CodeGeneratorContext context) Creates a new instance ofCodeBuilderBase
. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
addConstructorArgument
(ParameterSpec argument) Adds an argument to the constructor.protected final void
addConstructorCode
(CodeBlock code) Adds code to the constructor body.protected final void
Adds a warning to the@SuppressWarnings
annotation for the constructor of the new configuration bean.protected final void
addField
(CodeBuilder.StandardField reference, FieldSpec field) Adds the given standard field to the new class.protected final void
Adds the given field to the new class.protected final void
addMethod
(CodeBuilder.StandardMethod reference, MethodSpec method) Adds the given method to the new class.protected final void
addMethod
(MethodSpec method) Adds the given method to the new class.abstract void
build()
Generates the relevant code.static MethodSpec
composeAddMethod
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes an 'add' method for the given property.static CodeBlock
composeConstructorFragment4Environment
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a constructor fragment for the initialisation of the given property in cases it is annotated with@EnvironmentVariable
.static CodeBlock
composeConstructorFragment4SystemPreference
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a constructor fragment for the initialisation of the given property in cases it is annotated with@EnvironmentVariable
.static CodeBlock
composeConstructorFragment4SystemProp
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a constructor fragment for the initialisation of the given property in cases it is annotated with@EnvironmentVariable
.static FieldSpec
composeField
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a field for the given property.static MethodSpec
composeGetter
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a getter for the given property.static MethodSpec
composeSetter
(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a setter for the given property.protected static final CodeBuilderBase.StringConverterInstantiation
determineStringConverterInstantiation
(TypeName stringConverterClass, boolean isEnum) Determines how to instantiate the given implementation ofStringConverter
.final JavaComposer
Provides access to the composer.Provides access to the code builder configuration.final FieldSpec
getField
(CodeBuilder.StandardField reference) Returns the specification for a standard field.final MethodSpec
getMethod
(CodeBuilder.StandardMethod reference) Returns the specification for a standard method.protected final Iterator
<PropertySpec> Returns an iterator over the configured properties.getStringConverter
(TypeName type) Returns theStringConverter
type for the given type.protected final boolean
Returns the flag that controls whether the configuration bean has to be generated thread safe.
-
Field Details
-
m_ClassBuilder
The class builder. -
m_Composer
The composer. -
m_Configuration
The configuration for the code generation. -
m_ConstructorCode
The builder for body of the constructor. -
m_Context
The code generator context. -
m_IsSynchronized
The synchronised flag. -
m_StandardFields
The standard fields. -
m_StandardMethods
The standard methods. -
m_ConverterRegistry
The registry for the known implementations ofStringConverter
implementations.
-
-
Constructor Details
-
CodeBuilderBase
Creates a new instance ofCodeBuilderBase
.- Parameters:
context
- The code generator context.
-
-
Method Details
-
addConstructorArgument
Adds an argument to the constructor.- Parameters:
argument
- The parameter to add.
-
addConstructorCode
Adds code to the constructor body.- Parameters:
code
- The code to add.
-
addConstructorSuppressedWarning
Adds a warning to the@SuppressWarnings
annotation for the constructor of the new configuration bean.- Parameters:
warning
- The warning to suppress.
-
addField
Adds the given field to the new class.- Parameters:
field
- The field to add.
-
addField
Adds the given standard field to the new class.- Parameters:
reference
- The identifier for the standard field.field
- The field to add.
-
addMethod
Adds the given method to the new class.- Parameters:
method
- The method to add.
-
addMethod
Adds the given method to the new class.- Parameters:
reference
- The identifier for the standard method.method
- The method to add.
-
build
Generates the relevant code.- Specified by:
build
in interfaceCodeBuilder
-
composeAddMethod
The default implementation of the method that composes an 'add' method for the given property.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The method specification.
-
composeConstructorFragment4Environment
public static CodeBlock composeConstructorFragment4Environment(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a constructor fragment for the initialisation of the given property in cases it is annotated with@EnvironmentVariable
.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The field specification.
-
composeConstructorFragment4SystemPreference
public static CodeBlock composeConstructorFragment4SystemPreference(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a constructor fragment for the initialisation of the given property in cases it is annotated with@EnvironmentVariable
.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The field specification.
-
composeConstructorFragment4SystemProp
public static CodeBlock composeConstructorFragment4SystemProp(CodeBuilder codeBuilder, PropertySpecImpl property) The default implementation of the method that composes a constructor fragment for the initialisation of the given property in cases it is annotated with@EnvironmentVariable
.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The field specification.
-
composeField
The default implementation of the method that composes a field for the given property.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The field specification.
-
composeGetter
The default implementation of the method that composes a getter for the given property.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The method specification.
-
composeSetter
The default implementation of the method that composes a setter for the given property.- Parameters:
codeBuilder
- The factory for the code generation.property
- The property.- Returns:
- The method specification.
-
determineStringConverterInstantiation
protected static final CodeBuilderBase.StringConverterInstantiation determineStringConverterInstantiation(TypeName stringConverterClass, boolean isEnum) Determines how to instantiate the given implementation ofStringConverter
.- Parameters:
stringConverterClass
- The String converter class.isEnum
-true
if the property is of anenum
type,false
otherwise.- Returns:
- The type of instantiation.
-
getComposer
Provides access to the composer.- Specified by:
getComposer
in interfaceCodeBuilder
- Returns:
- The composer.
-
getConfiguration
Provides access to the code builder configuration.- Specified by:
getConfiguration
in interfaceCodeBuilder
- Returns:
- The configuration.
-
getField
Returns the specification for a standard field.- Specified by:
getField
in interfaceCodeBuilder
- Parameters:
reference
- The identifier for the standard field.- Returns:
- The field.
-
getMethod
Returns the specification for a standard method.- Specified by:
getMethod
in interfaceCodeBuilder
- Parameters:
reference
- The identifier for the standard method.- Returns:
- The method.
-
getProperties
Returns an iterator over the configured properties.- Returns:
- The iterator.
-
getStringConverter
Returns theStringConverter
type for the given type.- Parameters:
type
- The type.- Returns:
- An instance of
Optional
that holds the requested implementation ofStringConverter
.
-
isSynchronized
Returns the flag that controls whether the configuration bean has to be generated thread safe.- Returns:
true
if lock support is required,false
otherwise.
-