Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional suffix to static builder #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

@@ -363,7 +363,7 @@ public static MyRecord(int p1, T p2, ...) {
}
*/
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.

None yet

3 participants