@@ -14,23 +14,23 @@ private Templates() {}
14
14
15
15
/** Builder class for {@link {{shortName}} } */
16
16
@Generated("avaje-record-builder")
17
- public class {{shortName}}Builder {{fullTypeParams}} {
17
+ public class {{builderName}} {{fullTypeParams}} {
18
18
19
19
{{fields}}
20
- private {{shortName}}Builder () {}
20
+ private {{builderName}} () {}
21
21
{{constructor}}
22
22
/**
23
23
* Return a new builder with all fields set to default Java values
24
24
*/
25
- public static{{fullTypeParamsTransformed}}{{shortName}}Builder {{typeParams}} builder() {
26
- return new {{shortName}}Builder {{typeParams}}();
25
+ public static{{fullTypeParamsTransformed}}{{builderName}} {{typeParams}} builder() {
26
+ return new {{builderName}} {{typeParams}}();
27
27
}
28
28
29
29
/**
30
30
* Return a new builder with all fields set to the values taken from the given record instance
31
31
*/
32
- public static{{fullTypeParamsTransformed}}{{shortName}}Builder {{typeParams}} builder({{shortName}}{{typeParams}} from) {
33
- return new {{shortName}}Builder {{typeParams}}({{builderFrom}});
32
+ public static{{fullTypeParamsTransformed}}{{builderName}} {{typeParams}} builder({{shortName}}{{typeParams}} from) {
33
+ return new {{builderName}} {{typeParams}}({{builderFrom}});
34
34
}
35
35
36
36
/**
@@ -43,14 +43,15 @@ public class {{shortName}}Builder{{fullTypeParams}} {
43
43
private static <T> T requireNonNull(@Nullable T obj, String fieldName) {
44
44
if (obj == null) {
45
45
throw new IllegalStateException(
46
- \"{{shortName}}Builder expected a value for property %s, but was null.\".formatted(fieldName));
46
+ \"{{builderName}} expected a value for property %s, but was null.\".formatted(fieldName));
47
47
}
48
48
return obj;
49
49
}
50
50
""" )
51
51
public record ClassTemplate (
52
52
String packageName ,
53
53
String imports ,
54
+ String builderName ,
54
55
String shortName ,
55
56
String fields ,
56
57
String constructor ,
@@ -66,6 +67,7 @@ String render() {
66
67
static String classTemplate (
67
68
String packageName ,
68
69
String imports ,
70
+ String builderName ,
69
71
String shortName ,
70
72
String fields ,
71
73
String constructorArgs ,
@@ -78,10 +80,11 @@ static String classTemplate(
78
80
var constructor =
79
81
constructorArgs .isBlank ()
80
82
? ""
81
- : new Constructor (shortName , constructorArgs , constructorBody ).render ();
83
+ : new Constructor (builderName , constructorArgs , constructorBody ).render ();
82
84
return new ClassTemplate (
83
85
packageName .isBlank () ? "" : "package " + packageName + ";" ,
84
86
imports ,
87
+ builderName ,
85
88
shortName ,
86
89
fields ,
87
90
constructor ,
@@ -98,11 +101,11 @@ static String classTemplate(
98
101
template =
99
102
"""
100
103
101
- private {{shortName}}Builder ({{args}}) {
104
+ private {{builderName}} ({{args}}) {
102
105
{{constructorBody}}
103
106
}
104
107
""" )
105
- public record Constructor (String shortName , String args , String constructorBody ) {
108
+ public record Constructor (String builderName , String args , String constructorBody ) {
106
109
107
110
String render () {
108
111
return ConstructorRenderer .of ().execute (this );
@@ -114,19 +117,19 @@ String render() {
114
117
"""
115
118
116
119
/** Set a new value for {@code {{componentName}} }. */
117
- public {{shortName}}Builder {{typeParams}} {{componentName}}({{type}} {{componentName}}) {
120
+ public {{builderName}} {{typeParams}} {{componentName}}({{type}} {{componentName}}) {
118
121
this.{{componentName}} = {{componentName}};
119
122
return this;
120
123
}
121
124
""" )
122
125
public record MethodSetter (
123
- String componentName , String type , String shortName , String typeParams ) {
126
+ String componentName , String type , String builderName , String typeParams ) {
124
127
125
128
static String methodSetter (
126
- CharSequence componentName , String type , String shortName , String typeParams ) {
129
+ CharSequence componentName , String type , String builderName , String typeParams ) {
127
130
128
131
return new MethodSetter (
129
- componentName .toString (), type , shortName . replace ( "." , "$" ) , typeParams )
132
+ componentName .toString (), type , builderName , typeParams )
130
133
.render ();
131
134
}
132
135
@@ -175,20 +178,20 @@ String render() {
175
178
"""
176
179
177
180
/** Add new element to the {@code {{componentName}} } collection. */
178
- public {{shortName}}Builder {{typeParams}} add{{upperCamel}}({{param0}} element) {
181
+ public {{builderName}} {{typeParams}} add{{upperCamel}}({{param0}} element) {
179
182
this.{{componentName}}.add(element);
180
183
return this;
181
184
}
182
185
""" )
183
186
public record MethodAdd (
184
- String componentName , String shortName , String upperCamel , String param0 , String typeParams ) {
187
+ String componentName , String builderName , String upperCamel , String param0 , String typeParams ) {
185
188
static String methodAdd (
186
- String componentName , String type , String shortName , String param0 , String typeParams ) {
189
+ String componentName , String builderName , String param0 , String typeParams ) {
187
190
String upperCamel =
188
191
Character .toUpperCase (componentName .charAt (0 )) + componentName .substring (1 );
189
192
190
193
return new MethodAdd (
191
- componentName , shortName . replace ( "." , "$" ) , upperCamel , param0 , typeParams )
194
+ componentName , builderName , upperCamel , param0 , typeParams )
192
195
.render ();
193
196
}
194
197
@@ -202,26 +205,26 @@ String render() {
202
205
"""
203
206
204
207
/** Add new key/value pair to the {@code {{componentName}} } map. */
205
- public {{shortName}}Builder {{typeParams}} put{{upperCamel}}({{param0}} key, {{param1}} value) {
208
+ public {{builderName}} {{typeParams}} put{{upperCamel}}({{param0}} key, {{param1}} value) {
206
209
this.{{componentName}}.put(key, value);
207
210
return this;
208
211
}
209
212
""" )
210
213
public record MethodPut (
211
214
String componentName ,
212
- String shortName ,
215
+ String builderName ,
213
216
String upperCamel ,
214
217
String param0 ,
215
218
String param1 ,
216
219
String typeParams ) {
217
220
218
221
static String methodPut (
219
- String componentName , String shortName , String param0 , String param1 , String typeParams ) {
222
+ String componentName , String builderName , String param0 , String param1 , String typeParams ) {
220
223
String upperCamel =
221
224
Character .toUpperCase (componentName .charAt (0 )) + componentName .substring (1 );
222
225
223
226
return new MethodPut (
224
- componentName , shortName . replace ( "." , "$" ) , upperCamel , param0 , param1 , typeParams )
227
+ componentName , builderName , upperCamel , param0 , param1 , typeParams )
225
228
.render ();
226
229
}
227
230
0 commit comments