File tree Expand file tree Collapse file tree 4 files changed +63
-10
lines changed
record-builder-processor/src/main/java/io/soabase/recordbuilder/processor
main/java/io/soabase/recordbuilder/test/staged
test/java/io/soabase/recordbuilder/test/staged Expand file tree Collapse file tree 4 files changed +63
-10
lines changed Original file line number Diff line number Diff line change @@ -196,10 +196,6 @@ private void addOnceOnlySupport() {
196
196
}
197
197
198
198
private void addStagedBuilderClasses () {
199
- if (recordComponents .size () < 2 ) {
200
- return ;
201
- }
202
-
203
199
IntStream .range (0 , recordComponents .size ()).forEach (index -> {
204
200
Optional <RecordClassType > nextComponent = ((index + 1 ) < recordComponents .size ())
205
201
? Optional .of (recordComponents .get (index + 1 )) : Optional .empty ();
@@ -723,10 +719,6 @@ private void addStaticDefaultBuilderMethod() {
723
719
}
724
720
725
721
private void addStaticStagedBuilderMethod (String builderMethodName ) {
726
- if (recordComponents .size () < 2 ) {
727
- return ;
728
- }
729
-
730
722
/*
731
723
* Adds the staged builder method similar to:
732
724
*
@@ -757,11 +749,12 @@ private void addStaticStagedBuilderMethod(String builderMethodName) {
757
749
codeBlock .addStatement (")" );
758
750
}
759
751
752
+ var returnType = stagedBuilderType (recordComponents .isEmpty () ? builderClassType : recordComponents .get (0 ));
753
+
760
754
var methodSpec = MethodSpec .methodBuilder (builderMethodName )
761
755
.addJavadoc ("Return the first stage of a staged builder\n " )
762
756
.addModifiers (Modifier .PUBLIC , Modifier .STATIC ).addAnnotation (generatedRecordBuilderAnnotation )
763
- .addTypeVariables (typeVariables ).returns (stagedBuilderType (recordComponents .get (0 )).typeName ())
764
- .addCode (codeBlock .build ()).build ();
757
+ .addTypeVariables (typeVariables ).returns (returnType .typeName ()).addCode (codeBlock .build ()).build ();
765
758
builder .addMethod (methodSpec );
766
759
}
767
760
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2019 The original author or authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package io .soabase .recordbuilder .test .staged ;
17
+
18
+ import io .soabase .recordbuilder .core .RecordBuilder ;
19
+
20
+ @ RecordBuilder
21
+ @ RecordBuilder .Options (builderMode = RecordBuilder .BuilderMode .STAGED )
22
+ public record NoFieldsStaged () {
23
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2019 The original author or authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package io .soabase .recordbuilder .test .staged ;
17
+
18
+ import io .soabase .recordbuilder .core .RecordBuilder ;
19
+
20
+ import java .time .Instant ;
21
+
22
+ @ RecordBuilder
23
+ @ RecordBuilder .Options (builderMode = RecordBuilder .BuilderMode .STAGED )
24
+ public record SingleFieldStaged (int i ) {
25
+ }
Original file line number Diff line number Diff line change @@ -61,4 +61,16 @@ void testGenericCombined() {
61
61
.aT (new GenericStaged <>("other" , builder .build (), BigInteger .TEN )).theUThing (BigDecimal .ONE ).build ();
62
62
assertEquals (obj1 , obj2 );
63
63
}
64
+
65
+ @ Test
66
+ void testSingleField () {
67
+ SingleFieldStaged obj = SingleFieldStagedBuilder .builder ().i (1 ).build ();
68
+ assertEquals (new SingleFieldStaged (1 ), obj );
69
+ }
70
+
71
+ @ Test
72
+ void testNoFields () {
73
+ NoFieldsStaged obj = NoFieldsStagedBuilder .builder ().build ();
74
+ assertEquals (new NoFieldsStaged (), obj );
75
+ }
64
76
}
You can’t perform that action at this time.
0 commit comments