4
4
import com .google .common .annotations .VisibleForTesting ;
5
5
import com .google .common .base .Preconditions ;
6
6
7
+ import org .inferred .freebuilder .processor .BuildableType .MergeBuilderMethod ;
8
+ import org .inferred .freebuilder .processor .BuildableType .PartialToBuilderMethod ;
7
9
import org .inferred .freebuilder .processor .source .Excerpt ;
8
10
import org .inferred .freebuilder .processor .source .Type ;
9
11
@@ -48,8 +50,8 @@ public String toString() {
48
50
49
51
private Type type ;
50
52
private Type builderType ;
51
- private BuildableType . MergeBuilderMethod mergeBuilder ;
52
- private BuildableType . PartialToBuilderMethod partialToBuilder ;
53
+ private MergeBuilderMethod mergeBuilder ;
54
+ private PartialToBuilderMethod partialToBuilder ;
53
55
private BuilderFactory builderFactory ;
54
56
private Excerpt suppressUnchecked ;
55
57
private final EnumSet <Property > _unsetProperties = EnumSet .allOf (Property .class );
@@ -131,7 +133,7 @@ public Type builderType() {
131
133
* @return this {@code Builder} object
132
134
* @throws NullPointerException if {@code mergeBuilder} is null
133
135
*/
134
- public BuildableType .Builder mergeBuilder (BuildableType . MergeBuilderMethod mergeBuilder ) {
136
+ public BuildableType .Builder mergeBuilder (MergeBuilderMethod mergeBuilder ) {
135
137
this .mergeBuilder = Objects .requireNonNull (mergeBuilder );
136
138
_unsetProperties .remove (Property .MERGE_BUILDER );
137
139
return (BuildableType .Builder ) this ;
@@ -145,8 +147,7 @@ public BuildableType.Builder mergeBuilder(BuildableType.MergeBuilderMethod merge
145
147
* @throws NullPointerException if {@code mapper} is null or returns null
146
148
* @throws IllegalStateException if the field has not been set
147
149
*/
148
- public BuildableType .Builder mapMergeBuilder (
149
- UnaryOperator <BuildableType .MergeBuilderMethod > mapper ) {
150
+ public BuildableType .Builder mapMergeBuilder (UnaryOperator <MergeBuilderMethod > mapper ) {
150
151
Objects .requireNonNull (mapper );
151
152
return mergeBuilder (mapper .apply (mergeBuilder ()));
152
153
}
@@ -156,7 +157,7 @@ public BuildableType.Builder mapMergeBuilder(
156
157
*
157
158
* @throws IllegalStateException if the field has not been set
158
159
*/
159
- public BuildableType . MergeBuilderMethod mergeBuilder () {
160
+ public MergeBuilderMethod mergeBuilder () {
160
161
Preconditions .checkState (
161
162
!_unsetProperties .contains (Property .MERGE_BUILDER ), "mergeBuilder not set" );
162
163
return mergeBuilder ;
@@ -168,8 +169,7 @@ public BuildableType.MergeBuilderMethod mergeBuilder() {
168
169
* @return this {@code Builder} object
169
170
* @throws NullPointerException if {@code partialToBuilder} is null
170
171
*/
171
- public BuildableType .Builder partialToBuilder (
172
- BuildableType .PartialToBuilderMethod partialToBuilder ) {
172
+ public BuildableType .Builder partialToBuilder (PartialToBuilderMethod partialToBuilder ) {
173
173
this .partialToBuilder = Objects .requireNonNull (partialToBuilder );
174
174
_unsetProperties .remove (Property .PARTIAL_TO_BUILDER );
175
175
return (BuildableType .Builder ) this ;
@@ -183,8 +183,7 @@ public BuildableType.Builder partialToBuilder(
183
183
* @throws NullPointerException if {@code mapper} is null or returns null
184
184
* @throws IllegalStateException if the field has not been set
185
185
*/
186
- public BuildableType .Builder mapPartialToBuilder (
187
- UnaryOperator <BuildableType .PartialToBuilderMethod > mapper ) {
186
+ public BuildableType .Builder mapPartialToBuilder (UnaryOperator <PartialToBuilderMethod > mapper ) {
188
187
Objects .requireNonNull (mapper );
189
188
return partialToBuilder (mapper .apply (partialToBuilder ()));
190
189
}
@@ -194,7 +193,7 @@ public BuildableType.Builder mapPartialToBuilder(
194
193
*
195
194
* @throws IllegalStateException if the field has not been set
196
195
*/
197
- public BuildableType . PartialToBuilderMethod partialToBuilder () {
196
+ public PartialToBuilderMethod partialToBuilder () {
198
197
Preconditions .checkState (
199
198
!_unsetProperties .contains (Property .PARTIAL_TO_BUILDER ), "partialToBuilder not set" );
200
199
return partialToBuilder ;
@@ -272,93 +271,102 @@ public Excerpt suppressUnchecked() {
272
271
return suppressUnchecked ;
273
272
}
274
273
275
- /** Sets all property values using the given {@code BuildableType} as a template. */
274
+ /**
275
+ * Copies values from {@code value}.
276
+ *
277
+ * @return this {@code Builder} object
278
+ */
276
279
public BuildableType .Builder mergeFrom (BuildableType value ) {
277
- BuildableType_Builder _defaults = new BuildableType .Builder ();
278
- if (_defaults ._unsetProperties .contains (Property .TYPE )
279
- || !Objects .equals (value .type (), _defaults .type ())) {
280
+ BuildableType_Builder defaults = new BuildableType .Builder ();
281
+ if (defaults ._unsetProperties .contains (Property .TYPE )
282
+ || !Objects .equals (value .type (), defaults .type ())) {
280
283
type (value .type ());
281
284
}
282
- if (_defaults ._unsetProperties .contains (Property .BUILDER_TYPE )
283
- || !Objects .equals (value .builderType (), _defaults .builderType ())) {
285
+ if (defaults ._unsetProperties .contains (Property .BUILDER_TYPE )
286
+ || !Objects .equals (value .builderType (), defaults .builderType ())) {
284
287
builderType (value .builderType ());
285
288
}
286
- if (_defaults ._unsetProperties .contains (Property .MERGE_BUILDER )
287
- || !Objects .equals (value .mergeBuilder (), _defaults .mergeBuilder ())) {
289
+ if (defaults ._unsetProperties .contains (Property .MERGE_BUILDER )
290
+ || !Objects .equals (value .mergeBuilder (), defaults .mergeBuilder ())) {
288
291
mergeBuilder (value .mergeBuilder ());
289
292
}
290
- if (_defaults ._unsetProperties .contains (Property .PARTIAL_TO_BUILDER )
291
- || !Objects .equals (value .partialToBuilder (), _defaults .partialToBuilder ())) {
293
+ if (defaults ._unsetProperties .contains (Property .PARTIAL_TO_BUILDER )
294
+ || !Objects .equals (value .partialToBuilder (), defaults .partialToBuilder ())) {
292
295
partialToBuilder (value .partialToBuilder ());
293
296
}
294
- if (_defaults ._unsetProperties .contains (Property .BUILDER_FACTORY )
295
- || !Objects .equals (value .builderFactory (), _defaults .builderFactory ())) {
297
+ if (defaults ._unsetProperties .contains (Property .BUILDER_FACTORY )
298
+ || !Objects .equals (value .builderFactory (), defaults .builderFactory ())) {
296
299
builderFactory (value .builderFactory ());
297
300
}
298
- if (_defaults ._unsetProperties .contains (Property .SUPPRESS_UNCHECKED )
299
- || !Objects .equals (value .suppressUnchecked (), _defaults .suppressUnchecked ())) {
301
+ if (defaults ._unsetProperties .contains (Property .SUPPRESS_UNCHECKED )
302
+ || !Objects .equals (value .suppressUnchecked (), defaults .suppressUnchecked ())) {
300
303
suppressUnchecked (value .suppressUnchecked ());
301
304
}
302
305
return (BuildableType .Builder ) this ;
303
306
}
304
307
305
308
/**
306
- * Copies values from the given {@code Builder}. Does not affect any properties not set on the
307
- * input.
309
+ * Copies values from {@code template}, skipping unset properties.
310
+ *
311
+ * @return this {@code Builder} object
308
312
*/
309
313
public BuildableType .Builder mergeFrom (BuildableType .Builder template ) {
310
314
// Upcast to access private fields; otherwise, oddly, we get an access violation.
311
315
BuildableType_Builder base = template ;
312
- BuildableType_Builder _defaults = new BuildableType .Builder ();
316
+ BuildableType_Builder defaults = new BuildableType .Builder ();
313
317
if (!base ._unsetProperties .contains (Property .TYPE )
314
- && (_defaults ._unsetProperties .contains (Property .TYPE )
315
- || !Objects .equals (template .type (), _defaults .type ()))) {
318
+ && (defaults ._unsetProperties .contains (Property .TYPE )
319
+ || !Objects .equals (template .type (), defaults .type ()))) {
316
320
type (template .type ());
317
321
}
318
322
if (!base ._unsetProperties .contains (Property .BUILDER_TYPE )
319
- && (_defaults ._unsetProperties .contains (Property .BUILDER_TYPE )
320
- || !Objects .equals (template .builderType (), _defaults .builderType ()))) {
323
+ && (defaults ._unsetProperties .contains (Property .BUILDER_TYPE )
324
+ || !Objects .equals (template .builderType (), defaults .builderType ()))) {
321
325
builderType (template .builderType ());
322
326
}
323
327
if (!base ._unsetProperties .contains (Property .MERGE_BUILDER )
324
- && (_defaults ._unsetProperties .contains (Property .MERGE_BUILDER )
325
- || !Objects .equals (template .mergeBuilder (), _defaults .mergeBuilder ()))) {
328
+ && (defaults ._unsetProperties .contains (Property .MERGE_BUILDER )
329
+ || !Objects .equals (template .mergeBuilder (), defaults .mergeBuilder ()))) {
326
330
mergeBuilder (template .mergeBuilder ());
327
331
}
328
332
if (!base ._unsetProperties .contains (Property .PARTIAL_TO_BUILDER )
329
- && (_defaults ._unsetProperties .contains (Property .PARTIAL_TO_BUILDER )
330
- || !Objects .equals (template .partialToBuilder (), _defaults .partialToBuilder ()))) {
333
+ && (defaults ._unsetProperties .contains (Property .PARTIAL_TO_BUILDER )
334
+ || !Objects .equals (template .partialToBuilder (), defaults .partialToBuilder ()))) {
331
335
partialToBuilder (template .partialToBuilder ());
332
336
}
333
337
if (!base ._unsetProperties .contains (Property .BUILDER_FACTORY )
334
- && (_defaults ._unsetProperties .contains (Property .BUILDER_FACTORY )
335
- || !Objects .equals (template .builderFactory (), _defaults .builderFactory ()))) {
338
+ && (defaults ._unsetProperties .contains (Property .BUILDER_FACTORY )
339
+ || !Objects .equals (template .builderFactory (), defaults .builderFactory ()))) {
336
340
builderFactory (template .builderFactory ());
337
341
}
338
342
if (!base ._unsetProperties .contains (Property .SUPPRESS_UNCHECKED )
339
- && (_defaults ._unsetProperties .contains (Property .SUPPRESS_UNCHECKED )
340
- || !Objects .equals (template .suppressUnchecked (), _defaults .suppressUnchecked ()))) {
343
+ && (defaults ._unsetProperties .contains (Property .SUPPRESS_UNCHECKED )
344
+ || !Objects .equals (template .suppressUnchecked (), defaults .suppressUnchecked ()))) {
341
345
suppressUnchecked (template .suppressUnchecked ());
342
346
}
343
347
return (BuildableType .Builder ) this ;
344
348
}
345
349
346
- /** Resets the state of this builder. */
350
+ /**
351
+ * Resets the state of this builder.
352
+ *
353
+ * @return this {@code Builder} object
354
+ */
347
355
public BuildableType .Builder clear () {
348
- BuildableType_Builder _defaults = new BuildableType .Builder ();
349
- type = _defaults .type ;
350
- builderType = _defaults .builderType ;
351
- mergeBuilder = _defaults .mergeBuilder ;
352
- partialToBuilder = _defaults .partialToBuilder ;
353
- builderFactory = _defaults .builderFactory ;
354
- suppressUnchecked = _defaults .suppressUnchecked ;
356
+ BuildableType_Builder defaults = new BuildableType .Builder ();
357
+ type = defaults .type ;
358
+ builderType = defaults .builderType ;
359
+ mergeBuilder = defaults .mergeBuilder ;
360
+ partialToBuilder = defaults .partialToBuilder ;
361
+ builderFactory = defaults .builderFactory ;
362
+ suppressUnchecked = defaults .suppressUnchecked ;
355
363
_unsetProperties .clear ();
356
- _unsetProperties .addAll (_defaults ._unsetProperties );
364
+ _unsetProperties .addAll (defaults ._unsetProperties );
357
365
return (BuildableType .Builder ) this ;
358
366
}
359
367
360
368
/**
361
- * Returns a newly-created {@link BuildableType} based on the contents of the {@code Builder}.
369
+ * Returns a newly-created {@link BuildableType} based on the contents of this {@code Builder}.
362
370
*
363
371
* @throws IllegalStateException if any field has not been set
364
372
*/
@@ -384,8 +392,8 @@ public BuildableType buildPartial() {
384
392
private static final class Value extends BuildableType {
385
393
private final Type type ;
386
394
private final Type builderType ;
387
- private final BuildableType . MergeBuilderMethod mergeBuilder ;
388
- private final BuildableType . PartialToBuilderMethod partialToBuilder ;
395
+ private final MergeBuilderMethod mergeBuilder ;
396
+ private final PartialToBuilderMethod partialToBuilder ;
389
397
private final BuilderFactory builderFactory ;
390
398
private final Excerpt suppressUnchecked ;
391
399
@@ -409,12 +417,12 @@ public Type builderType() {
409
417
}
410
418
411
419
@ Override
412
- public BuildableType . MergeBuilderMethod mergeBuilder () {
420
+ public MergeBuilderMethod mergeBuilder () {
413
421
return mergeBuilder ;
414
422
}
415
423
416
424
@ Override
417
- public BuildableType . PartialToBuilderMethod partialToBuilder () {
425
+ public PartialToBuilderMethod partialToBuilder () {
418
426
return partialToBuilder ;
419
427
}
420
428
@@ -469,8 +477,8 @@ public String toString() {
469
477
private static final class Partial extends BuildableType {
470
478
private final Type type ;
471
479
private final Type builderType ;
472
- private final BuildableType . MergeBuilderMethod mergeBuilder ;
473
- private final BuildableType . PartialToBuilderMethod partialToBuilder ;
480
+ private final MergeBuilderMethod mergeBuilder ;
481
+ private final PartialToBuilderMethod partialToBuilder ;
474
482
private final BuilderFactory builderFactory ;
475
483
private final Excerpt suppressUnchecked ;
476
484
private final EnumSet <Property > _unsetProperties ;
@@ -502,15 +510,15 @@ public Type builderType() {
502
510
}
503
511
504
512
@ Override
505
- public BuildableType . MergeBuilderMethod mergeBuilder () {
513
+ public MergeBuilderMethod mergeBuilder () {
506
514
if (_unsetProperties .contains (Property .MERGE_BUILDER )) {
507
515
throw new UnsupportedOperationException ("mergeBuilder not set" );
508
516
}
509
517
return mergeBuilder ;
510
518
}
511
519
512
520
@ Override
513
- public BuildableType . PartialToBuilderMethod partialToBuilder () {
521
+ public PartialToBuilderMethod partialToBuilder () {
514
522
if (_unsetProperties .contains (Property .PARTIAL_TO_BUILDER )) {
515
523
throw new UnsupportedOperationException ("partialToBuilder not set" );
516
524
}
0 commit comments