@@ -246,6 +246,12 @@ public @interface RecordBuilder {
|
||||
* name of that class.
|
||||
*/
|
||||
String fromWithClassName() default "_FromWith";
|
||||
|
||||
/**
|
||||
* If true, a functional-style builder is added so that record instances can be instantiated
|
||||
* without {@code new}.
|
||||
*/
|
||||
boolean addStaticBuilder() default true;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
|
||||
@@ -81,7 +81,9 @@ class InternalRecordBuilderProcessor {
|
||||
addBeanNestedClass();
|
||||
}
|
||||
addDefaultConstructor();
|
||||
if (metaData.addStaticBuilder()) {
|
||||
addStaticBuilder();
|
||||
}
|
||||
if (recordComponents.size() > 0) {
|
||||
addAllArgsConstructor();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.soabase.recordbuilder.test;
|
||||
|
||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||
|
||||
/**
|
||||
* Copyright 2019 Jordan Zimmerman
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@RecordBuilder.Options(addStaticBuilder = false)
|
||||
@RecordBuilder
|
||||
public record NoStaticBuilder(String foo) {
|
||||
}
|
||||
@@ -15,13 +15,14 @@
|
||||
*/
|
||||
package io.soabase.recordbuilder.test;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TestCustomMethodNames {
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestVariousOptions {
|
||||
|
||||
@Test
|
||||
public void builderGetsCustomSetterAndGetterNames() {
|
||||
@@ -54,4 +55,15 @@ public class TestCustomMethodNames {
|
||||
assertEquals(List.of(2), obj.getTheList());
|
||||
assertTrue(obj.isTheBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noStaticBuilder() {
|
||||
boolean hasStaticBuilder = Stream.of(NoStaticBuilderBuilder.class.getDeclaredMethods())
|
||||
.anyMatch(method -> method.getName().equals("NoStaticBuilder"));
|
||||
assertFalse(hasStaticBuilder);
|
||||
|
||||
hasStaticBuilder = Stream.of(SimpleRecordBuilder.class.getDeclaredMethods())
|
||||
.anyMatch(method -> method.getName().equals("SimpleRecord"));
|
||||
assertTrue(hasStaticBuilder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user