Interface FieldHandler


public interface FieldHandler
An element capable of handling constants on a type.
  • Method Details

    • create

      static FieldHandler create(ClassModel.Builder classModel, Constructor.Builder constructor)
      Create a new constant handler for a class. The constant handler ignores existing constants, or constants created outside of it.
      Parameters:
      classModel - class model builder
      constructor - 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 as HEADER_X_TEST
      constantType - type of the constant, such as type of HeaderName
      uniqueIdentifier - unique identification of the constant within its type, must have correct equals and hashCode methods
      contentBuilder - 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 field
      fieldName - name of the field
      modifier - modifier of the declaration
      uniqueIdentifier - unique identification of the field within its type, must have correct equals and hashCode methods
      fieldUpdater - 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