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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@
*/
boolean addStaticBuilder() default true;

/**
* If set, appends a suffix to the static builder method
*/
String staticBuilderSuffix() default "";


/**
* If {@link #addSingleItemCollectionBuilders()} and {@link #useImmutableCollections()} are enabled the builder
* uses an internal class to track changes to lists. This is the name of that class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

.addJavadoc("Static constructor/builder. Can be used instead of new $L(...)\n", recordClassType.name())
.addTypeVariables(typeVariables)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
Expand Down