Skip to content

Comments

feat: add optional suffix to static builder#134

Open
RichardTree wants to merge 1 commit intoRandgalt:masterfrom
RichardTree:master
Open

feat: add optional suffix to static builder#134
RichardTree wants to merge 1 commit intoRandgalt:masterfrom
RichardTree:master

Conversation

@RichardTree
Copy link

Not sure what you think of this, my team are coming from using Immutables heavily and are fond of their FieldName.of() syntax convention for static builders.

I’m assuming my change would enable us to call a static builder like FieldNameBuilder.FieldNameOf().

When statically imported, would read succinctly as FieldNameOf()

@Randgalt
Copy link
Owner

Thanks for the PR - I'll look at this soon.

*/
CodeBlock codeBlock = buildCodeBlock();
var builder = MethodSpec.methodBuilder(recordClassType.name())
var builder = MethodSpec.methodBuilder(recordClassType.name() + metaData.staticBuilderSuffix())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var builder = MethodSpec.methodBuilder(recordClassType.name() + metaData.staticBuilderSuffix())
var staticBuilderName = Optional.of(metaData.staticBuilderSuffix()).filter(e -> !e.isEmpty()).map(e -> lowerCaseFirstLetter(recordClassType.name())+ e).orElse(recordClassType.name());
var builder = MethodSpec.methodBuilder(staticBuilderName)
   private String lowerCaseFirstLetter(String value) {
        return value.substring(0,1).toLowerCase() + value.substring(1);
    }

Might be nicer to lowercase the first letter of the static builder as well so instead of FirstnameOf you have firstnameOf for example

@Randgalt
Copy link
Owner

My initial reaction is that RecordBuilder is getting too many options. We've already had some incompatible ones. We may need to re-think the customization scheme.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants