Skip to content

Configure the Package of Generated Builders #294

Description

@AndreasIgel

Motivation

Allow users to explicitly control the package in which generated builder classes are created.

This is particularly useful for @SimpleBuilderFor, where the target type may belong to a third-party package and the generated builder should live in the application’s own package. Or for usecases where developers want to collect builders in one central package.

Proposed API

Add a package configuration option to the existing @SimpleBuilder.Options:

@SimpleBuilderFor(
    value = ExternalUser.class,
    options = @SimpleBuilder.Options(
        packageName = "com.example.generated"
    )
)
class ExternalBuilders {
}

The option should use the existing @SimpleBuilder.Options mechanism rather than adding a separate parameter to @SimpleBuilderFor. This option should always default to the package of the class for which it is generated. In case of SimpleBuilderFor it is the class where the annotation is positioned.

Example

Given:

package com.vendor.api;

public class ExternalUser {
    // ...
}

the generated builder could be placed in:

com.example.generated.ExternalUserBuilder

instead of deriving its package solely from the target type.

Requirements

  • Add packageName to the existing @SimpleBuilder.Options.
  • Preserve the current default behavior when packageName is not specified.
  • Apply the option consistently to all relevant builder-generation mechanisms.
  • Ensure generated imports and references remain valid.
  • Validate invalid package names at compile time.
  • Ensure that the constructors or setters are reachable. For example package-private (and protected) constructors, setters or getters should be handled as if they are not there because the builder would afterwards be placed in a totally different package

Relationship to @SimpleBuilderFor

In #293 we implement a feature for generation without adding annotation directly on this class. This feature here should be implemented as an independent, reusable configuration feature.

@SimpleBuilderFor can then use it without introducing external-type-specific package configuration.

Goal

Provide explicit control over the package of generated builders while keeping package configuration part of the existing Simple Builders options model.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions