Class EntityPropertiesEmitter<T extends EntityProperties>
- java.lang.Object
-
- com.atlassian.bamboo.specs.codegen.emitters.value.EntityPropertiesEmitter<T>
-
- All Implemented Interfaces:
CodeEmitter<T>
- Direct Known Subclasses:
AnyNotificationRecipientEmitter,AnyNotificationTypeEmitter,AnyVcsRepositoryViewerEmitter,ArtifactItemEmitter,BaseVcsTaskEmitter,BranchCleanupEmitter,BuildWarningParserTaskEmitter,CheckoutSpecEmitter,DockerBuildImageEmitter,DockerRegistryEmitter,DockerRunContainerEmitter,PermissionPropertiesEmitter,PlanIdentifierEmitter,ScheduledTriggerEmitter,ScpTaskEmitter,SharedCredentialsIdentifierEmitter,SshTaskEmitter
public class EntityPropertiesEmitter<T extends EntityProperties> extends java.lang.Object implements CodeEmitter<T>
Default code generator for anyEntityPropertiesThis class can be extended to implement more specialised generators. Note that the implementation is stateful.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<?>builderClassBuilder class associated with given properties type.protected java.util.Set<java.lang.String>fieldsToSkipFields that should be skipped inemitFields(CodeGenerationContext, EntityProperties).
-
Constructor Summary
Constructors Constructor Description EntityPropertiesEmitter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EntityPropertiescreateDefaultObject(EntityProperties rootObject)Creates instance of theEntityPropertiesthat contains default values.@NotNull java.lang.StringemitCode(@NotNull CodeGenerationContext context, T entity)Generates code for properties class.protected java.lang.StringemitConstructorInvocation(@NotNull CodeGenerationContext context, T entity)Generates constructor invocation of the builder class.protected java.lang.StringemitFields(@NotNull CodeGenerationContext context, @NotNull EntityProperties entity)Generate code for all fields of the class that are not already covered byemitConstructorInvocation(CodeGenerationContext, EntityProperties)not contained infieldsToSkipand not annotated withSkipCodeGen.protected java.lang.StringemitFieldValue(CodeGenerationContext context, EntityProperties entity, java.lang.reflect.Field field)Generates value of a field.protected @Nullable java.lang.reflect.FieldfindField(java.lang.Class<?> clazz, java.lang.String fieldName)protected booleanhasPublicConstructor(java.lang.Class<?> builderClass, java.lang.Class<?>... argTypes)protected voidinitBuilderClass(T entity)Default method of findingbuilderClass.
-
-
-
Field Detail
-
builderClass
protected java.lang.Class<?> builderClass
Builder class associated with given properties type.
-
fieldsToSkip
protected final java.util.Set<java.lang.String> fieldsToSkip
Fields that should be skipped inemitFields(CodeGenerationContext, EntityProperties). Extending classes can use this field to be able to add specialised handling for some fields, while still being able to delegate handling for the rest of the class to default implementation.
-
-
Method Detail
-
findField
@Nullable protected @Nullable java.lang.reflect.Field findField(java.lang.Class<?> clazz, java.lang.String fieldName)
-
hasPublicConstructor
protected boolean hasPublicConstructor(java.lang.Class<?> builderClass, java.lang.Class<?>... argTypes)
-
emitConstructorInvocation
protected java.lang.String emitConstructorInvocation(@NotNull @NotNull CodeGenerationContext context, @NotNull T entity) throws CodeGenerationExceptionGenerates constructor invocation of the builder class.- Throws:
CodeGenerationException
-
emitFieldValue
protected java.lang.String emitFieldValue(CodeGenerationContext context, EntityProperties entity, java.lang.reflect.Field field) throws CodeGenerationException
Generates value of a field. Used to generate constructor invocation.- Throws:
CodeGenerationException
-
createDefaultObject
protected EntityProperties createDefaultObject(EntityProperties rootObject)
Creates instance of theEntityPropertiesthat contains default values. The values are then compared to the actual field values of the instance the code is generated for. If the values match it is assumed that invocation of the respective setter is not necessary. The object is generated by trying the following:- static method annotated with
DefaultFieldValues - a parameterless constructor
- static method annotated with
-
emitFields
protected java.lang.String emitFields(@NotNull @NotNull CodeGenerationContext context, @NotNull @NotNull EntityProperties entity) throws CodeGenerationExceptionGenerate code for all fields of the class that are not already covered byemitConstructorInvocation(CodeGenerationContext, EntityProperties)not contained infieldsToSkipand not annotated withSkipCodeGen. This involves finding a matching setter method, determining the appropriate code generator and generating method invocation and its arguments.- Throws:
CodeGenerationException
-
initBuilderClass
protected void initBuilderClass(@NotNull T entity) throws CodeGenerationExceptionDefault method of findingbuilderClass. Extending class can set the field explicitly to skip the default search algorithm.- Throws:
CodeGenerationException
-
emitCode
@NotNull public @NotNull java.lang.String emitCode(@NotNull @NotNull CodeGenerationContext context, @NotNull T entity) throws CodeGenerationExceptionGenerates code for properties class. This includes generating invocation of the constructor of the appropriate builder followed by invocations of its setters.- Specified by:
emitCodein interfaceCodeEmitter<T extends EntityProperties>- Throws:
CodeGenerationException
-
-