Class EntityPropertiesEmitter<T extends com.atlassian.bamboo.specs.api.model.EntityProperties>
java.lang.Object
com.atlassian.bamboo.specs.codegen.emitters.value.EntityPropertiesEmitter<T>
- All Implemented Interfaces:
com.atlassian.bamboo.specs.api.codegen.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 com.atlassian.bamboo.specs.api.model.EntityProperties>
extends Object
implements com.atlassian.bamboo.specs.api.codegen.CodeEmitter<T>
Default code generator for any
EntityProperties
This class can be extended to implement more specialised generators.
Note that the implementation is stateful.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Class<?>Builder class associated with given properties type.Fields that should be skipped inemitFields(CodeGenerationContext, EntityProperties). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.atlassian.bamboo.specs.api.model.EntityPropertiescreateDefaultObject(com.atlassian.bamboo.specs.api.model.EntityProperties rootObject) Creates instance of theEntityPropertiesthat contains default values.@NotNull StringGenerates code for properties class.protected StringemitConstructorInvocation(@NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, T entity) Generates constructor invocation of the builder class.protected StringemitFields(@NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, @NotNull com.atlassian.bamboo.specs.api.model.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 StringemitFieldValue(com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, com.atlassian.bamboo.specs.api.model.EntityProperties entity, Field field) Generates value of a field.protected @Nullable Fieldprotected booleanhasPublicConstructor(Class<?> builderClass, Class<?>... argTypes) protected voidinitBuilderClass(T entity) Default method of findingbuilderClass.
-
Field Details
-
builderClass
Builder class associated with given properties type. -
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.
-
-
Constructor Details
-
EntityPropertiesEmitter
public EntityPropertiesEmitter()
-
-
Method Details
-
findField
-
hasPublicConstructor
-
emitConstructorInvocation
protected String emitConstructorInvocation(@NotNull @NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, @NotNull T entity) throws com.atlassian.bamboo.specs.api.codegen.CodeGenerationException Generates constructor invocation of the builder class.- Throws:
com.atlassian.bamboo.specs.api.codegen.CodeGenerationException
-
emitFieldValue
protected String emitFieldValue(com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, com.atlassian.bamboo.specs.api.model.EntityProperties entity, Field field) throws com.atlassian.bamboo.specs.api.codegen.CodeGenerationException Generates value of a field. Used to generate constructor invocation.- Throws:
com.atlassian.bamboo.specs.api.codegen.CodeGenerationException
-
createDefaultObject
protected com.atlassian.bamboo.specs.api.model.EntityProperties createDefaultObject(com.atlassian.bamboo.specs.api.model.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 String emitFields(@NotNull @NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, @NotNull @NotNull com.atlassian.bamboo.specs.api.model.EntityProperties entity) throws com.atlassian.bamboo.specs.api.codegen.CodeGenerationException Generate 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:
com.atlassian.bamboo.specs.api.codegen.CodeGenerationException
-
initBuilderClass
protected void initBuilderClass(@NotNull T entity) throws com.atlassian.bamboo.specs.api.codegen.CodeGenerationException Default method of findingbuilderClass. Extending class can set the field explicitly to skip the default search algorithm.- Throws:
com.atlassian.bamboo.specs.api.codegen.CodeGenerationException
-
emitCode
@NotNull public @NotNull String emitCode(@NotNull @NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, @NotNull T entity) throws com.atlassian.bamboo.specs.api.codegen.CodeGenerationException Generates code for properties class. This includes generating invocation of the constructor of the appropriate builder followed by invocations of its setters.- Specified by:
emitCodein interfacecom.atlassian.bamboo.specs.api.codegen.CodeEmitter<T extends com.atlassian.bamboo.specs.api.model.EntityProperties>- Throws:
com.atlassian.bamboo.specs.api.codegen.CodeGenerationException
-