Randgalt / record-builder

Record builder generator for Java records
Apache License 2.0
723 stars 51 forks source link

Configurable modifiers on static builders #135

Closed codefish1 closed 1 year ago

codefish1 commented 1 year ago

The use case

Ensure people use the static builder and don't new up the record directly by restricting access to the records constructor. This becomes more important when 50+ developers are working on the same code base, by using the compiler to help enforce the stylist approaches.

Why Do we need this?

Currently with records we can't make the constructor private, it will have the same visibility as the record it's self. In addition when using this library, the static builder will also have the same visibility as the record.

What does this PR add?

This PR enables you to configure the modifiers on the static builder such that you can set the static builder to have a public modifier whereas the record is package-protect, so when your records are in a domain package they can't be accessed directly and new'ed up.

Discussion points

  1. Do we want to make this configurable like in this PR or a simple boolean flag

Outstanding work

Assuming you are happy with the principle and approach, I need to update the documentation.

Randgalt commented 1 year ago

This is good - I like the option as is. Please update the doc.

codefish1 commented 1 year ago

Is there a page which describes the various options? All I can see is a link to the RecordBuilder annotation to view the javadoc in there

Randgalt commented 1 year ago

Is there a page which describes the various options? All I can see is a link to the RecordBuilder annotation to view the javadoc in there

I guess not.

Randgalt commented 1 year ago

Thanks for the submission