├── .github ├── FUNDING.yml └── workflows │ ├── maven_java17.yml │ └── maven_java21.yml ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── README.md ├── customizing.md ├── deconstructors.md ├── mvnw ├── mvnw.cmd ├── options.md ├── pom.xml ├── record-builder-core ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── soabase │ └── recordbuilder │ └── core │ ├── DeconstructorFull.java │ ├── IgnoreDefaultMethod.java │ ├── RecordBuilder.java │ ├── RecordBuilderFull.java │ ├── RecordBuilderGenerated.java │ └── RecordInterface.java ├── record-builder-processor ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── soabase │ │ └── recordbuilder │ │ └── processor │ │ ├── ClassType.java │ │ ├── CollectionBuilderUtils.java │ │ ├── ElementUtils.java │ │ ├── IncludeHelper.java │ │ ├── InitializerUtil.java │ │ ├── InternalDeconstructorProcessor.java │ │ ├── InternalRecordBuilderProcessor.java │ │ ├── InternalRecordInterfaceProcessor.java │ │ ├── OptionalType.java │ │ ├── RecordBuilderOptions.java │ │ ├── RecordBuilderProcessor.java │ │ ├── RecordClassType.java │ │ └── RecordFacade.java │ └── resources │ └── META-INF │ ├── gradle │ └── incremental.annotation.processors │ └── services │ └── javax.annotation.processing.Processor ├── record-builder-test ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── soabase │ │ └── recordbuilder │ │ └── test │ │ ├── Annotated.java │ │ ├── BeanStyle.java │ │ ├── Builder.java │ │ ├── CollectionCopying.java │ │ ├── CollectionInterface.java │ │ ├── CollectionRecord.java │ │ ├── CollectionRecordConflicts.java │ │ ├── CustomMethodNames.java │ │ ├── CustomMethodNamesWithFunctionalMethods.java │ │ ├── Customer.java │ │ ├── DuplicateMethodNames.java │ │ ├── Empty.java │ │ ├── ExceptionDetails.java │ │ ├── FullRecord.java │ │ ├── HasDefaults.java │ │ ├── IgnoreAnnotated.java │ │ ├── IncludeWithOption.java │ │ ├── Initialized.java │ │ ├── InterfaceTemplateTest.java │ │ ├── MutableCollectionRecord.java │ │ ├── MyInterfaceTemplate.java │ │ ├── MyTemplate.java │ │ ├── Nested.java │ │ ├── NoBuilder.java │ │ ├── NoStaticBuilder.java │ │ ├── NonspecializedNullabeCollectionRecord.java │ │ ├── NullableCollectionRecord.java │ │ ├── NullableCollectionRecordInterpretingNotNulls.java │ │ ├── OnceOnly.java │ │ ├── Pair.java │ │ ├── Person.java │ │ ├── Point.java │ │ ├── PublicConstructor.java │ │ ├── RecordWithAnR.java │ │ ├── RecordWithDefaultNotNull.java │ │ ├── RecordWithOptional.java │ │ ├── RecordWithOptional2.java │ │ ├── RequestWithValid.java │ │ ├── RequiredRecord.java │ │ ├── RequiredRecord2.java │ │ ├── SimpleGenericRecord.java │ │ ├── SimpleRecord.java │ │ ├── SingleItems.java │ │ ├── SpecializedPerson.java │ │ ├── StrippedFeaturesRecord.java │ │ ├── TemplateTest.java │ │ ├── Thingy.java │ │ ├── UnmodifiableCollectionsRecord.java │ │ ├── Usage.java │ │ ├── WildcardSingleItems.java │ │ ├── deconstructors │ │ ├── ClassWithStaged.java │ │ ├── ComplexClass.java │ │ ├── GenericClass.java │ │ ├── InterfaceTest.java │ │ ├── MyClass.java │ │ ├── NoRecordBuilder.java │ │ ├── UniqueVarNameCheck.java │ │ ├── UniqueVarNameCheck2.java │ │ └── WithAnnotations.java │ │ ├── includes │ │ ├── IncludeFactory.java │ │ ├── JustATest.java │ │ └── pack │ │ │ ├── AlsoIgnoreMe.java │ │ │ ├── IgnoreMe.java │ │ │ ├── PackRecord1.java │ │ │ ├── PackRecord2.java │ │ │ └── PackRecord3.java │ │ ├── jacoco │ │ └── FullRecordForJacoco.java │ │ ├── naming │ │ ├── Builder.java │ │ └── ConvertRequest.java │ │ ├── package-info.java │ │ ├── staged │ │ ├── CombinedGenericStaged.java │ │ ├── CombinedSimpleStaged.java │ │ ├── GenericStaged.java │ │ ├── InitializedStaged.java │ │ ├── NoFieldsStaged.java │ │ ├── OptionalListStaged.java │ │ ├── OptionalStagedRequiredOnly.java │ │ ├── SimpleStaged.java │ │ └── SingleFieldStaged.java │ │ └── visibility │ │ ├── PackagePrivateRecord.java │ │ ├── PackagePrivateRecordWithPublicBuilder.java │ │ └── Wrapper.java │ └── test │ └── java │ └── io │ └── soabase │ └── recordbuilder │ └── test │ ├── TestAnnotated.java │ ├── TestCollections.java │ ├── TestCollectionsBuilder.java │ ├── TestDefaultNotNull.java │ ├── TestImmutableCollections.java │ ├── TestIncludes.java │ ├── TestInitialized.java │ ├── TestNullableCollectionsBuilder.java │ ├── TestOnceOnly.java │ ├── TestOptional.java │ ├── TestOptionsOnPackage.java │ ├── TestPublicConstructor.java │ ├── TestRecordBuilderFull.java │ ├── TestRecordInterface.java │ ├── TestSingleItems.java │ ├── TestTemplate.java │ ├── TestUnmodifiableCollectionsBuilder.java │ ├── TestValidation.java │ ├── TestVariousOptions.java │ ├── TestWithers.java │ ├── deconstructors │ └── TestGenericClass.java │ ├── staged │ └── TestStagedBuilder.java │ └── visibility │ └── TestVisibility.java ├── record-builder-validator ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── soabase │ └── recordbuilder │ └── validator │ └── RecordBuilderValidator.java └── src └── etc └── header.txt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: Randgalt 4 | -------------------------------------------------------------------------------- /.github/workflows/maven_java17.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Maven Build - Java 17 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 17 23 | - name: Build with Maven 24 | run: ./mvnw -B package --file pom.xml 25 | -------------------------------------------------------------------------------- /.github/workflows/maven_java21.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Maven Build - Java 21 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 21 23 | - name: Build with Maven 24 | run: ./mvnw -B package --file pom.xml -Djdk-version=21 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | .idea 3 | .classpath 4 | .project 5 | .settings/ 6 | **/target/** 7 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randgalt/record-builder/c4a6113607609503c65eb168edc331f2728223b6/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar 19 | -------------------------------------------------------------------------------- /customizing.md: -------------------------------------------------------------------------------- 1 | [◀︎ RecordBuilder](README.md) • Customizing RecordBuilder 2 | 3 | # RecordBuilderFull 4 | 5 | Note: `@RecordBuilderFull` has most optional features enabled. It's an alternate 6 | form of `@RecordBuilder` that uses the [templating mechanism](#create-a-custom-annotation) to 7 | enable optional features. 8 | 9 | # Customizing RecordBuilder 10 | 11 | RecordBuilder can be customized in a number of ways. The types of customizations will change over time. See 12 | [RecordBuilder Options](options.md) 13 | for the current set of customizations and their default values. For example, the `useImmutableCollections` option 14 | adds special handling for record components of type `java.util.List`, `java.util.Set`, `java.util.Map` and `java.util.Collection`. When the record is built, any components of these types are passed through an added shim method that uses the corresponding immutable collection (e.g. `List.copyOf(o)`) or an empty immutable collection if the component is `null`. 15 | 16 | You can: 17 | 18 | - [Customize an entire build](#customize-an-entire-build) - all uses of `@RecordBuilder` in your project 19 | - [Customize a single record](#customize-a-single-record) annotated with `@RecordBuilder` 20 | - [Create a custom annotation](#create-a-custom-annotation) that specifies your options and use that instead of `@RecordBuilder` 21 | 22 | ## Customize an entire build 23 | 24 | To customize an entire build, use javac's annotation processor options via `-A` on the command line. 25 | The options available are the same as the attributes in [@RecordBuilder.Options](record-builder-core/src/main/java/io/soabase/recordbuilder/core/RecordBuilder.java). 26 | i.e. to disable "prefixing enclosing class names", compile with: 27 | 28 | ```shell 29 | javac -AprefixEnclosingClassNames=false ... 30 | ``` 31 | 32 | _Note: use a separate `-A` for each option._ 33 | 34 | #### Maven 35 | 36 | If you are using Maven, specify the options in the compiler plugin: 37 | 38 | ```xml 39 | 40 | org.apache.maven.plugins 41 | maven-compiler-plugin 42 | ${maven-compiler-plugin-version} 43 | 44 | 45 | -AprefixEnclosingClassNames=false 46 | -AfileComment="something different" 47 | 48 | 49 | 50 | ``` 51 | 52 | #### Gradle 53 | 54 | For Gradle, specify the options: 55 | 56 | ```groovy 57 | compilerArgs.addAll(['-AprefixEnclosingClassNames=false', '-AfileComment="something different"']) 58 | ``` 59 | 60 | ## Customize a single record 61 | 62 | To customize a single record, add `@RecordBuilder.Options` ([options details](options.md)) in addition to 63 | `@RecordBuilder`. 64 | 65 | E.g. 66 | 67 | ```java 68 | @RecordBuilder.Options(withClassName = "Wither") 69 | @RecordBuilder 70 | public record MyRecord(String s){} 71 | ``` 72 | 73 | ## Create a custom annotation 74 | 75 | Using `@RecordBuilder.Template` you can create your own RecordBuilder annotation 76 | that uses the set of options you want. E.g. to create a custom annotation that 77 | uses an alternate file comment and an alternate With classname: 78 | 79 | ```java 80 | @RecordBuilder.Template(options = @RecordBuilder.Options( 81 | fileComment = "MyCo license", 82 | withClassName = "Wither" 83 | )) 84 | @Retention(RetentionPolicy.SOURCE) 85 | @Target(ElementType.TYPE) 86 | @Inherited 87 | public @interface MyCoRecordBuilder { 88 | } 89 | ``` 90 | 91 | Now, you can use `@MyCoRecordBuilder` instead of `@RecordBuilder` and the record 92 | will be built with options as specified. 93 | 94 | Note: the template mechanism also supports `@RecordInterface` templates via the `asRecordInterface` attribute. 95 | When it is set a `@RecordInterface` template is created instead. 96 | -------------------------------------------------------------------------------- /deconstructors.md: -------------------------------------------------------------------------------- 1 | [◀︎ RecordBuilder](README.md) • Deconstructors 2 | 3 | # Deconstructors 4 | 5 | Deconstructors have been proposed for a future JDK. RecordBuilder's deconstructor support is based on this proposal. See: https://github.com/openjdk/amber-docs/blob/master/eg-drafts/deconstruction-patterns-records-and-classes.md#deconstructors-for-classes. 6 | Quoting the proposal: 7 | 8 | > A deconstruction pattern can be thought of as the dual of a constructor; a constructor takes N state components and 9 | > aggregates them into an object, and a deconstruction pattern takes an object and decomposes it into N state components. 10 | 11 | JDK `record`s have implicit deconstructors that are used throughout the JDK for pattern matching, etc. However, standard 12 | Java classes do not have deconstructors. RecordBuilder can generate records and builders from deconstructor-style methods in any Java class. 13 | 14 | A deconstructor is a method in any class or interface that: 15 | 16 | - returns `void` 17 | - is not `static` 18 | - has one or more parameters of type: 19 | - `Consumer` 20 | - `IntConsumer` 21 | - `LongConsumer` 22 | - `DoubleConsumer` 23 | - is annotated with `@RecordBuilder.Deconstructor` 24 | 25 | When RecordBuilder encounters a deconstructor method it generates a `record` that matches the deconstructor's parameters 26 | and, optionally, creates a record builder for it. 27 | The record's components are the same as the implied types of the deconstructor's parameters. The `record` will have a static 28 | method named `from` (you can change this) that 29 | takes an instance of the class containing the deconstructor method and returns an instance of the generated `record`. 30 | In other words, it deconstructs the class instance into a data access object that can be used in pattern matching, 31 | etc. 32 | 33 | ## Example 34 | 35 | Given this POJO: 36 | 37 | ```java 38 | public class MyClass { 39 | private final int qty; 40 | private final String name; 41 | 42 | public MyClass(int qty, String name) { 43 | this.qty = qty; 44 | this.name = name; 45 | } 46 | 47 | @Deconstructor 48 | public void deconstructor(IntConsumer qty, Consumer name) { 49 | qty.accept(this.qty); 50 | name.accept(this.name); 51 | } 52 | } 53 | ``` 54 | 55 | RecordBuilder will generate a `record` (and record builder) similar to: 56 | 57 | ```java 58 | public record MyClassDao(int qty, String name) { 59 | public static MyClassDao from(MyClass rhs) { 60 | MyClassDaoBuilder builder = MyClassDaoBuilder.builder(); 61 | rhs.deconstructor(builder::qty, builder::name); 62 | return builder.build(); 63 | } 64 | } 65 | ``` 66 | 67 | You can use it in switch statements, etc.: 68 | 69 | ```java 70 | MyClass myClass = ... 71 | 72 | switch (MyClassDao.from(myClass)) { 73 | case MyClassDao(var qty, var name) when qty > 0 -> ... 74 | case MyClassDao(var qty, var name) when qty == 0 -> ... 75 | case MyClassDao(var qty, var name) when name.isEmpty() -> ... 76 | ... etc. ... 77 | } 78 | ``` 79 | 80 | ## Options 81 | 82 | The `@RecordBuilder.Deconstructor` annotation has several options that control how the record is generated. 83 | See [the definition](record-builder-core/src/main/java/io/soabase/recordbuilder/core/RecordBuilder.java) for details. 84 | 85 | When `addRecordBuilder()` is `true` a RecordBuilder is created for the generated record. You can add 86 | a `@RecordBuilder.Options` annotation to the deconstructor method to control how the record builder is generated. 87 | You can also create a `@DeconstructorTemplate` to build a custom deconstructor annotation. It is created 88 | in the same manner as a custom `@Template` annotation. See [Customizing](customizing.md#create-a-custom-annotation) for details. 89 | 90 | A pre-built template, `@DeconstructorFull` can be used which is an analog to `@RecordBuilderFull`. 91 | -------------------------------------------------------------------------------- /record-builder-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | io.soabase.record-builder 22 | record-builder 23 | 48-SNAPSHOT 24 | 25 | 4.0.0 26 | 27 | record-builder-core 28 | 29 | 30 | ${project.parent.basedir}/src/etc/header.txt 31 | io.soabase.recordbuilder.core 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /record-builder-core/src/main/java/io/soabase/recordbuilder/core/DeconstructorFull.java: -------------------------------------------------------------------------------- 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.core; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * An alternate form of {@code @Deconstructor} that has most optional features turned on for the generated record 22 | * builder 23 | */ 24 | @RecordBuilder.DeconstructorTemplate(options = @RecordBuilder.Options(interpretNotNulls = true, useImmutableCollections = true, addSingleItemCollectionBuilders = true, addFunctionalMethodsToWith = true, addClassRetainedGenerated = true)) 25 | @Retention(RetentionPolicy.SOURCE) 26 | @Target(ElementType.METHOD) 27 | @Inherited 28 | public @interface DeconstructorFull { 29 | } 30 | -------------------------------------------------------------------------------- /record-builder-core/src/main/java/io/soabase/recordbuilder/core/IgnoreDefaultMethod.java: -------------------------------------------------------------------------------- 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.core; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Retention(RetentionPolicy.SOURCE) 24 | @Target(ElementType.METHOD) 25 | public @interface IgnoreDefaultMethod { 26 | } 27 | -------------------------------------------------------------------------------- /record-builder-core/src/main/java/io/soabase/recordbuilder/core/RecordBuilderFull.java: -------------------------------------------------------------------------------- 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.core; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * An alternate form of {@code @RecordBuilder} that has most optional features turned on 22 | */ 23 | @RecordBuilder.Template(options = @RecordBuilder.Options(interpretNotNulls = true, useImmutableCollections = true, addSingleItemCollectionBuilders = true, addFunctionalMethodsToWith = true, addClassRetainedGenerated = true)) 24 | @Retention(RetentionPolicy.SOURCE) 25 | @Target({ ElementType.TYPE, ElementType.METHOD }) 26 | @Inherited 27 | public @interface RecordBuilderFull { 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-core/src/main/java/io/soabase/recordbuilder/core/RecordBuilderGenerated.java: -------------------------------------------------------------------------------- 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.core; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.*; 23 | 24 | /** 25 | * Jacoco ignores classes and methods annotated with `*Generated` 26 | */ 27 | @Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, PARAMETER }) 28 | @Retention(RetentionPolicy.CLASS) 29 | public @interface RecordBuilderGenerated { 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-core/src/main/java/io/soabase/recordbuilder/core/RecordInterface.java: -------------------------------------------------------------------------------- 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.core; 17 | 18 | import java.lang.annotation.*; 19 | 20 | @Retention(RetentionPolicy.SOURCE) 21 | @Target(ElementType.TYPE) 22 | @Inherited 23 | public @interface RecordInterface { 24 | boolean addRecordBuilder() default true; 25 | 26 | @Target({ ElementType.TYPE, ElementType.PACKAGE }) 27 | @Retention(RetentionPolicy.SOURCE) 28 | @Inherited 29 | @interface Include { 30 | /** 31 | * @return collection of classes to include 32 | */ 33 | Class[] value() default {}; 34 | 35 | /** 36 | * Synonym for {@code value()}. When using the other attributes it maybe clearer to use {@code classes()} 37 | * instead of {@code value()}. Note: both attributes are applied (i.e. a union of classes from both attributes). 38 | * 39 | * @return collection of classes 40 | */ 41 | Class[] classes() default {}; 42 | 43 | /** 44 | * If true the generated record is annotated with {@code @RecordBuilder} 45 | * 46 | * @return true/false 47 | */ 48 | boolean addRecordBuilder() default true; 49 | 50 | /** 51 | * Pattern used to generate the package for the generated class. The value is the literal package name however 52 | * two replacement values can be used. '@' is replaced with the package of the {@code Include} annotation. '*' 53 | * is replaced with the package of the included class. 54 | * 55 | * @return package pattern 56 | */ 57 | String packagePattern() default "@"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /record-builder-processor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | io.soabase.record-builder 22 | record-builder 23 | 48-SNAPSHOT 24 | 25 | 4.0.0 26 | 27 | record-builder-processor 28 | 29 | 30 | ${project.parent.basedir}/src/etc/header.txt 31 | none 32 | 33 | 34 | 35 | 36 | io.soabase.java-composer 37 | java-composer 38 | 39 | 40 | 41 | io.soabase.record-builder 42 | record-builder-core 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/ClassType.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import com.squareup.javapoet.TypeName; 19 | 20 | public class ClassType { 21 | private final TypeName typeName; 22 | private final String name; 23 | 24 | public ClassType(TypeName typeName, String name) { 25 | this.typeName = typeName; 26 | this.name = name; 27 | } 28 | 29 | public TypeName typeName() { 30 | return typeName; 31 | } 32 | 33 | public String name() { 34 | return name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/IncludeHelper.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import javax.annotation.processing.ProcessingEnvironment; 19 | import javax.lang.model.element.*; 20 | import javax.lang.model.type.TypeMirror; 21 | import javax.tools.Diagnostic; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | class IncludeHelper { 27 | private final boolean isValid; 28 | private final List classTypeElements; 29 | private final Map annotationValues; 30 | 31 | IncludeHelper(ProcessingEnvironment processingEnv, Element element, AnnotationMirror annotationMirror, 32 | boolean packagesSupported) { 33 | annotationValues = processingEnv.getElementUtils().getElementValuesWithDefaults(annotationMirror); 34 | var value = ElementUtils.getAnnotationValue(annotationValues, "value"); 35 | var classes = ElementUtils.getAnnotationValue(annotationValues, "classes"); 36 | var packages = ElementUtils.getAnnotationValue(annotationValues, "packages"); 37 | var isValid = true; 38 | var classTypeElements = new ArrayList(); 39 | if (value.isPresent() || classes.isPresent() || packages.isPresent()) { 40 | var valueList = value.map(ElementUtils::getAttributeTypeMirrorList).orElseGet(List::of); 41 | var classesList = classes.map(ElementUtils::getAttributeTypeMirrorList).orElseGet(List::of); 42 | var packagesList = packages.map(ElementUtils::getAttributeStringList).orElseGet(List::of); 43 | if (valueList.isEmpty() && classesList.isEmpty() && packagesList.isEmpty()) { 44 | if (packagesSupported) { 45 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 46 | "At least one of \"value\", \"classes\" or \"packages\" required", element); 47 | } else { 48 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 49 | "At least one of \"value\" or \"classes\" required", element); 50 | } 51 | isValid = false; 52 | } 53 | isValid = processList(processingEnv, isValid, element, valueList, classTypeElements); 54 | isValid = processList(processingEnv, isValid, element, classesList, classTypeElements); 55 | packages.ifPresent(annotationValue -> processPackages(processingEnv, classTypeElements, packagesList)); 56 | } else { 57 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not read attribute for annotation", 58 | element); 59 | isValid = false; 60 | } 61 | this.isValid = isValid; 62 | this.classTypeElements = List.copyOf(classTypeElements); 63 | } 64 | 65 | Map getAnnotationValues() { 66 | return annotationValues; 67 | } 68 | 69 | boolean isValid() { 70 | return isValid; 71 | } 72 | 73 | List getClassTypeElements() { 74 | return classTypeElements; 75 | } 76 | 77 | private boolean processList(ProcessingEnvironment processingEnv, boolean isValid, Element element, 78 | List list, ArrayList classTypeElements) { 79 | for (var typeMirror : list) { 80 | TypeElement typeElement = (TypeElement) processingEnv.getTypeUtils().asElement(typeMirror); 81 | if (typeElement == null) { 82 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 83 | "Could not get element for: " + typeMirror, element); 84 | isValid = false; 85 | } else { 86 | classTypeElements.add(typeElement); 87 | } 88 | } 89 | return isValid; 90 | } 91 | 92 | private void processPackages(ProcessingEnvironment processingEnv, List classTypeElements, 93 | List packagesList) { 94 | for (var packageName : packagesList) { 95 | var packageElement = processingEnv.getElementUtils().getPackageElement(packageName); 96 | for (var child : packageElement.getEnclosedElements()) { 97 | if (child.getKind() == ElementKind.RECORD) { 98 | classTypeElements.add((TypeElement) child); 99 | } 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/InitializerUtil.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import com.squareup.javapoet.CodeBlock; 19 | import io.soabase.recordbuilder.core.RecordBuilder; 20 | 21 | import javax.annotation.processing.ProcessingEnvironment; 22 | import javax.lang.model.element.*; 23 | import javax.tools.Diagnostic; 24 | import java.util.Map; 25 | import java.util.Optional; 26 | import java.util.stream.Collectors; 27 | import java.util.stream.Stream; 28 | 29 | import static io.soabase.recordbuilder.processor.ElementUtils.getAnnotationValue; 30 | import static io.soabase.recordbuilder.processor.ElementUtils.getStringAttribute; 31 | 32 | class InitializerUtil { 33 | static Map detectInitializers(ProcessingEnvironment processingEnv, TypeElement record) { 34 | return record.getEnclosedElements().stream().flatMap(element -> { 35 | var annotation = ElementUtils.findAnnotationMirror(processingEnv, element, 36 | RecordBuilder.Initializer.class.getName().replace("$", ".")); 37 | var value = annotation.flatMap(mirror -> getAnnotationValue(mirror.getElementValues(), "value")); 38 | if (value.isEmpty()) { 39 | return Stream.of(); 40 | } 41 | 42 | var source = annotation.flatMap(mirror -> getAnnotationValue(mirror.getElementValues(), "source")); 43 | 44 | var name = getStringAttribute(value.get(), ""); 45 | var sourceElement = findSourceElement(processingEnv, record, source); 46 | 47 | Optional initializer = sourceElement.getEnclosedElements().stream() 48 | .filter(enclosedElement -> enclosedElement.getSimpleName().toString().equals(name)) 49 | .flatMap(enclosedElement -> { 50 | if ((enclosedElement.getKind() == ElementKind.METHOD) 51 | && isValid(processingEnv, element, (ExecutableElement) enclosedElement)) { 52 | return Stream.of(CodeBlock.builder().add("$T.$L()", sourceElement, name).build()); 53 | } 54 | 55 | if ((enclosedElement.getKind() == ElementKind.FIELD) 56 | && isValid(processingEnv, element, (VariableElement) enclosedElement)) { 57 | return Stream.of(CodeBlock.builder().add("$T.$L", sourceElement, name).build()); 58 | } 59 | 60 | return Stream.of(); 61 | }).findFirst(); 62 | 63 | if (initializer.isEmpty()) { 64 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 65 | "No matching public static field or method found for initializer named: " + name, element); 66 | } 67 | 68 | return initializer.map(codeBlock -> Map.entry(element.getSimpleName().toString(), codeBlock)).stream(); 69 | }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); 70 | } 71 | 72 | private static boolean isValid(ProcessingEnvironment processingEnv, Element element, 73 | ExecutableElement executableElement) { 74 | if (executableElement.getModifiers().contains(Modifier.PUBLIC) 75 | && executableElement.getModifiers().contains(Modifier.STATIC)) { 76 | return processingEnv.getTypeUtils().isSameType(executableElement.getReturnType(), element.asType()); 77 | } 78 | return false; 79 | } 80 | 81 | private static boolean isValid(ProcessingEnvironment processingEnv, Element element, 82 | VariableElement variableElement) { 83 | if (variableElement.getModifiers().contains(Modifier.PUBLIC) 84 | && variableElement.getModifiers().contains(Modifier.STATIC) 85 | && variableElement.getModifiers().contains(Modifier.FINAL)) { 86 | return processingEnv.getTypeUtils().isSameType(variableElement.asType(), element.asType()); 87 | } 88 | return false; 89 | } 90 | 91 | private static TypeElement findSourceElement(ProcessingEnvironment processingEnv, TypeElement record, 92 | Optional source) { 93 | return source.flatMap(ElementUtils::getAttributeTypeMirror) 94 | .map(sourceMirror -> (TypeElement) processingEnv.getTypeUtils().asElement(sourceMirror)).orElse(record); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/OptionalType.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import java.util.Optional; 19 | import java.util.OptionalDouble; 20 | import java.util.OptionalInt; 21 | import java.util.OptionalLong; 22 | 23 | import com.squareup.javapoet.ParameterizedTypeName; 24 | import com.squareup.javapoet.TypeName; 25 | 26 | public record OptionalType(TypeName typeName, TypeName valueType) { 27 | 28 | private static final TypeName optionalType = TypeName.get(Optional.class); 29 | private static final TypeName optionalIntType = TypeName.get(OptionalInt.class); 30 | private static final TypeName optionalLongType = TypeName.get(OptionalLong.class); 31 | private static final TypeName optionalDoubleType = TypeName.get(OptionalDouble.class); 32 | 33 | private static boolean isOptional(ClassType component) { 34 | if (component.typeName().equals(optionalType)) { 35 | return true; 36 | } 37 | return (component.typeName() instanceof ParameterizedTypeName parameterizedTypeName) 38 | && parameterizedTypeName.rawType.equals(optionalType); 39 | } 40 | 41 | static Optional fromClassType(final ClassType component) { 42 | if (isOptional(component)) { 43 | if (!(component.typeName() instanceof ParameterizedTypeName parameterizedType)) { 44 | return Optional.of(new OptionalType(optionalType, TypeName.get(Object.class))); 45 | } 46 | final TypeName containingType = parameterizedType.typeArguments.isEmpty() ? TypeName.get(Object.class) 47 | : parameterizedType.typeArguments.get(0); 48 | return Optional.of(new OptionalType(optionalType, containingType)); 49 | } 50 | if (component.typeName().equals(optionalIntType)) { 51 | return Optional.of(new OptionalType(optionalIntType, TypeName.get(int.class))); 52 | } 53 | if (component.typeName().equals(optionalLongType)) { 54 | return Optional.of(new OptionalType(optionalLongType, TypeName.get(long.class))); 55 | } 56 | if (component.typeName().equals(optionalDoubleType)) { 57 | return Optional.of(new OptionalType(optionalDoubleType, TypeName.get(double.class))); 58 | } 59 | return Optional.empty(); 60 | } 61 | 62 | public boolean isOptional() { 63 | return typeName.equals(optionalType); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderOptions.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import java.lang.reflect.Method; 20 | import java.lang.reflect.Proxy; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import java.util.Set; 24 | import java.util.stream.Collectors; 25 | import java.util.stream.Stream; 26 | 27 | class RecordBuilderOptions { 28 | private static final Map defaultValues = buildDefaultValues(); 29 | 30 | static RecordBuilder.Options build(Map options) { 31 | return (RecordBuilder.Options) Proxy.newProxyInstance(RecordBuilderOptions.class.getClassLoader(), 32 | new Class[] { RecordBuilder.Options.class }, (proxy, method, args) -> { 33 | var name = method.getName(); 34 | var defaultValue = defaultValues.get(name); 35 | var option = options.get(name); 36 | if (option != null) { 37 | if (defaultValue instanceof String) { 38 | return option; 39 | } 40 | if (defaultValue instanceof Boolean) { 41 | return Boolean.parseBoolean(option); 42 | } 43 | if (defaultValue instanceof Integer) { 44 | return Integer.parseInt(option); 45 | } 46 | if (defaultValue instanceof Long) { 47 | return Long.parseLong(option); 48 | } 49 | if (defaultValue instanceof Double) { 50 | return Double.parseDouble(option); 51 | } 52 | if (defaultValue instanceof RecordBuilder.BuilderMode) { 53 | return RecordBuilder.BuilderMode.valueOf(option); 54 | } 55 | throw new IllegalArgumentException("Unhandled option type: " + defaultValue.getClass()); 56 | } 57 | return defaultValue; 58 | }); 59 | } 60 | 61 | static Set optionNames() { 62 | return Stream.of(RecordBuilder.Options.class.getDeclaredMethods()).map(Method::getName) 63 | .collect(Collectors.toUnmodifiableSet()); 64 | } 65 | 66 | private static Map buildDefaultValues() { 67 | var workMap = new HashMap(); 68 | for (Method method : RecordBuilder.Options.class.getDeclaredMethods()) { 69 | workMap.put(method.getName(), method.getDefaultValue()); 70 | } 71 | workMap.put("toString", "Generated RecordBuilder.Options"); 72 | return Map.copyOf(workMap); 73 | } 74 | 75 | private RecordBuilderOptions() { 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordClassType.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import com.squareup.javapoet.TypeName; 19 | 20 | import javax.lang.model.element.AnnotationMirror; 21 | import java.util.List; 22 | 23 | public class RecordClassType extends ClassType { 24 | private final TypeName rawTypeName; 25 | private final List accessorAnnotations; 26 | private final List canonicalConstructorAnnotations; 27 | 28 | public RecordClassType(TypeName typeName, TypeName rawTypeName, String name, 29 | List accessorAnnotations, 30 | List canonicalConstructorAnnotations) { 31 | super(typeName, name); 32 | this.rawTypeName = rawTypeName; 33 | this.accessorAnnotations = accessorAnnotations; 34 | this.canonicalConstructorAnnotations = canonicalConstructorAnnotations; 35 | } 36 | 37 | public TypeName rawTypeName() { 38 | return rawTypeName; 39 | } 40 | 41 | public List getAccessorAnnotations() { 42 | return accessorAnnotations; 43 | } 44 | 45 | public List getCanonicalConstructorAnnotations() { 46 | return canonicalConstructorAnnotations; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordFacade.java: -------------------------------------------------------------------------------- 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.processor; 17 | 18 | import com.squareup.javapoet.CodeBlock; 19 | import com.squareup.javapoet.TypeVariableName; 20 | import io.soabase.recordbuilder.core.RecordBuilder; 21 | 22 | import javax.annotation.processing.ProcessingEnvironment; 23 | import javax.lang.model.element.*; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Optional; 27 | import java.util.Set; 28 | import java.util.stream.Collectors; 29 | import java.util.stream.IntStream; 30 | 31 | import static io.soabase.recordbuilder.processor.ElementUtils.generateName; 32 | 33 | record RecordFacade(Element element, String packageName, ClassType recordClassType, ClassType builderClassType, 34 | List typeVariables, List recordComponents, 35 | Map initializers, Set modifiers, boolean builderIsInRecordPackage) { 36 | public static RecordFacade fromTypeElement(ProcessingEnvironment processingEnv, TypeElement record, 37 | Optional packageNameOpt, RecordBuilder.Options metaData) { 38 | String recordActualPackage = ElementUtils.getPackageName(record); 39 | String packageName = packageNameOpt.orElse(recordActualPackage); 40 | ClassType recordClassType = ElementUtils.getClassType(record, record.getTypeParameters()); 41 | ClassType builderClassType = ElementUtils.getClassType(packageName, 42 | generateName(record, recordClassType, metaData.suffix(), metaData.prefixEnclosingClassNames()), 43 | record.getTypeParameters()); 44 | List typeVariables = record.getTypeParameters().stream().map(TypeVariableName::get) 45 | .collect(Collectors.toList()); 46 | List recordComponents = buildRecordComponents(processingEnv, record); 47 | Map initializers = InitializerUtil.detectInitializers(processingEnv, record); 48 | 49 | return new RecordFacade(record, packageName, recordClassType, builderClassType, typeVariables, recordComponents, 50 | initializers, record.getModifiers(), recordActualPackage.equals(packageName)); 51 | } 52 | 53 | private static List buildRecordComponents(ProcessingEnvironment processingEnv, 54 | TypeElement record) { 55 | var accessorAnnotations = record.getRecordComponents().stream().map(e -> (e.getAccessor() != null) ? e.getAccessor().getAnnotationMirrors() : List.of()).collect(Collectors.toList()); 56 | var canonicalConstructorAnnotations = ElementUtils.findCanonicalConstructor(record) 57 | .map(constructor -> ((ExecutableElement) constructor).getParameters().stream() 58 | .map(Element::getAnnotationMirrors).collect(Collectors.toList())) 59 | .orElse(List.of()); 60 | var recordComponents = record.getRecordComponents(); 61 | return IntStream.range(0, recordComponents.size()).mapToObj(index -> { 62 | var thisAccessorAnnotations = (accessorAnnotations.size() > index) ? accessorAnnotations.get(index) 63 | : List. of(); 64 | var thisCanonicalConstructorAnnotations = (canonicalConstructorAnnotations.size() > index) 65 | ? canonicalConstructorAnnotations.get(index) : List. of(); 66 | return ElementUtils.getRecordClassType(processingEnv, recordComponents.get(index), thisAccessorAnnotations, 67 | thisCanonicalConstructorAnnotations); 68 | }).collect(Collectors.toList()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors: -------------------------------------------------------------------------------- 1 | io.soabase.recordbuilder.processor.RecordBuilderProcessor,isolating 2 | -------------------------------------------------------------------------------- /record-builder-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | io.soabase.recordbuilder.processor.RecordBuilderProcessor -------------------------------------------------------------------------------- /record-builder-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | io.soabase.record-builder 22 | record-builder 23 | 48-SNAPSHOT 24 | 25 | 4.0.0 26 | 27 | record-builder-test 28 | 29 | 30 | ${project.parent.basedir}/src/etc/header.txt 31 | true 32 | true 33 | 34 | 35 | 36 | 37 | javax.validation 38 | validation-api 39 | 40 | 41 | 42 | jakarta.validation 43 | jakarta.validation-api 44 | 45 | 46 | 47 | io.soabase.record-builder 48 | record-builder-processor 49 | provided 50 | 51 | 52 | 53 | io.soabase.record-builder 54 | record-builder-validator 55 | 56 | 57 | 58 | org.hibernate.validator 59 | hibernate-validator 60 | provided 61 | 62 | 63 | 64 | org.glassfish 65 | javax.el 66 | provided 67 | 68 | 69 | 70 | org.junit.jupiter 71 | junit-jupiter 72 | test 73 | 74 | 75 | 76 | org.assertj 77 | assertj-core 78 | test 79 | 80 | 81 | 82 | 83 | 84 | 85 | org.jacoco 86 | jacoco-maven-plugin 87 | 88 | 89 | default-prepare-agent 90 | 91 | prepare-agent 92 | 93 | 94 | 95 | default-report 96 | 97 | report 98 | 99 | 100 | 101 | default-check 102 | 103 | check 104 | 105 | 106 | 107 | io/soabase/recordbuilder/test/jacoco/* 108 | 109 | 110 | 111 | BUNDLE 112 | 113 | 114 | COMPLEXITY 115 | COVEREDRATIO 116 | 0.60 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Annotated.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import javax.validation.constraints.Max; 20 | import javax.validation.constraints.Min; 21 | import javax.validation.constraints.NotNull; 22 | import javax.validation.constraints.Null; 23 | 24 | @RecordBuilder 25 | public record Annotated(@NotNull @Null String hey, @Min(10) @Max(100) int i, double d) { 26 | } 27 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/BeanStyle.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordInterface; 19 | import java.time.Instant; 20 | 21 | @RecordInterface 22 | public interface BeanStyle { 23 | String getName(); 24 | 25 | Instant getDate(); 26 | 27 | boolean isSomething(); 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Builder.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import io.soabase.recordbuilder.core.RecordInterface; 20 | 21 | @RecordInterface.Include({ Thingy.class }) 22 | @RecordBuilder.Include({ Nested.NestedRecord.class }) 23 | public class Builder { 24 | } 25 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/CollectionCopying.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.time.Instant; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | @RecordBuilder 27 | @RecordBuilder.Options(addSingleItemCollectionBuilders = true, useImmutableCollections = true, mutableListClassName = "PersonalizedMutableList") 28 | public record CollectionCopying(List list, Set set, Map map, Collection collection, 29 | int count) implements CollectionCopyingBuilder.With { 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/CollectionInterface.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import io.soabase.recordbuilder.core.RecordInterface; 20 | 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | @RecordInterface 27 | @RecordBuilder.Options(useImmutableCollections = true) 28 | public interface CollectionInterface { 29 | List l(); 30 | 31 | Set s(); 32 | 33 | Map m(); 34 | 35 | Collection c(); 36 | } 37 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/CollectionRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.time.Instant; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | @RecordBuilder 27 | @RecordBuilder.Options(useImmutableCollections = true, addFunctionalMethodsToWith = true) 28 | public record CollectionRecord(List l, Set s, Map m, Collection c) 29 | implements CollectionRecordBuilder.With { 30 | public static void main(String[] args) { 31 | var r = new CollectionRecord<>(List.of("hey"), Set.of("there"), Map.of("one", new Point(10, 20)), 32 | Set.of(new Point(30, 40))); 33 | Instant now = r.map((l1, s1, m1, c1) -> Instant.now()); 34 | r.accept((l1, s1, m1, c1) -> { 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/CollectionRecordConflicts.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.Collection; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | @RecordBuilder 26 | @RecordBuilder.Options(useImmutableCollections = true) 27 | public record CollectionRecordConflicts(List __list, Set __set, Map __map, 28 | Collection __collection) implements CollectionRecordConflictsBuilder.With { 29 | } 30 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/CustomMethodNames.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import io.soabase.recordbuilder.core.RecordBuilder; 22 | import io.soabase.recordbuilder.test.CustomMethodNamesBuilder.Bean; 23 | 24 | @RecordBuilder 25 | @RecordBuilder.Options(setterPrefix = "set", getterPrefix = "get", booleanPrefix = "is", beanClassName = "Bean") 26 | public record CustomMethodNames(Map kvMap, int theValue, List theList, boolean theBoolean) 27 | implements Bean, CustomMethodNamesBuilder.With { 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/CustomMethodNamesWithFunctionalMethods.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import io.soabase.recordbuilder.core.RecordBuilder; 22 | 23 | @RecordBuilder 24 | @RecordBuilder.Options(getterPrefix = "get", booleanPrefix = "is", addFunctionalMethodsToWith = true) 25 | public record CustomMethodNamesWithFunctionalMethods(Map kvMap, int theValue, List theList, 26 | boolean theBoolean) implements CustomMethodNamesWithFunctionalMethodsBuilder.With { 27 | } 28 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Customer.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.time.Instant; 19 | 20 | public interface Customer { 21 | String name(); 22 | 23 | String address(); 24 | 25 | Instant activeDate(); 26 | } 27 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/DuplicateMethodNames.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | @RecordBuilder.Options(builderMode = RecordBuilder.BuilderMode.STANDARD_AND_STAGED, builderMethodName = "notBuilder", buildMethodName = "notBuild", stagedBuilderMethodName = "notStagedBuilder") 22 | public record DuplicateMethodNames(int builder, int build, int from, int stream, int stagedBuilder) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Empty.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | public record Empty() implements EmptyBuilder.With { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/ExceptionDetails.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.lang.model.type.ErrorType; 21 | import java.util.List; 22 | 23 | @RecordBuilder 24 | public record ExceptionDetails(String internalMessage, String endUserMessage, String httpStatus, ErrorType errorType, 25 | List jsonProblems, Throwable cause) { 26 | @Override 27 | public List jsonProblems() { 28 | if (jsonProblems == null) { 29 | return List.of(); 30 | } 31 | return jsonProblems; 32 | } 33 | } -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/FullRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilderFull; 19 | 20 | import javax.validation.constraints.NotNull; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | @RecordBuilderFull 25 | public record FullRecord(@NotNull List numbers, @NotNull Map fullRecords, 26 | @NotNull String justAString) { 27 | } 28 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/HasDefaults.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.IgnoreDefaultMethod; 19 | import io.soabase.recordbuilder.core.RecordInterface; 20 | 21 | import java.time.Instant; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | @RecordInterface 25 | public interface HasDefaults { 26 | Instant time(); 27 | 28 | default Instant tomorrow() { 29 | return Instant.now().plusMillis(TimeUnit.DAYS.toMillis(1)); 30 | } 31 | 32 | @IgnoreDefaultMethod 33 | default void complexMethod(String s1, String s2) { 34 | // do nothing 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/IgnoreAnnotated.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.validation.constraints.NotNull; 21 | 22 | @RecordBuilder() 23 | @RecordBuilder.Options(inheritComponentAnnotations = false) 24 | public record IgnoreAnnotated(@NotNull String s) { 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/IncludeWithOption.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder.Options(prefixEnclosingClassNames = false) 21 | @RecordBuilder.Include(IncludeWithOption.Hey.class) 22 | public class IncludeWithOption { 23 | public static record Hey(String s) { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Initialized.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import io.soabase.recordbuilder.core.RecordBuilderFull; 20 | 21 | import java.util.Optional; 22 | 23 | @RecordBuilderFull 24 | public record Initialized(@RecordBuilder.Initializer("DEFAULT_NAME") String name, 25 | @RecordBuilder.Initializer("defaultAge") int age, Optional dummy, 26 | @RecordBuilder.Initializer(value = "defaultAltName", source = AltSource.class) Optional altName) { 27 | 28 | public static final String DEFAULT_NAME = "hey"; 29 | 30 | public static int defaultAge() { 31 | return 18; 32 | } 33 | 34 | public static class AltSource { 35 | public static Optional defaultAltName() { 36 | return Optional.of("alt"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/InterfaceTemplateTest.java: -------------------------------------------------------------------------------- 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; 17 | 18 | @MyInterfaceTemplate 19 | public interface InterfaceTemplateTest { 20 | String name(); 21 | 22 | int age(); 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/MutableCollectionRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.List; 21 | 22 | @RecordBuilder 23 | public record MutableCollectionRecord(List l) implements MutableCollectionRecordBuilder.With { 24 | } 25 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/MyInterfaceTemplate.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder.Template(options = @RecordBuilder.Options(fileComment = "This is a test", withClassName = "Com"), asRecordInterface = true) 21 | public @interface MyInterfaceTemplate { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/MyTemplate.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder.Template(options = @RecordBuilder.Options(fileComment = "This is a test", withClassName = "Com")) 21 | public @interface MyTemplate { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Nested.java: -------------------------------------------------------------------------------- 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; 17 | 18 | public class Nested { 19 | record NestedRecord(int x, int y) { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/NoBuilder.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordInterface; 19 | 20 | import java.math.BigDecimal; 21 | import java.math.BigInteger; 22 | 23 | @RecordInterface(addRecordBuilder = false) 24 | public interface NoBuilder { 25 | BigInteger big(); 26 | 27 | BigDecimal decimal(); 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/NoStaticBuilder.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | /** 21 | * Copyright 2019 Jordan Zimmerman 22 | * 23 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 24 | * the License. You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 29 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 30 | * specific language governing permissions and limitations under the License. 31 | */ 32 | @RecordBuilder.Options(addStaticBuilder = false) 33 | @RecordBuilder 34 | public record NoStaticBuilder(String foo) { 35 | } 36 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/NonspecializedNullabeCollectionRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.Collection; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | /** 26 | * To test that the compilation warning is emitted for this combination of options 27 | */ 28 | @RecordBuilder 29 | @RecordBuilder.Options(useImmutableCollections = false, useUnmodifiableCollections = false, allowNullableCollections = true) 30 | public record NonspecializedNullabeCollectionRecord(List l, Set s, Map m, 31 | Collection c) implements CollectionRecordBuilder.With { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/NullableCollectionRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.Collection; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | @RecordBuilder 26 | @RecordBuilder.Options(useImmutableCollections = true, allowNullableCollections = true) 27 | public record NullableCollectionRecord(List l, Set s, Map m, Collection c) 28 | implements CollectionRecordBuilder.With { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/NullableCollectionRecordInterpretingNotNulls.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.validation.constraints.NotNull; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | @RecordBuilder 27 | @RecordBuilder.Options(useImmutableCollections = true, allowNullableCollections = true, interpretNotNulls = true) 28 | public record NullableCollectionRecordInterpretingNotNulls(@NotNull List l, Set s, 29 | Map m, @NotNull Collection c) implements CollectionRecordBuilder.With { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/OnceOnly.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | @RecordBuilder.Options(onceOnlyAssignment = true, builderMode = RecordBuilder.BuilderMode.STANDARD_AND_STAGED) 22 | public record OnceOnly(int a, int b, int c) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Pair.java: -------------------------------------------------------------------------------- 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; 17 | 18 | public record Pair(T t, U u) { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Person.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordInterface; 19 | 20 | @RecordInterface 21 | public interface Person { 22 | String name(); 23 | 24 | int age(); 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Point.java: -------------------------------------------------------------------------------- 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; 17 | 18 | public record Point(int x, int y) { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/PublicConstructor.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | @RecordBuilder.Options(publicBuilderConstructors = true) 22 | public record PublicConstructor(int i, String s) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RecordWithAnR.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | public record RecordWithAnR(int r, String b) { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RecordWithDefaultNotNull.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import javax.validation.constraints.Null; 20 | 21 | @RecordBuilder.Options(defaultNotNull = true) 22 | @RecordBuilder 23 | public record RecordWithDefaultNotNull(Integer notNullInteger, String notNullString, @Null String nullString) { 24 | } 25 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RecordWithOptional.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import javax.validation.constraints.NotNull; 19 | 20 | import io.soabase.recordbuilder.core.RecordBuilder; 21 | 22 | import java.util.Optional; 23 | import java.util.OptionalDouble; 24 | import java.util.OptionalInt; 25 | import java.util.OptionalLong; 26 | 27 | @RecordBuilder.Options(emptyDefaultForOptional = true, addConcreteSettersForOptional = true) 28 | @RecordBuilder 29 | public record RecordWithOptional(@NotNull Optional value, Optional raw, OptionalInt i, OptionalLong l, 30 | OptionalDouble d) { 31 | } 32 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RecordWithOptional2.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.util.Optional; 19 | import java.util.OptionalDouble; 20 | import java.util.OptionalInt; 21 | import java.util.OptionalLong; 22 | import io.soabase.recordbuilder.core.RecordBuilder; 23 | 24 | @RecordBuilder.Options(emptyDefaultForOptional = true) 25 | @RecordBuilder 26 | public record RecordWithOptional2(Optional value, Optional raw, OptionalInt i, OptionalLong l, 27 | OptionalDouble d) { 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RequestWithValid.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.validation.Valid; 21 | import javax.validation.constraints.NotBlank; 22 | import javax.validation.constraints.NotNull; 23 | 24 | @RecordBuilder 25 | @RecordBuilder.Options(useValidationApi = true) 26 | public record RequestWithValid(@NotNull @Valid @jakarta.validation.Valid Part part) 27 | implements RequestWithValidBuilder.With { 28 | public record Part(@NotBlank String name) { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RequiredRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.validation.constraints.NotNull; 21 | import java.util.List; 22 | 23 | @RecordBuilder.Options(interpretNotNulls = true) 24 | @RecordBuilder 25 | public record RequiredRecord(@NotNull String hey, @NotNull int i, @NotNull List l) 26 | implements RequiredRecordBuilder.With { 27 | } 28 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/RequiredRecord2.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.validation.constraints.NotNull; 21 | 22 | @RecordBuilder.Options(useValidationApi = true) 23 | @RecordBuilder 24 | public record RequiredRecord2(@NotNull String hey, @NotNull int i) implements RequiredRecord2Builder.With { 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/SimpleGenericRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | public record SimpleGenericRecord(int i, T s) implements SimpleGenericRecordBuilder.With { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/SimpleRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | @RecordBuilder.Options(prefixEnclosingClassNames = false) 22 | public record SimpleRecord(int i, String s) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/SingleItems.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.time.Instant; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | @RecordBuilder 27 | @RecordBuilder.Options(addSingleItemCollectionBuilders = true, singleItemBuilderPrefix = "add1", useImmutableCollections = true, addFunctionalMethodsToWith = true) 28 | public record SingleItems(List strings, Set> sets, Map map, Collection collection) 29 | implements SingleItemsBuilder.With { 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/SpecializedPerson.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordInterface; 19 | 20 | import java.util.List; 21 | import java.util.Map; 22 | import java.util.function.Function; 23 | import java.util.function.Supplier; 24 | 25 | @RecordInterface 26 | public interface SpecializedPerson extends Person { 27 | List features(); 28 | 29 | Map, Function>> complex(); 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/StrippedFeaturesRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | @RecordBuilder.Options(enableGetters = false, enableWither = false) 22 | public record StrippedFeaturesRecord(int aField) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/TemplateTest.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.time.Instant; 19 | 20 | @MyTemplate 21 | public record TemplateTest(String text, Instant date) implements TemplateTestBuilder.Com { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Thingy.java: -------------------------------------------------------------------------------- 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; 17 | 18 | public interface Thingy { 19 | T getIt(); 20 | } 21 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/UnmodifiableCollectionsRecord.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.Collection; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | @RecordBuilder 26 | @RecordBuilder.Options(useUnmodifiableCollections = true) 27 | record UnmodifiableCollectionsRecord(List aList, Set orderedSet, Map orderedMap, 28 | Collection aCollection) { 29 | } 30 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/Usage.java: -------------------------------------------------------------------------------- 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; 17 | 18 | public class Usage { 19 | public static void main(String[] args) { 20 | var hey = SimpleRecordBuilder.builder().i(10).s("hey").build(); 21 | System.out.println(hey); 22 | var hey2 = SimpleRecordBuilder.builder(hey).i(100).build(); 23 | System.out.println(hey2); 24 | 25 | var person = new PersonRecord("me", 42); 26 | outputPerson(person); 27 | var aged = PersonRecordBuilder.builder(person).age(100).build(); 28 | outputPerson(aged); 29 | } 30 | 31 | private static void outputPerson(Person p) { 32 | System.out.println(p.toString()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/WildcardSingleItems.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.time.Instant; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | @RecordBuilder 27 | @RecordBuilder.Options(addSingleItemCollectionBuilders = true, useImmutableCollections = true) 28 | public record WildcardSingleItems(List strings, Set> sets, 29 | Map map, Collection collection) 30 | implements WildcardSingleItemsBuilder.With { 31 | } 32 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/ClassWithStaged.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.function.Consumer; 21 | import java.util.function.IntConsumer; 22 | 23 | public class ClassWithStaged { 24 | @RecordBuilder.Deconstructor 25 | @RecordBuilder.Options(builderMode = RecordBuilder.BuilderMode.STAGED) 26 | public void deconstructor(IntConsumer i, Consumer s) { 27 | // notning 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/ComplexClass.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.DeconstructorFull; 19 | 20 | import java.util.function.Consumer; 21 | 22 | public class ComplexClass> { 23 | private final T t; 24 | private final ComplexClass c; 25 | 26 | public ComplexClass(T t, ComplexClass c) { 27 | this.t = t; 28 | this.c = c; 29 | } 30 | 31 | @DeconstructorFull 32 | public void deconstructor(Consumer t, Consumer> c) { 33 | t.accept(this.t); 34 | c.accept(this.c); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/GenericClass.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import io.soabase.recordbuilder.core.RecordBuilder.Deconstructor; 20 | 21 | import java.util.function.Consumer; 22 | 23 | public class GenericClass { 24 | private final T t; 25 | 26 | public GenericClass(T t) { 27 | this.t = t; 28 | } 29 | 30 | @Deconstructor 31 | @RecordBuilder.Options(interpretNotNulls = true, useImmutableCollections = true, addSingleItemCollectionBuilders = true, addFunctionalMethodsToWith = true, addClassRetainedGenerated = true) 32 | public void deconstructor(Consumer t) { 33 | t.accept(this.t); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/InterfaceTest.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder.Deconstructor; 19 | 20 | import java.time.Instant; 21 | import java.util.function.Consumer; 22 | import java.util.function.IntConsumer; 23 | 24 | public interface InterfaceTest { 25 | @Deconstructor 26 | void deconstructor1(Consumer string, IntConsumer integer, Consumer instant); 27 | 28 | @Deconstructor(prefix = "MeMeMe") 29 | void deconstructor2(Consumer string); 30 | } 31 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/MyClass.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.util.function.Consumer; 21 | import java.util.function.IntConsumer; 22 | 23 | public class MyClass { 24 | private final int i; 25 | private final String s; 26 | 27 | public MyClass(int i, String s) { 28 | this.i = i; 29 | this.s = s; 30 | } 31 | 32 | @RecordBuilder.Deconstructor 33 | public void deconstructor(IntConsumer i, Consumer s) { 34 | i.accept(this.i); 35 | s.accept(this.s); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/NoRecordBuilder.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder.Deconstructor; 19 | 20 | import java.util.function.IntConsumer; 21 | 22 | public class NoRecordBuilder { 23 | @Deconstructor(addRecordBuilder = false) 24 | public void unapply(IntConsumer i) { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/UniqueVarNameCheck.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import io.soabase.recordbuilder.core.RecordBuilder.Deconstructor; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.function.Consumer; 24 | import java.util.function.IntConsumer; 25 | 26 | public class UniqueVarNameCheck { 27 | @Deconstructor 28 | @RecordBuilder.Options(builderMode = RecordBuilder.BuilderMode.STAGED) // use staged so that deconstructor can't use 29 | // builder 30 | public void unapply(Consumer>> components, IntConsumer rhs) { 31 | } 32 | 33 | @Deconstructor(suffix = "Alt") 34 | public void unapplyWithBuilder(Consumer>> c, IntConsumer rhs) { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/UniqueVarNameCheck2.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | import io.soabase.recordbuilder.core.RecordBuilder.Deconstructor; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.function.Consumer; 24 | import java.util.function.IntConsumer; 25 | 26 | public class UniqueVarNameCheck2 { 27 | @Deconstructor 28 | public void unapply(Consumer>> components, IntConsumer rhs) { 29 | } 30 | 31 | @Deconstructor(suffix = "Alt") 32 | @RecordBuilder.Options(builderMethodName = "altBuilder") 33 | public void unapplyWithBuilder(Consumer>> builder, IntConsumer rhs) { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/deconstructors/WithAnnotations.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder.Deconstructor; 19 | 20 | import javax.validation.constraints.NotEmpty; 21 | import javax.validation.constraints.NotNull; 22 | import java.util.function.Consumer; 23 | import java.util.function.IntConsumer; 24 | 25 | public interface WithAnnotations { 26 | @Deconstructor 27 | void unapply(@NotNull @NotEmpty Consumer s, IntConsumer p); 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/IncludeFactory.java: -------------------------------------------------------------------------------- 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.includes; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder.Include(packages = "io.soabase.recordbuilder.test.includes.pack", classes = JustATest.class) 21 | public class IncludeFactory { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/JustATest.java: -------------------------------------------------------------------------------- 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.includes; 17 | 18 | public record JustATest(int i) { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/pack/AlsoIgnoreMe.java: -------------------------------------------------------------------------------- 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.includes.pack; 17 | 18 | public interface AlsoIgnoreMe { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/pack/IgnoreMe.java: -------------------------------------------------------------------------------- 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.includes.pack; 17 | 18 | public class IgnoreMe { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/pack/PackRecord1.java: -------------------------------------------------------------------------------- 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.includes.pack; 17 | 18 | public record PackRecord1(String name) { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/pack/PackRecord2.java: -------------------------------------------------------------------------------- 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.includes.pack; 17 | 18 | public record PackRecord2(String name, int age) { 19 | } 20 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/includes/pack/PackRecord3.java: -------------------------------------------------------------------------------- 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.includes.pack; 17 | 18 | import java.time.Instant; 19 | 20 | public record PackRecord3(Instant time, int age) { 21 | } 22 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/jacoco/FullRecordForJacoco.java: -------------------------------------------------------------------------------- 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.jacoco; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilderFull; 19 | import io.soabase.recordbuilder.core.RecordBuilderGenerated; 20 | 21 | import javax.validation.constraints.NotNull; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | @RecordBuilderFull 26 | @RecordBuilderGenerated 27 | public record FullRecordForJacoco(@NotNull List numbers, @NotNull Map fullRecords, 28 | @NotNull String justAString) { 29 | } 30 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/naming/Builder.java: -------------------------------------------------------------------------------- 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.naming; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import java.lang.annotation.*; 21 | 22 | @RecordBuilder.Template(options = @RecordBuilder.Options(enableGetters = false, enableWither = false, fileIndent = " ", inheritComponentAnnotations = false, prefixEnclosingClassNames = false)) 23 | @Retention(RetentionPolicy.SOURCE) 24 | @Target(ElementType.TYPE) 25 | @Inherited 26 | public @interface Builder { 27 | } 28 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/naming/ConvertRequest.java: -------------------------------------------------------------------------------- 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.naming; 17 | 18 | @Builder 19 | record ConvertRequest(double from, double to) { 20 | } -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/package-info.java: -------------------------------------------------------------------------------- 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 | @RecordBuilder.Include(value = { Point.class, Pair.class }, packagePattern = "*.foo") 17 | @RecordBuilder.Options(fileComment = "MyLicense - Auto generated") 18 | @RecordInterface.Include(value = Customer.class, addRecordBuilder = false, packagePattern = "*.bar") 19 | package io.soabase.recordbuilder.test; 20 | 21 | import io.soabase.recordbuilder.core.RecordBuilder; 22 | import io.soabase.recordbuilder.core.RecordInterface; 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/CombinedGenericStaged.java: -------------------------------------------------------------------------------- 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.STANDARD_AND_STAGED) 22 | public record CombinedGenericStaged, U>(String name, T aT, U theUThing) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/CombinedSimpleStaged.java: -------------------------------------------------------------------------------- 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.STANDARD_AND_STAGED) 24 | public record CombinedSimpleStaged(int i, String s, Instant instant) { 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/GenericStaged.java: -------------------------------------------------------------------------------- 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 GenericStaged(String name, T aT, U theUThing) { 23 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/InitializedStaged.java: -------------------------------------------------------------------------------- 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_REQUIRED_ONLY, skipStagingForInitializedComponents = true) 22 | public record InitializedStaged(@RecordBuilder.Initializer("defaultAge") int age, String name) { 23 | 24 | public static int defaultAge() { 25 | return 18; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/NoFieldsStaged.java: -------------------------------------------------------------------------------- 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 | } 24 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/OptionalListStaged.java: -------------------------------------------------------------------------------- 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 javax.validation.constraints.Null; 21 | import java.time.Instant; 22 | import java.util.List; 23 | import java.util.Optional; 24 | 25 | @RecordBuilder 26 | @RecordBuilder.Options(builderMode = RecordBuilder.BuilderMode.STAGED_REQUIRED_ONLY, interpretNotNulls = true, useImmutableCollections = true) 27 | public record OptionalListStaged(int a, Optional b, double c, List d, @Null String e, String f) { 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/OptionalStagedRequiredOnly.java: -------------------------------------------------------------------------------- 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.util.Optional; 21 | 22 | @RecordBuilder 23 | @RecordBuilder.Options(builderMode = RecordBuilder.BuilderMode.STAGED_REQUIRED_ONLY, addConcreteSettersForOptional = true) 24 | public record OptionalStagedRequiredOnly(int a, Optional b, String c) { 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/SimpleStaged.java: -------------------------------------------------------------------------------- 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 SimpleStaged(int i, String s, Instant instant) { 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/staged/SingleFieldStaged.java: -------------------------------------------------------------------------------- 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 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/visibility/PackagePrivateRecord.java: -------------------------------------------------------------------------------- 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.visibility; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | @RecordBuilder 21 | record PackagePrivateRecord(int i) { 22 | } 23 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/visibility/PackagePrivateRecordWithPublicBuilder.java: -------------------------------------------------------------------------------- 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.visibility; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | import javax.lang.model.element.Modifier; 21 | 22 | @RecordBuilder.Options(builderClassModifiers = { Modifier.PUBLIC }) 23 | @RecordBuilder 24 | record PackagePrivateRecordWithPublicBuilder(String value) { 25 | } 26 | -------------------------------------------------------------------------------- /record-builder-test/src/main/java/io/soabase/recordbuilder/test/visibility/Wrapper.java: -------------------------------------------------------------------------------- 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.visibility; 17 | 18 | import io.soabase.recordbuilder.core.RecordBuilder; 19 | 20 | class Wrapper { 21 | @RecordBuilder 22 | protected record ProtectedRecord(int i) { 23 | } 24 | 25 | @RecordBuilder 26 | record PackagePrivateRecord(int i) { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestAnnotated.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import javax.validation.Valid; 22 | import javax.validation.constraints.Max; 23 | import javax.validation.constraints.Min; 24 | import javax.validation.constraints.NotNull; 25 | import javax.validation.constraints.Null; 26 | import java.lang.reflect.AnnotatedElement; 27 | 28 | class TestAnnotated { 29 | @Test 30 | void testInheritComponentAnnotationsFalse() throws NoSuchMethodException { 31 | var method = IgnoreAnnotatedBuilder.class.getMethod("s"); 32 | Assertions.assertNull(method.getAnnotation(NotNull.class)); 33 | } 34 | 35 | @Test 36 | void testFiltersOutJavaXValid() throws NoSuchMethodException { 37 | var method = RequestWithValidBuilder.With.class.getMethod("part"); 38 | Assertions.assertNull(method.getAnnotation(Valid.class)); 39 | } 40 | 41 | @Test 42 | void testFiltersOutJakartaValid() throws NoSuchMethodException { 43 | var method = RequestWithValidBuilder.With.class.getMethod("part"); 44 | Assertions.assertNull(method.getAnnotation(jakarta.validation.Valid.class)); 45 | } 46 | 47 | @Test 48 | void testStaticConstructor() throws NoSuchMethodException { 49 | var method = AnnotatedBuilder.class.getMethod("Annotated", String.class, Integer.TYPE, Double.TYPE); 50 | var parameters = method.getParameters(); 51 | Assertions.assertEquals(3, parameters.length); 52 | assertHey(parameters[0]); 53 | assertI(parameters[1]); 54 | assertD(parameters[2]); 55 | } 56 | 57 | @Test 58 | void testSetters() throws NoSuchMethodException { 59 | var method = AnnotatedBuilder.class.getMethod("hey", String.class); 60 | var parameters = method.getParameters(); 61 | Assertions.assertEquals(1, parameters.length); 62 | assertHey(parameters[0]); 63 | 64 | method = AnnotatedBuilder.class.getMethod("i", Integer.TYPE); 65 | parameters = method.getParameters(); 66 | Assertions.assertEquals(1, parameters.length); 67 | assertI(parameters[0]); 68 | 69 | method = AnnotatedBuilder.class.getMethod("d", Double.TYPE); 70 | parameters = method.getParameters(); 71 | Assertions.assertEquals(1, parameters.length); 72 | assertD(parameters[0]); 73 | } 74 | 75 | @Test 76 | void testGetters() throws NoSuchMethodException { 77 | var method = AnnotatedBuilder.class.getMethod("hey"); 78 | assertHey(method); 79 | 80 | method = AnnotatedBuilder.class.getMethod("i"); 81 | assertI(method); 82 | 83 | method = AnnotatedBuilder.class.getMethod("d"); 84 | assertD(method); 85 | } 86 | 87 | @Test 88 | void testWitherSetters() throws NoSuchMethodException { 89 | var method = AnnotatedBuilder.With.class.getMethod("withHey", String.class); 90 | var parameters = method.getParameters(); 91 | Assertions.assertEquals(1, parameters.length); 92 | assertHey(parameters[0]); 93 | 94 | method = AnnotatedBuilder.With.class.getMethod("withI", Integer.TYPE); 95 | parameters = method.getParameters(); 96 | Assertions.assertEquals(1, parameters.length); 97 | assertI(parameters[0]); 98 | 99 | method = AnnotatedBuilder.With.class.getMethod("withD", Double.TYPE); 100 | parameters = method.getParameters(); 101 | Assertions.assertEquals(1, parameters.length); 102 | assertD(parameters[0]); 103 | } 104 | 105 | private void assertD(AnnotatedElement d) { 106 | Assertions.assertEquals(0, d.getAnnotations().length); 107 | } 108 | 109 | private void assertI(AnnotatedElement i) { 110 | Assertions.assertNotNull(i.getAnnotation(Min.class)); 111 | Assertions.assertEquals(i.getAnnotation(Min.class).value(), 10); 112 | Assertions.assertNotNull(i.getAnnotation(Max.class)); 113 | Assertions.assertEquals(i.getAnnotation(Max.class).value(), 100); 114 | } 115 | 116 | private void assertHey(AnnotatedElement hey) { 117 | Assertions.assertNotNull(hey.getAnnotation(NotNull.class)); 118 | Assertions.assertNotNull(hey.getAnnotation(Null.class)); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestCollections.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.*; 22 | 23 | import static io.soabase.recordbuilder.test.foo.PointBuilder.Point; 24 | import static org.junit.jupiter.api.Assertions.*; 25 | 26 | class TestCollections { 27 | @Test 28 | void testRecordBuilderOptionsCopied() { 29 | try { 30 | assertNotNull(CollectionInterfaceRecordBuilder.class.getDeclaredMethod("__list", Collection.class)); 31 | } catch (NoSuchMethodException e) { 32 | Assertions.fail(e); 33 | } 34 | } 35 | 36 | @Test 37 | void testCollectionRecordDefaultValues() { 38 | var defaultValues = CollectionRecordBuilder.builder().build(); 39 | assertNotNull(defaultValues.l()); 40 | assertNotNull(defaultValues.s()); 41 | assertNotNull(defaultValues.m()); 42 | assertNotNull(defaultValues.c()); 43 | } 44 | 45 | @Test 46 | void testCollectionRecordImmutable() { 47 | var list = new ArrayList(); 48 | list.add("one"); 49 | var set = new HashSet(); 50 | set.add("one"); 51 | var map = new HashMap(); 52 | map.put("one", Point(10, 20)); 53 | var collectionAsSet = new HashSet(); 54 | collectionAsSet.add(Point(30, 40)); 55 | var r = CollectionRecordBuilder. builder().l(list).s(set).m(map).c(collectionAsSet).build(); 56 | 57 | assertValues(r, list, set, map, collectionAsSet); 58 | assertValueChanges(r, list, set, map, collectionAsSet); 59 | assertImmutable(r); 60 | 61 | var collectionAsList = new ArrayList(); 62 | var x = CollectionRecordBuilder. builder().l(list).s(set).m(map).c(collectionAsList).build(); 63 | assertTrue(x.c() instanceof List); 64 | } 65 | 66 | @Test 67 | void testCollectionRecordImmutableWithers() { 68 | var r = CollectionRecordBuilder. builder().build(); 69 | 70 | var list = new ArrayList(); 71 | list.add("one"); 72 | var set = new HashSet(); 73 | set.add("one"); 74 | var map = new HashMap(); 75 | map.put("one", Point(10, 20)); 76 | var collectionAsSet = new HashSet(); 77 | collectionAsSet.add(Point(30, 40)); 78 | var x = r.withL(list).withS(set).withM(map).withC(collectionAsSet); 79 | 80 | assertValues(x, list, set, map, collectionAsSet); 81 | assertValueChanges(x, list, set, map, collectionAsSet); 82 | assertImmutable(x); 83 | } 84 | 85 | @Test 86 | public void testMutableCollectionRecord() { 87 | var r = MutableCollectionRecordBuilder.builder().build(); 88 | assertNull(r.l()); 89 | 90 | var list = new ArrayList(); 91 | list.add("one"); 92 | r = MutableCollectionRecordBuilder.builder().l(list).build(); 93 | 94 | assertEquals(r.l(), list); 95 | list.add("two"); 96 | assertEquals(r.l(), list); 97 | } 98 | 99 | private void assertImmutable(CollectionRecord r) { 100 | assertThrows(UnsupportedOperationException.class, () -> r.l().add("hey")); 101 | assertThrows(UnsupportedOperationException.class, () -> r.s().add("hey")); 102 | assertThrows(UnsupportedOperationException.class, () -> r.m().put("hey", Point(1, 2))); 103 | assertThrows(UnsupportedOperationException.class, () -> r.c().add(Point(1, 2))); 104 | } 105 | 106 | private void assertValueChanges(CollectionRecord r, ArrayList list, HashSet set, 107 | HashMap map, HashSet collectionAsSet) { 108 | list.add("two"); 109 | set.add("two"); 110 | map.put("two", Point(50, 60)); 111 | collectionAsSet.add(Point(70, 80)); 112 | 113 | assertNotEquals(r.l(), list); 114 | assertNotEquals(r.s(), set); 115 | assertNotEquals(r.m(), map); 116 | assertNotEquals(r.c(), collectionAsSet); 117 | } 118 | 119 | private void assertValues(CollectionRecord r, ArrayList list, HashSet set, 120 | HashMap map, HashSet collectionAsSet) { 121 | assertEquals(r.l(), list); 122 | assertEquals(r.s(), set); 123 | assertEquals(r.m(), map); 124 | assertEquals(r.c(), collectionAsSet); 125 | assertTrue(r.c() instanceof Set); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestCollectionsBuilder.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | public class TestCollectionsBuilder { 22 | 23 | @Test 24 | void testCollectionsBuilderReturnNonNullEmptyCollections() { 25 | CollectionRecordBuilder builder = CollectionRecordBuilder.builder(); 26 | 27 | Assertions.assertNotNull(builder.l()); 28 | Assertions.assertTrue(builder.l().isEmpty()); 29 | Assertions.assertNotNull(builder.c()); 30 | Assertions.assertTrue(builder.c().isEmpty()); 31 | Assertions.assertNotNull(builder.m()); 32 | Assertions.assertTrue(builder.m().isEmpty()); 33 | Assertions.assertNotNull(builder.s()); 34 | Assertions.assertTrue(builder.s().isEmpty()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestDefaultNotNull.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | public class TestDefaultNotNull { 22 | @Test 23 | void testDefaultNotNullFieldSet() { 24 | final var validRecord = RecordWithDefaultNotNullBuilder.RecordWithDefaultNotNull(123, "wibble", null); 25 | Assertions.assertEquals(123, validRecord.notNullInteger()); 26 | Assertions.assertEquals("wibble", validRecord.notNullString()); 27 | Assertions.assertNull(validRecord.nullString()); 28 | } 29 | 30 | @Test 31 | void testDefaultNotNullThrowsExceptionForNullFields() { 32 | Assertions.assertThrows(NullPointerException.class, 33 | () -> RecordWithDefaultNotNullBuilder.RecordWithDefaultNotNull(null, null, null)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestImmutableCollections.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.time.Instant; 22 | import java.util.*; 23 | 24 | public class TestImmutableCollections { 25 | @Test 26 | public void testImmutableListNotCopiedWhenNotChanged() { 27 | var item = CollectionCopyingBuilder. builder().addList("a").addList("b").addList("c").build(); 28 | Assertions.assertEquals(item.list(), List.of("a", "b", "c")); 29 | 30 | var oldList = item.list(); 31 | 32 | var copy = item.with().count(1).build(); 33 | 34 | Assertions.assertSame(oldList, copy.list()); 35 | 36 | var otherCopy = item.with().count(2).build(); 37 | 38 | Assertions.assertSame(oldList, otherCopy.list()); 39 | } 40 | 41 | @Test 42 | public void testImmutableSetNotCopiedWhenNotChanged() { 43 | var item = CollectionCopyingBuilder. builder().addSet(Arrays.asList("1", "2", "3")).build(); 44 | Assertions.assertEquals(item.set(), Set.of("1", "2", "3")); 45 | 46 | var oldSet = item.set(); 47 | 48 | var copy = item.with().count(1).build(); 49 | 50 | Assertions.assertSame(oldSet, copy.set()); 51 | 52 | var otherCopy = item.with().count(2).build(); 53 | 54 | Assertions.assertSame(oldSet, otherCopy.set()); 55 | } 56 | 57 | @Test 58 | public void testImmutableCollectionNotCopiedWhenNotChanged() { 59 | var item = CollectionCopyingBuilder. builder().collection(List.of("foo", "bar", "baz")).build(); 60 | Assertions.assertEquals(item.collection(), List.of("foo", "bar", "baz")); 61 | 62 | var oldCollection = item.collection(); 63 | 64 | var copy = item.with().count(1).build(); 65 | 66 | Assertions.assertSame(oldCollection, copy.collection()); 67 | 68 | var otherCopy = item.with().count(2).build(); 69 | 70 | Assertions.assertSame(oldCollection, otherCopy.collection()); 71 | } 72 | 73 | @Test 74 | public void testImmutableMapNotCopiedWhenNotChanged() { 75 | var item = CollectionCopyingBuilder. builder().addMap(Instant.MAX, "future") 76 | .addMap(Instant.MIN, "before").build(); 77 | Assertions.assertEquals(item.map(), Map.of(Instant.MAX, "future", Instant.MIN, "before")); 78 | 79 | var oldMap = item.map(); 80 | 81 | var copy = item.with().count(1).build(); 82 | 83 | Assertions.assertSame(oldMap, copy.map()); 84 | 85 | var otherCopy = item.with().count(2).build(); 86 | 87 | Assertions.assertSame(oldMap, otherCopy.map()); 88 | } 89 | 90 | @Test 91 | void testSourceListNotModified() { 92 | var item = new CollectionCopying<>(new ArrayList<>(), null, null, null, 0); 93 | var modifiedItem = CollectionCopyingBuilder.builder(item).addList("a").build(); 94 | 95 | Assertions.assertEquals(modifiedItem.list(), List.of("a")); 96 | Assertions.assertTrue(item.list().isEmpty()); 97 | } 98 | 99 | @Test 100 | void testSourceSetNotModified() { 101 | var item = new CollectionCopying<>(null, new HashSet<>(), null, null, 0); 102 | var modifiedItem = CollectionCopyingBuilder.builder(item).addSet("a").build(); 103 | 104 | Assertions.assertEquals(modifiedItem.set(), Set.of("a")); 105 | Assertions.assertTrue(item.set().isEmpty()); 106 | } 107 | 108 | @Test 109 | void testSourceMapNotModified() { 110 | var item = new CollectionCopying<>(null, null, new HashMap<>(), null, 0); 111 | var modifiedItem = CollectionCopyingBuilder.builder(item).addMap(Instant.MIN, "a").build(); 112 | 113 | Assertions.assertEquals(modifiedItem.map(), Map.of(Instant.MIN, "a")); 114 | Assertions.assertTrue(item.map().isEmpty()); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestIncludes.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | class TestIncludes { 22 | @Test 23 | void testOptionsOnInclude() { 24 | // assert it's not prefixed with the enclosing class name 25 | IncludeWithOption.Hey hey = io.soabase.recordbuilder.test.HeyBuilder.builder().s("this is s").build(); 26 | Assertions.assertEquals("this is s", hey.s()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestInitialized.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.Optional; 22 | 23 | class TestInitialized { 24 | @Test 25 | void testInitialized() { 26 | var initialized = InitializedBuilder.builder().build(); 27 | Assertions.assertEquals(Initialized.DEFAULT_NAME, initialized.name()); 28 | Assertions.assertEquals(Initialized.defaultAge(), initialized.age()); 29 | Assertions.assertEquals(Initialized.AltSource.defaultAltName(), initialized.altName()); 30 | Assertions.assertEquals(Optional.empty(), initialized.dummy()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestNullableCollectionsBuilder.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | public class TestNullableCollectionsBuilder { 27 | 28 | @Test 29 | void testNullableCollectionsBuilder_returnsTheActualValuesIfSet() { 30 | List list = List.of("list"); 31 | Set set = Set.of("set"); 32 | Collection collection = List.of(new Point(10, 20)); 33 | Map map = Map.of("one", new Point(10, 20)); 34 | 35 | NullableCollectionRecordBuilder builder = NullableCollectionRecordBuilder.builder().l(list) 36 | .s(set).c(collection).m(map); 37 | 38 | Assertions.assertEquals(list, builder.l()); 39 | Assertions.assertEquals(set, builder.s()); 40 | Assertions.assertEquals(collection, builder.c()); 41 | Assertions.assertEquals(map, builder.m()); 42 | 43 | var record = builder.build(); 44 | Assertions.assertEquals(list, record.l()); 45 | Assertions.assertEquals(set, record.s()); 46 | Assertions.assertEquals(collection, record.c()); 47 | Assertions.assertEquals(map, record.m()); 48 | } 49 | 50 | @Test 51 | void testNullableCollectionsBuilder_whenNullsAreNotInterpreted_returnsNullForAllComponents_whenNullsAreNotInterpreted() { 52 | NullableCollectionRecordBuilder builder = NullableCollectionRecordBuilder.builder(); 53 | 54 | Assertions.assertNull(builder.l()); 55 | Assertions.assertNull(builder.m()); 56 | Assertions.assertNull(builder.c()); 57 | Assertions.assertNull(builder.s()); 58 | 59 | var record = builder.build(); 60 | Assertions.assertNull(record.l()); 61 | Assertions.assertNull(record.m()); 62 | Assertions.assertNull(record.c()); 63 | Assertions.assertNull(record.s()); 64 | } 65 | 66 | @Test 67 | void testNullableCollectionBuilder_whenNullsAreInterpreted_returnsNullOrEmptyCollectionBasedOnComponentNullability() { 68 | // NotNull - list, collection 69 | // Nullable - set, map 70 | NullableCollectionRecordInterpretingNotNullsBuilder builder = NullableCollectionRecordInterpretingNotNullsBuilder 71 | .builder(); 72 | 73 | Assertions.assertNotNull(builder.l()); 74 | Assertions.assertTrue(builder.l().isEmpty()); 75 | 76 | Assertions.assertNull(builder.m()); 77 | Assertions.assertNull(builder.s()); 78 | 79 | Assertions.assertNotNull(builder.c()); 80 | Assertions.assertTrue(builder.c().isEmpty()); 81 | 82 | var record = builder.build(); 83 | Assertions.assertNotNull(record.l()); 84 | Assertions.assertTrue(record.l().isEmpty()); 85 | 86 | Assertions.assertNull(record.m()); 87 | Assertions.assertNull(record.s()); 88 | 89 | Assertions.assertNotNull(record.c()); 90 | Assertions.assertTrue(record.c().isEmpty()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestOnceOnly.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.junit.jupiter.api.Assertions.*; 21 | 22 | class TestOnceOnly { 23 | @Test 24 | void testOnceOnly() { 25 | assertThrows(IllegalStateException.class, () -> OnceOnlyBuilder.builder().a(1).a(2)); 26 | assertThrows(IllegalStateException.class, () -> OnceOnlyBuilder.builder().b(1).b(2)); 27 | assertThrows(IllegalStateException.class, () -> OnceOnlyBuilder.builder().c(1).c(2)); 28 | 29 | assertDoesNotThrow(() -> OnceOnlyBuilder.builder().a(1).b(2).c(3).build()); 30 | } 31 | 32 | @Test 33 | void testStagedOnceOnly() { 34 | OnceOnlyBuilder.AStage aStage = OnceOnlyBuilder.stagedBuilder(); 35 | 36 | OnceOnlyBuilder.BStage bStage = aStage.a(1); 37 | assertThrows(IllegalStateException.class, () -> aStage.a(1)); 38 | 39 | OnceOnlyBuilder.CStage cStage = bStage.b(2); 40 | assertThrows(IllegalStateException.class, () -> bStage.b(2)); 41 | 42 | OnceOnlyBuilder.OnceOnlyBuilderStage builderStage = cStage.c(3); 43 | assertThrows(IllegalStateException.class, () -> cStage.c(3)); 44 | 45 | assertDoesNotThrow(builderStage::build); 46 | assertEquals(new OnceOnly(1, 2, 3), builderStage.build()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestOptional.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.util.Optional; 19 | import java.util.OptionalDouble; 20 | import java.util.OptionalInt; 21 | import java.util.OptionalLong; 22 | 23 | import org.junit.jupiter.api.Assertions; 24 | import org.junit.jupiter.api.Test; 25 | 26 | class TestOptional { 27 | @Test 28 | void testDefaultEmpty() { 29 | var record = RecordWithOptionalBuilder.builder(); 30 | Assertions.assertEquals(Optional.empty(), record.value()); 31 | Assertions.assertEquals(Optional.empty(), record.raw()); 32 | Assertions.assertEquals(OptionalInt.empty(), record.i()); 33 | Assertions.assertEquals(OptionalLong.empty(), record.l()); 34 | Assertions.assertEquals(OptionalDouble.empty(), record.d()); 35 | } 36 | 37 | @Test 38 | void testRawSetters() { 39 | var record = RecordWithOptionalBuilder.builder().value("value").raw("rawValue").i(42).l(424242L).d(42.42) 40 | .build(); 41 | Assertions.assertEquals(Optional.of("value"), record.value()); 42 | Assertions.assertEquals(Optional.of("rawValue"), record.raw()); 43 | Assertions.assertEquals(OptionalInt.of(42), record.i()); 44 | Assertions.assertEquals(OptionalLong.of(424242L), record.l()); 45 | Assertions.assertEquals(OptionalDouble.of(42.42), record.d()); 46 | } 47 | 48 | @Test 49 | void testOptionalSetters() { 50 | var record = RecordWithOptional2Builder.builder().value(Optional.of("value")).raw(Optional.of("rawValue")) 51 | .i(OptionalInt.of(42)).l(OptionalLong.of(424242L)).d(OptionalDouble.of(42.42)).build(); 52 | Assertions.assertEquals(Optional.of("value"), record.value()); 53 | Assertions.assertEquals(Optional.of("rawValue"), record.raw()); 54 | Assertions.assertEquals(OptionalInt.of(42), record.i()); 55 | Assertions.assertEquals(OptionalLong.of(424242L), record.l()); 56 | Assertions.assertEquals(OptionalDouble.of(42.42), record.d()); 57 | } 58 | 59 | @Test 60 | void shouldAcceptNullForOptionalRawSetter() { 61 | // given 62 | String value = null; 63 | 64 | // when 65 | var record = RecordWithOptionalBuilder.builder().value(value).build(); 66 | 67 | // then 68 | Assertions.assertEquals(Optional.empty(), record.value()); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestOptionsOnPackage.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.io.IOException; 19 | import java.nio.file.Files; 20 | import java.nio.file.Path; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | 25 | class TestOptionsOnPackage { 26 | @Test 27 | void testOptionsOnInclude() throws IOException { 28 | String text = Files.readString( 29 | Path.of("target/generated-sources/annotations/io/soabase/recordbuilder/test/foo/PairBuilder.java")); 30 | Assertions.assertTrue(text.contains("// MyLicense - Auto generated")); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestPublicConstructor.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | public class TestPublicConstructor { 22 | @Test 23 | public void testPublicConstructor() { 24 | PublicConstructor pc1 = new PublicConstructorBuilder().s("s").i(10).build(); 25 | PublicConstructor pc2 = new PublicConstructor(10, "s"); 26 | Assertions.assertEquals(pc1, pc2); 27 | Assertions.assertEquals(pc1, PublicConstructorBuilder.builder().s("s").i(10).build()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestRecordBuilderFull.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.ArrayList; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | class TestRecordBuilderFull { 27 | @Test 28 | void testNonNull() { 29 | var record = FullRecordBuilder.builder().justAString("").build(); 30 | Assertions.assertEquals(List.of(), record.numbers()); 31 | Assertions.assertEquals(Map.of(), record.fullRecords()); 32 | } 33 | 34 | @Test 35 | void testImmutable() { 36 | var record = FullRecordBuilder.builder().fullRecords(new HashMap<>()).numbers(new ArrayList<>()).justAString("") 37 | .build(); 38 | Assertions.assertThrows(UnsupportedOperationException.class, () -> record.fullRecords().put(1, record)); 39 | Assertions.assertThrows(UnsupportedOperationException.class, () -> record.numbers().add(1)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestRecordInterface.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import java.util.AbstractMap.SimpleImmutableEntry; 19 | import java.util.List; 20 | import java.util.Map; 21 | import org.junit.jupiter.api.Assertions; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import java.time.Instant; 25 | 26 | import static io.soabase.recordbuilder.test.SimpleGenericRecordBuilder.SimpleGenericRecord; 27 | import static io.soabase.recordbuilder.test.SimpleRecordBuilder.SimpleRecord; 28 | 29 | public class TestRecordInterface { 30 | @Test 31 | public void testHasDefaults() { 32 | var r1 = new HasDefaultsRecord(Instant.MIN, Instant.MAX); 33 | var r2 = r1.with(b -> b.tomorrow(Instant.MIN)); 34 | Assertions.assertEquals(Instant.MIN, r1.time()); 35 | Assertions.assertEquals(Instant.MAX, r1.tomorrow()); 36 | Assertions.assertEquals(Instant.MIN, r2.time()); 37 | Assertions.assertEquals(Instant.MIN, r2.tomorrow()); 38 | } 39 | 40 | @Test 41 | public void testStaticConstructor() { 42 | var simple = SimpleRecord(10, "hey"); 43 | Assertions.assertEquals(simple.i(), 10); 44 | Assertions.assertEquals(simple.s(), "hey"); 45 | 46 | var now = Instant.now(); 47 | var generic = SimpleGenericRecord(101, now); 48 | Assertions.assertEquals(generic.i(), 101); 49 | Assertions.assertEquals(generic.s(), now); 50 | } 51 | 52 | @Test 53 | public void testBuilderStreamWithValues() { 54 | var stream = SimpleRecordBuilder.stream(SimpleRecordBuilder.builder().i(19).s("value").build()).toList(); 55 | Assertions.assertEquals(stream, List.of(Map.entry("i", 19), Map.entry("s", "value"))); 56 | } 57 | 58 | @Test 59 | public void testBuilderStreamWithNulls() { 60 | var stream = SimpleRecordBuilder.stream(SimpleRecordBuilder.builder().build()).toList(); 61 | Assertions.assertEquals(stream, 62 | List.of(new SimpleImmutableEntry<>("i", 0), new SimpleImmutableEntry<>("s", null))); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestSingleItems.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.time.Instant; 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.Map; 25 | import java.util.Set; 26 | 27 | public class TestSingleItems { 28 | @Test 29 | public void testInternalCollections() { 30 | var now = Instant.now(); 31 | var item = SingleItemsBuilder. builder().add1Map(now, "now").add1Map(Instant.MIN, "before") 32 | .add1Sets(Arrays.asList("1", "2")).add1Sets(List.of("3")).add1Strings("a").add1Strings("b") 33 | .add1Strings("c").build(); 34 | Assertions.assertEquals(item.map(), Map.of(now, "now", Instant.MIN, "before")); 35 | Assertions.assertEquals(item.sets(), Set.of(List.of("1", "2"), List.of("3"))); 36 | Assertions.assertEquals(item.strings(), List.of("a", "b", "c")); 37 | 38 | var copy = item.with().add1Strings("new").add1Map(Instant.MAX, "after").add1Sets(List.of("10", "20", "30")) 39 | .build(); 40 | Assertions.assertNotEquals(item, copy); 41 | Assertions.assertEquals(copy.map(), Map.of(now, "now", Instant.MIN, "before", Instant.MAX, "after")); 42 | Assertions.assertEquals(copy.sets(), Set.of(List.of("1", "2"), List.of("3"), List.of("10", "20", "30"))); 43 | Assertions.assertEquals(copy.strings(), List.of("a", "b", "c", "new")); 44 | 45 | var stringsToAdd = Arrays.asList("x", "y", "z"); 46 | var listToAdd = Arrays.asList(List.of("aa", "bb"), List.of("cc")); 47 | var mapToAdd = Map.of(now.plusMillis(1), "now+1", now.plusMillis(2), "now+2"); 48 | var streamed = SingleItemsBuilder.builder(item).add1Strings(stringsToAdd.stream()).add1Sets(listToAdd.stream()) 49 | .add1Map(mapToAdd.entrySet().stream()).build(); 50 | Assertions.assertEquals(streamed.map(), 51 | Map.of(now, "now", Instant.MIN, "before", now.plusMillis(1), "now+1", now.plusMillis(2), "now+2")); 52 | Assertions.assertEquals(streamed.sets(), 53 | Set.of(List.of("1", "2"), List.of("3"), List.of("aa", "bb"), List.of("cc"))); 54 | Assertions.assertEquals(streamed.strings(), Arrays.asList("a", "b", "c", "x", "y", "z")); 55 | 56 | var nulls = SingleItemsBuilder.builder(item).strings(null).sets(null).map(null).build(); 57 | Assertions.assertEquals(nulls.map(), Map.of()); 58 | Assertions.assertEquals(nulls.sets(), Set.of()); 59 | Assertions.assertEquals(nulls.strings(), List.of()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestTemplate.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.time.Instant; 22 | 23 | class TestTemplate { 24 | @Test 25 | void testTemplate() { 26 | var t = TemplateTestBuilder.TemplateTest("one", Instant.MIN); 27 | var w = t.withText("other"); 28 | Assertions.assertEquals("one", t.text()); 29 | Assertions.assertEquals("other", w.text()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestUnmodifiableCollectionsBuilder.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.HashSet; 23 | import java.util.LinkedHashMap; 24 | import java.util.LinkedHashSet; 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | import static java.util.Map.entry; 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | import static org.junit.jupiter.api.Assertions.assertAll; 31 | import static org.junit.jupiter.api.Assertions.assertThrows; 32 | 33 | public class TestUnmodifiableCollectionsBuilder { 34 | 35 | @Test 36 | void shouldWrapCollectionsWithUnmodifiableView() { 37 | // given 38 | var list = new ArrayList(); 39 | list.add(2); 40 | list.add(1); 41 | list.add(0); 42 | 43 | var orderedSet = new LinkedHashSet(); 44 | orderedSet.add("C"); 45 | orderedSet.add("B"); 46 | orderedSet.add("A"); 47 | 48 | var orderedMap = new LinkedHashMap(); 49 | orderedMap.put("C", 2); 50 | orderedMap.put("B", 1); 51 | orderedMap.put("A", 0); 52 | 53 | var collection = new HashSet(); 54 | collection.add("C"); 55 | collection.add("B"); 56 | collection.add("A"); 57 | 58 | // when 59 | var record = UnmodifiableCollectionsRecordBuilder.builder().aList(list).orderedSet(orderedSet) 60 | .orderedMap(orderedMap).aCollection(collection).build(); 61 | 62 | // then 63 | assertAll(() -> assertThrows(UnsupportedOperationException.class, () -> record.aList().add(9)), 64 | () -> assertThat(record.aList()).containsExactly(2, 1, 0), 65 | () -> assertThrows(UnsupportedOperationException.class, () -> record.orderedSet().add("newElement")), 66 | () -> assertThat(record.orderedSet()).containsExactly("C", "B", "A"), 67 | () -> assertThrows(UnsupportedOperationException.class, () -> record.orderedMap().put("newElement", 9)), 68 | () -> assertThat(record.orderedMap()).containsExactly(entry("C", 2), entry("B", 1), entry("A", 0)), 69 | () -> assertThrows(UnsupportedOperationException.class, () -> record.aCollection().add("newElement")), 70 | () -> assertThat(record.aCollection()).containsExactlyInAnyOrder("C", "B", "A")); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestValidation.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import javax.validation.ValidationException; 22 | import java.util.List; 23 | 24 | class TestValidation { 25 | @Test 26 | void testNotNulls() { 27 | Assertions.assertThrows(NullPointerException.class, () -> RequiredRecordBuilder.builder().build()); 28 | } 29 | 30 | @Test 31 | void testValidation() { 32 | Assertions.assertThrows(ValidationException.class, () -> RequiredRecord2Builder.builder().build()); 33 | } 34 | 35 | @Test 36 | void testNotNullsWithNewProperty() { 37 | var valid = RequiredRecordBuilder.builder().hey("hey").i(1).l(List.of()).build(); 38 | Assertions.assertThrows(NullPointerException.class, () -> valid.withHey(null)); 39 | } 40 | 41 | @Test 42 | void testValidationWithNewProperty() { 43 | var valid = RequiredRecord2Builder.builder().hey("hey").i(1).build(); 44 | Assertions.assertThrows(ValidationException.class, () -> valid.withHey(null)); 45 | } 46 | 47 | @Test 48 | void testRequestWithValid() { 49 | Assertions.assertDoesNotThrow( 50 | () -> RequestWithValidBuilder.builder().part(new RequestWithValid.Part("jsfjsf")).build()); 51 | Assertions.assertThrows(ValidationException.class, 52 | () -> RequestWithValidBuilder.builder().part(new RequestWithValid.Part("")).build()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestVariousOptions.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.List; 21 | import java.util.Map; 22 | import java.util.stream.Stream; 23 | 24 | import static org.junit.jupiter.api.Assertions.*; 25 | 26 | public class TestVariousOptions { 27 | 28 | @Test 29 | public void builderGetsCustomSetterAndGetterNames() { 30 | var obj = CustomMethodNamesBuilder.builder().setKvMap(Map.of(1, "one")).setTheValue(1).setTheList(List.of(2)) 31 | .setTheBoolean(true); 32 | assertEquals(1, obj.getTheValue()); 33 | assertEquals(List.of(2), obj.getTheList()); 34 | assertTrue(obj.isTheBoolean()); 35 | assertEquals(new CustomMethodNames<>(Map.of(1, "one"), 1, List.of(2), true), obj.build()); 36 | } 37 | 38 | @Test 39 | public void withBuilderGetsCustomSetterAndGetterNames() { 40 | var obj = CustomMethodNamesBuilder.from( 41 | CustomMethodNamesBuilder.builder().setTheValue(1).setTheList(List.of(2)).setTheBoolean(true).build()); 42 | assertEquals(1, obj.theValue()); 43 | assertEquals(List.of(2), obj.theList()); 44 | assertTrue(obj.theBoolean()); 45 | } 46 | 47 | @Test 48 | public void recordHasPrefixedGetters() { 49 | var obj = new CustomMethodNames<>(Map.of(1, "one"), 1, List.of(2), true); 50 | assertEquals(1, obj.getTheValue()); 51 | assertEquals(List.of(2), obj.getTheList()); 52 | assertTrue(obj.isTheBoolean()); 53 | } 54 | 55 | @Test 56 | public void noStaticBuilder() { 57 | boolean hasStaticBuilder = Stream.of(NoStaticBuilderBuilder.class.getDeclaredMethods()) 58 | .anyMatch(method -> method.getName().equals("NoStaticBuilder")); 59 | assertFalse(hasStaticBuilder); 60 | 61 | hasStaticBuilder = Stream.of(SimpleRecordBuilder.class.getDeclaredMethods()) 62 | .anyMatch(method -> method.getName().equals("SimpleRecord")); 63 | assertTrue(hasStaticBuilder); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/TestWithers.java: -------------------------------------------------------------------------------- 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; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.List; 22 | 23 | class TestWithers { 24 | @Test 25 | void testFromWithers() { 26 | var r1 = new SimpleGenericRecord<>(10, List.of("1", "2", "3")); 27 | var r2 = SimpleGenericRecordBuilder.from(r1).withS(List.of("4", "5")); 28 | var r3 = SimpleGenericRecordBuilder.from(r1).with(b -> b.i(20).s(List.of("6", "7"))); 29 | Assertions.assertEquals(List.of("1", "2", "3"), r1.s()); 30 | Assertions.assertEquals(List.of("4", "5"), r2.s()); 31 | Assertions.assertEquals(List.of("6", "7"), r3.s()); 32 | Assertions.assertEquals(20, r3.i()); 33 | } 34 | 35 | @Test 36 | void testWithers() { 37 | var r1 = new SimpleGenericRecord<>(10, List.of("1", "2", "3")); 38 | var r2 = r1.withS(List.of("4", "5")); 39 | var r3 = r2.withI(20); 40 | Assertions.assertEquals(10, r1.i()); 41 | Assertions.assertEquals(List.of("1", "2", "3"), r1.s()); 42 | Assertions.assertEquals(10, r2.i()); 43 | Assertions.assertEquals(List.of("4", "5"), r2.s()); 44 | Assertions.assertEquals(20, r3.i()); 45 | Assertions.assertEquals(List.of("4", "5"), r2.s()); 46 | } 47 | 48 | @Test 49 | void testWitherBuilder() { 50 | var r1 = new SimpleGenericRecord<>(10, "ten"); 51 | var r2 = r1.with().i(20).s("twenty").build(); 52 | var r3 = r2.with().s("changed"); 53 | Assertions.assertEquals(10, r1.i()); 54 | Assertions.assertEquals("ten", r1.s()); 55 | Assertions.assertEquals(20, r2.i()); 56 | Assertions.assertEquals("twenty", r2.s()); 57 | Assertions.assertEquals(20, r3.i()); 58 | Assertions.assertEquals("changed", r3.s()); 59 | } 60 | 61 | @Test 62 | void testWitherBuilderConsumer() { 63 | var r1 = new SimpleGenericRecord<>(10, "ten"); 64 | var r2 = r1.with(r -> r.i(15)); 65 | var r3 = r1.with(r -> r.s("twenty").i(20)); 66 | Assertions.assertEquals(10, r1.i()); 67 | Assertions.assertEquals("ten", r1.s()); 68 | Assertions.assertEquals(15, r2.i()); 69 | Assertions.assertEquals("ten", r2.s()); 70 | Assertions.assertEquals(20, r3.i()); 71 | Assertions.assertEquals("twenty", r3.s()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/deconstructors/TestGenericClass.java: -------------------------------------------------------------------------------- 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.deconstructors; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | public class TestGenericClass { 23 | @Test 24 | public void testBuilder() { 25 | GenericClass genericClass = new GenericClass<>("what?"); 26 | GenericClassDao unapplied = GenericClassDao.from(genericClass); 27 | assertThat(unapplied.t()).isEqualTo("what?"); 28 | 29 | GenericClassDao yo = GenericClassDaoBuilder. builder().t("yo").build(); 30 | assertThat(yo.t()).isEqualTo("yo"); 31 | 32 | GenericClassDao nope = yo.withT("nope"); 33 | assertThat(nope.t()).isEqualTo("nope"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/staged/TestStagedBuilder.java: -------------------------------------------------------------------------------- 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 org.junit.jupiter.api.Test; 19 | 20 | import java.math.BigDecimal; 21 | import java.math.BigInteger; 22 | import java.time.Instant; 23 | import java.util.List; 24 | import java.util.Optional; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | public class TestStagedBuilder { 29 | @Test 30 | void testSimple() { 31 | var now = Instant.now(); 32 | var obj = SimpleStagedBuilder.builder().i(1).s("s").instant(now).build(); 33 | assertEquals(new SimpleStaged(1, "s", now), obj); 34 | } 35 | 36 | @Test 37 | void testSimpleCombined() { 38 | var now = Instant.now(); 39 | var obj1 = CombinedSimpleStagedBuilder.builder().i(1).s("s").instant(now).build(); 40 | var obj2 = CombinedSimpleStagedBuilder.stagedBuilder().i(1).s("s").instant(now).build(); 41 | assertEquals(obj1, obj2); 42 | } 43 | 44 | @Test 45 | void testGeneric() { 46 | var now = Instant.now(); 47 | var obj = SimpleStagedBuilder.builder().i(1).s("s").instant(now).build(); 48 | 49 | GenericStaged generic = GenericStagedBuilder. builder().name("name") 50 | .aT(obj).theUThing("thing").build(); 51 | 52 | assertEquals(new GenericStaged<>("name", new SimpleStaged(1, "s", now), "thing"), generic); 53 | } 54 | 55 | @Test 56 | void testGenericCombined() { 57 | var now = Instant.now(); 58 | var builder = SimpleStagedBuilder.builder().i(1).s("s").instant(now).builder(); 59 | 60 | var obj1 = CombinedGenericStagedBuilder.builder().name("name") 61 | .aT(new GenericStaged<>("other", builder.build(), BigInteger.TEN)).theUThing(BigDecimal.ONE).build(); 62 | var obj2 = CombinedGenericStagedBuilder.stagedBuilder().name("name") 63 | .aT(new GenericStaged<>("other", builder.build(), BigInteger.TEN)).theUThing(BigDecimal.ONE).build(); 64 | assertEquals(obj1, obj2); 65 | } 66 | 67 | @Test 68 | void testSingleField() { 69 | SingleFieldStaged obj = SingleFieldStagedBuilder.builder().i(1).build(); 70 | assertEquals(new SingleFieldStaged(1), obj); 71 | } 72 | 73 | @Test 74 | void testNoFields() { 75 | NoFieldsStaged obj = NoFieldsStagedBuilder.builder().build(); 76 | assertEquals(new NoFieldsStaged(), obj); 77 | } 78 | 79 | @Test 80 | void testOptionalList() { 81 | OptionalListStaged obj = OptionalListStagedBuilder.builder().a(1).c(1.1).f("ffff").b(Optional.of("bbbb")) 82 | .d(List.of(Instant.EPOCH)).e("eeee").build(); 83 | assertEquals(new OptionalListStaged(1, Optional.of("bbbb"), 1.1, List.of(Instant.EPOCH), "eeee", "ffff"), obj); 84 | 85 | obj = OptionalListStagedBuilder.builder().a(1).c(1.1).f("ffff").build(); 86 | assertEquals(new OptionalListStaged(1, Optional.empty(), 1.1, List.of(), null, "ffff"), obj); 87 | } 88 | 89 | @Test 90 | void testInitialized() { 91 | InitializedStaged obj = InitializedStagedBuilder.builder().name("foo").age(42).build(); 92 | assertEquals(new InitializedStaged(42, "foo"), obj); 93 | } 94 | 95 | @Test 96 | void testOptionalStagedRequiredOnlyConcreteSetter() { 97 | OptionalStagedRequiredOnly obj = OptionalStagedRequiredOnlyBuilder.builder().a(1).c("cccc").build(); 98 | assertEquals(new OptionalStagedRequiredOnly(1, Optional.empty(), "cccc"), obj); 99 | 100 | obj = OptionalStagedRequiredOnlyBuilder.builder().a(1).c("cccc").b(Optional.of("bbbb")).build(); 101 | assertEquals(new OptionalStagedRequiredOnly(1, Optional.of("bbbb"), "cccc"), obj); 102 | 103 | obj = OptionalStagedRequiredOnlyBuilder.builder().a(1).c("cccc").b("bbbb").build(); 104 | assertEquals(new OptionalStagedRequiredOnly(1, Optional.of("bbbb"), "cccc"), obj); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /record-builder-test/src/test/java/io/soabase/recordbuilder/test/visibility/TestVisibility.java: -------------------------------------------------------------------------------- 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.visibility; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.lang.reflect.Modifier; 22 | 23 | class TestVisibility { 24 | @Test 25 | void testMatches() { 26 | Assertions.assertFalse(Modifier.isPublic(PackagePrivateRecordBuilder.class.getModifiers())); 27 | Assertions.assertFalse(Modifier.isPrivate(PackagePrivateRecordBuilder.class.getModifiers())); 28 | Assertions.assertFalse(Modifier.isProtected(PackagePrivateRecordBuilder.class.getModifiers())); 29 | 30 | Assertions.assertTrue(Modifier.isPublic(WrapperProtectedRecordBuilder.class.getModifiers())); 31 | } 32 | 33 | @Test 34 | void testMatchesWithModifers() { 35 | Assertions.assertFalse(Modifier.isPublic(PackagePrivateRecordWithPublicBuilder.class.getModifiers())); 36 | Assertions.assertFalse(Modifier.isPrivate(PackagePrivateRecordWithPublicBuilder.class.getModifiers())); 37 | Assertions.assertFalse(Modifier.isProtected(PackagePrivateRecordWithPublicBuilder.class.getModifiers())); 38 | 39 | Assertions.assertTrue(Modifier.isPublic(PackagePrivateRecordWithPublicBuilderBuilder.class.getModifiers())); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /record-builder-validator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | io.soabase.record-builder 22 | record-builder 23 | 48-SNAPSHOT 24 | 25 | 4.0.0 26 | 27 | record-builder-validator 28 | 29 | 30 | ${project.parent.basedir}/src/etc/header.txt 31 | io.soabase.recordbuilder.validator 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /record-builder-validator/src/main/java/io/soabase/recordbuilder/validator/RecordBuilderValidator.java: -------------------------------------------------------------------------------- 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.validator; 17 | 18 | import java.lang.reflect.Constructor; 19 | import java.lang.reflect.InvocationTargetException; 20 | import java.lang.reflect.Method; 21 | import java.util.Collection; 22 | import java.util.Set; 23 | 24 | // complete Java Validation via reflection to avoid dependencies 25 | public class RecordBuilderValidator { 26 | private static final Object validator; 27 | private static final Method validationMethod; 28 | private static final Constructor constraintViolationExceptionCtor; 29 | private static final Class[] emptyGroups = new Class[0]; 30 | 31 | private static final boolean PRINT_ERROR_STACKTRACE = Boolean.getBoolean("record_builder_validator_errors"); 32 | 33 | static { 34 | Object localValidator = null; 35 | Method localValidationMethod = null; 36 | Constructor localConstraintViolationExceptionCtor = null; 37 | try { 38 | var validationClass = Class.forName("javax.validation.Validation"); 39 | var factoryClass = validationClass.getDeclaredMethod("buildDefaultValidatorFactory"); 40 | var factory = factoryClass.invoke(null); 41 | var getValidatorMethod = factory.getClass().getMethod("getValidator"); 42 | var constraintViolationExceptionClass = Class.forName("javax.validation.ConstraintViolationException"); 43 | localValidator = getValidatorMethod.invoke(factory); 44 | localValidationMethod = localValidator.getClass().getMethod("validate", Object.class, Class[].class); 45 | localConstraintViolationExceptionCtor = constraintViolationExceptionClass.getConstructor(Set.class); 46 | } catch (Exception e) { 47 | if (PRINT_ERROR_STACKTRACE) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | validator = localValidator; 52 | validationMethod = localValidationMethod; 53 | constraintViolationExceptionCtor = localConstraintViolationExceptionCtor; 54 | } 55 | 56 | public static T validate(T o) { 57 | if ((validator != null) && (validationMethod != null)) { 58 | try { 59 | var violations = validationMethod.invoke(validator, o, emptyGroups); 60 | if (!((Collection) violations).isEmpty()) { 61 | throw (RuntimeException) constraintViolationExceptionCtor.newInstance(violations); 62 | } 63 | } catch (IllegalAccessException | InstantiationException e) { 64 | throw new RuntimeException(e); 65 | } catch (InvocationTargetException e) { 66 | if (e.getCause() != null) { 67 | if (e.getCause() instanceof RuntimeException) { 68 | throw (RuntimeException) e.getCause(); 69 | } 70 | throw new RuntimeException(e.getCause()); 71 | } 72 | throw new RuntimeException(e); 73 | } 74 | } 75 | return o; 76 | } 77 | 78 | private RecordBuilderValidator() { 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright ${year} The original author or authors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | --------------------------------------------------------------------------------