public class EntityPropertiesEmitter<T extends EntityProperties> extends Object implements CodeEmitter<T>
EntityProperties
This class can be extended to implement more specialised generators.
Note that the implementation is stateful.Modifier and Type | Field and Description |
---|---|
protected Class<?> |
builderClass
Builder class associated with given properties type.
|
protected Set<String> |
fieldsToSkip
Fields that should be skipped in
emitFields(CodeGenerationContext, EntityProperties) . |
Constructor and Description |
---|
EntityPropertiesEmitter() |
Modifier and Type | Method and Description |
---|---|
protected EntityProperties |
createDefaultObject(EntityProperties rootObject)
Creates instance of the
EntityProperties that contains default values. |
String |
emitCode(CodeGenerationContext context,
T entity)
Generates code for properties class.
|
protected String |
emitConstructorInvocation(CodeGenerationContext context,
T entity)
Generates constructor invocation of the builder class.
|
protected String |
emitFields(CodeGenerationContext context,
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 String |
emitFieldValue(CodeGenerationContext context,
EntityProperties entity,
Field field)
Generates value of a field.
|
protected Field |
findField(Class<?> clazz,
String fieldName) |
protected boolean |
hasPublicConstructor(Class<?> builderClass,
Class<?>... argTypes) |
protected void |
initBuilderClass(T entity)
Default method of finding
builderClass . |
protected Class<?> builderClass
protected final Set<String> fieldsToSkip
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.protected boolean hasPublicConstructor(Class<?> builderClass, Class<?>... argTypes)
protected String emitConstructorInvocation(@NotNull CodeGenerationContext context, @NotNull T entity) throws CodeGenerationException
CodeGenerationException
protected String emitFieldValue(CodeGenerationContext context, EntityProperties entity, Field field) throws CodeGenerationException
CodeGenerationException
protected EntityProperties createDefaultObject(EntityProperties rootObject)
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:
DefaultFieldValues
protected String emitFields(@NotNull CodeGenerationContext context, @NotNull EntityProperties entity) throws CodeGenerationException
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.CodeGenerationException
protected void initBuilderClass(@NotNull T entity) throws CodeGenerationException
builderClass
. Extending class can set the field explicitly to skip the default search algorithm.CodeGenerationException
@NotNull public String emitCode(@NotNull CodeGenerationContext context, @NotNull T entity) throws CodeGenerationException
emitCode
in interface CodeEmitter<T extends EntityProperties>
CodeGenerationException
Copyright © 2020 Atlassian Software Systems Pty Ltd. All rights reserved.