public interface FieldHandler
An element capable of handling constants on a type.
-
Method Summary
Modifier and TypeMethodDescriptionconstant(String constantNamePrefix, TypeName constantType, Object uniqueIdentifier, Consumer<ContentBuilder<?>> contentBuilder) Creates (or re-uses) a private constant in the generated class.static FieldHandlercreate(ClassModel.Builder classModel, Constructor.Builder constructor) Create a new constant handler for a class.field(TypeName typeName, String fieldName, AccessModifier modifier, Object uniqueIdentifier, Consumer<ContentBuilder<?>> fieldUpdater, BiConsumer<Constructor.Builder, String> constructorUpdater) Creates (or re-uses) a private final field in the generated class.
-
Method Details
-
create
Create a new constant handler for a class. The constant handler ignores existing constants, or constants created outside of it.- Parameters:
classModel- class model builderconstructor- constructor builder (of the class we are processing), to add assignments and parameters if needed- Returns:
- a new constant handler
-
constant
String constant(String constantNamePrefix, TypeName constantType, Object uniqueIdentifier, Consumer<ContentBuilder<?>> contentBuilder) Creates (or re-uses) a private constant in the generated class.In case a new constant is needed, and there is a name conflict, a number will be used to uniquely identify the constant.
- Parameters:
constantNamePrefix- prefix for the constant name, such asHEADER_X_TESTconstantType- type of the constant, such as type ofHeaderNameuniqueIdentifier- unique identification of the constant within its type, must have correct equals and hashCode methodscontentBuilder- content builder to initialize the constant if it does not yet exist- Returns:
- constant name
-
field
String field(TypeName typeName, String fieldName, AccessModifier modifier, Object uniqueIdentifier, Consumer<ContentBuilder<?>> fieldUpdater, BiConsumer<Constructor.Builder, String> constructorUpdater) Creates (or re-uses) a private final field in the generated class.In case a new field is needed, and there is a name conflict, a number will be used to uniquely identify the field.
- Parameters:
typeName- type of the fieldfieldName- name of the fieldmodifier- modifier of the declarationuniqueIdentifier- unique identification of the field within its type, must have correct equals and hashCode methodsfieldUpdater- consumer of the field content builder (if it is initialized inlined)constructorUpdater- bi-consumer of the constructor builder (if it is initialized in constructor), and the field name- Returns:
- field name
-