Skip to content

Conversation

@velo
Copy link

@velo velo commented Oct 24, 2025

Summary

This PR adds support for using @Singular with Optional types in @Builder.

Changes

  • Added JavacJavaUtilOptionalSingularizer for javac compiler support
  • Added EclipseJavaUtilOptionalSingularizer for Eclipse compiler support
  • Added comprehensive test cases for Optional singularization

Behavior

For a field annotated with @Singular Optional<T>, the builder generates:

  • A setter method accepting the unwrapped type T
  • A clear method to reset the optional
  • Build code that wraps the value in Optional.ofNullable() or returns Optional.empty()

Example

@Builder class Example { @Singular private Optional<String> name; } // Generated methods: builder.name("John") // Sets the value builder.clearName() // Clears the value builder.build() // Returns Optional.ofNullable(value) or Optional.empty()

Test Plan

  • Compiles successfully with ant dist
  • Added test cases in test/transform/resource/
  • Tests should be run with ant test

Fixes #3976

velo added 2 commits October 24, 2025 10:00
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
@ExE-Boss
Copy link

Since this is using Optional​::ofNullable(…), the …$set subfield is redundant.

…le directly Signed-off-by: Marvin Froeder <velo.br@gmail.com>
@velo
Copy link
Author

velo commented Oct 27, 2025

Since this is using Optional​::ofNullable(…), the …$set subfield is redundant.

done

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

Labels

None yet

2 participants