@@ -142,46 +142,33 @@ public class ${class.name}
142
142
#end
143
143
144
144
/**
145
- * Constructor for this class, package protected .
145
+ * Constructor for this class, to be called from {@link Builder} and its subclasses .
146
146
* @see Builder#build()
147
147
*/
148
- ${class.name}(
149
- #if ( $class == $root )
150
- String namespaceUri,
151
- String modelEncoding,
152
- #end
153
- #foreach ( $field in $allFields )
154
- #set ( $sep = "#if(${locationTracking}||$field!=${allFields[${allFields.size()} - 1]}),#end" )
155
- #set ( $type = ${types.getOrDefault($field,${types.getOrDefault($field.type,$field.type)})} )
156
- #if ( $type.startsWith("List<") )
157
- #set ( $type = ${type.replace('List<','Collection<')} )
158
- #end
159
- $type $field.name${sep}
160
- #end
161
- #if ( $locationTracking )
162
- Map<Object, InputLocation> locations
163
- #end
164
- ) {
148
+ #set ( $additionalArguments = "#if(${locationTracking}), Map<Object, InputLocation> locations#end" )
149
+ protected ${class.name}(Builder builder${additionalArguments}) {
165
150
#if ( $class.superClass )
166
151
super(
167
- #foreach ( $field in $inheritedFields )
168
- #set ( $sep = "#if(${locationTracking}||$field!=${inheritedFields[${inheritedFields.size()} - 1]}),#end" )
169
- ${field.name}${sep}
170
- #end
152
+ #set ( $sep = "#if(${locationTracking}),#end" )
153
+ builder${sep}
171
154
#if ( $locationTracking )
172
155
locations
173
156
#end
174
157
);
175
158
#end
176
159
#if ( $class == $root )
177
- this.namespaceUri = namespaceUri;
178
- this.modelEncoding = modelEncoding;
160
+ this.namespaceUri = builder. namespaceUri;
161
+ this.modelEncoding = builder. modelEncoding;
179
162
#end
180
163
#foreach ( $field in $class.getFields($version) )
181
164
#if ( $field.type == "java.util.List" || $field.type == "java.util.Properties" || $field.type == "java.util.Map" )
182
- this.${field.name} = ImmutableCollections.copy(${field.name});
165
+ this.${field.name} = ImmutableCollections.copy(builder. ${field.name} != null ? builder.${field.name} : (builder.base != null ? builder.base.${field.name} : null) );
183
166
#else
184
- this.${field.name} = ${field.name};
167
+ #if ( $field.type == "boolean" || $field.type == "int" )
168
+ this.${field.name} = builder.${field.name} != null ? builder.${field.name} : (builder.base != null ? builder.base.${field.name} : ${field.defaultValue});
169
+ #else
170
+ this.${field.name} = builder.${field.name} != null ? builder.${field.name} : (builder.base != null ? builder.base.${field.name} : null);
171
+ #end
185
172
#end
186
173
#end
187
174
#if ( $locationTracking )
@@ -384,7 +371,7 @@ public class ${class.name}
384
371
Map<Object, InputLocation> locations;
385
372
#end
386
373
387
- Builder(boolean withDefaults) {
374
+ protected Builder(boolean withDefaults) {
388
375
#if ( $class.superClass )
389
376
super(withDefaults);
390
377
#end
@@ -402,7 +389,7 @@ public class ${class.name}
402
389
}
403
390
}
404
391
405
- Builder(${class.name} base, boolean forceCopy) {
392
+ protected Builder(${class.name} base, boolean forceCopy) {
406
393
#if ( $class.superClass )
407
394
super(base, forceCopy);
408
395
#end
@@ -480,23 +467,8 @@ public class ${class.name}
480
467
locations.put("${field.name}", newlocs.containsKey("${field.name}") ? newlocs.get("${field.name}") : oldlocs.get("${field.name}"));
481
468
#end
482
469
#end
483
- return new ${class.name}(
484
- #if ( $class == $root )
485
- namespaceUri != null ? namespaceUri : (base != null ? base.namespaceUri : ""),
486
- modelEncoding != null ? modelEncoding : (base != null ? base.modelEncoding : "UTF-8"),
487
- #end
488
- #foreach ( $field in $allFields )
489
- #set ( $sep = "#if(${locationTracking}||$field!=${allFields[${allFields.size()} - 1]}),#end" )
490
- #if ( $field.type == "boolean" || $field.type == "int" )
491
- ${field.name} != null ? ${field.name} : (base != null ? base.${field.name} : ${field.defaultValue})${sep}
492
- #else
493
- ${field.name} != null ? ${field.name} : (base != null ? base.${field.name} : null)${sep}
494
- #end
495
- #end
496
- #if ( $locationTracking )
497
- locations
498
- #end
499
- );
470
+ #set ( $additionalArguments = "#if(${locationTracking}), locations#end" )
471
+ return new ${class.name}(this${additionalArguments});
500
472
}
501
473
}
502
474
0 commit comments