Class EntityPropertiesEmitter<T extends com.atlassian.bamboo.specs.api.model.EntityProperties>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.atlassian.bamboo.specs.api.model.EntityProperties createDefaultObject​(com.atlassian.bamboo.specs.api.model.EntityProperties rootObject)
      Creates instance of the EntityProperties that contains default values.
      @NotNull java.lang.String emitCode​(@NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, T entity)
      Generates code for properties class.
      protected java.lang.String emitConstructorInvocation​(@NotNull com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, T entity)
      Generates constructor invocation of the builder class.
      protected java.lang.String emitFields​(@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 by emitConstructorInvocation(CodeGenerationContext, EntityProperties) not contained in fieldsToSkip and not annotated with SkipCodeGen.
      protected java.lang.String emitFieldValue​(com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context, com.atlassian.bamboo.specs.api.model.EntityProperties entity, java.lang.reflect.Field field)
      Generates value of a field.
      protected @Nullable java.lang.reflect.Field findField​(java.lang.Class<?> clazz, java.lang.String fieldName)  
      protected boolean hasPublicConstructor​(java.lang.Class<?> builderClass, java.lang.Class<?>... argTypes)  
      protected void initBuilderClass​(T entity)
      Default method of finding builderClass.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 in emitFields(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 Detail

      • EntityPropertiesEmitter

        public EntityPropertiesEmitter()
    • 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 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 java.lang.String emitFieldValue​(com.atlassian.bamboo.specs.api.codegen.CodeGenerationContext context,
                                                  com.atlassian.bamboo.specs.api.model.EntityProperties entity,
                                                  java.lang.reflect.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 the EntityProperties that 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
        If none of the above is present null value is returned and code is generated for all non-empty fields.
      • emitFields

        protected java.lang.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 by emitConstructorInvocation(CodeGenerationContext, EntityProperties) not contained in fieldsToSkip and not annotated with SkipCodeGen. 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 finding builderClass. 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 java.lang.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:
        emitCode in interface com.atlassian.bamboo.specs.api.codegen.CodeEmitter<T extends com.atlassian.bamboo.specs.api.model.EntityProperties>
        Throws:
        com.atlassian.bamboo.specs.api.codegen.CodeGenerationException