Configurable modifiers on static builders (#135)
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.soabase.recordbuilder.core;
|
package io.soabase.recordbuilder.core;
|
||||||
|
|
||||||
|
import javax.lang.model.element.Modifier;
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@@ -270,6 +271,13 @@ public @interface RecordBuilder {
|
|||||||
* uses an internal class to track changes to maps. This is the name of that class.
|
* uses an internal class to track changes to maps. This is the name of that class.
|
||||||
*/
|
*/
|
||||||
String mutableMapClassName() default "_MutableMap";
|
String mutableMapClassName() default "_MutableMap";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any additional {@link javax.lang.model.element.Modifier} you wish to apply to the builder. For example to
|
||||||
|
* make the builder public when the record is package protect.
|
||||||
|
*/
|
||||||
|
Modifier[] builderClassModifiers() default {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.CLASS)
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class InternalRecordBuilderProcessor {
|
|||||||
|
|
||||||
builder = TypeSpec.classBuilder(builderClassType.name())
|
builder = TypeSpec.classBuilder(builderClassType.name())
|
||||||
.addAnnotation(generatedRecordBuilderAnnotation)
|
.addAnnotation(generatedRecordBuilderAnnotation)
|
||||||
|
.addModifiers(metaData.builderClassModifiers())
|
||||||
.addTypeVariables(typeVariables);
|
.addTypeVariables(typeVariables);
|
||||||
if (metaData.addClassRetainedGenerated()) {
|
if (metaData.addClassRetainedGenerated()) {
|
||||||
builder.addAnnotation(recordBuilderGeneratedAnnotation);
|
builder.addAnnotation(recordBuilderGeneratedAnnotation);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2019 Jordan Zimmerman
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.soabase.recordbuilder.test.visibility;
|
||||||
|
|
||||||
|
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||||
|
|
||||||
|
import javax.lang.model.element.Modifier;
|
||||||
|
|
||||||
|
|
||||||
|
@RecordBuilder.Options(builderClassModifiers = {Modifier.PUBLIC})
|
||||||
|
@RecordBuilder
|
||||||
|
record PackagePrivateRecordWithPublicBuilder(String value) {
|
||||||
|
}
|
||||||
@@ -29,4 +29,15 @@ class TestVisibility {
|
|||||||
|
|
||||||
Assertions.assertTrue(Modifier.isPublic(WrapperProtectedRecordBuilder.class.getModifiers()));
|
Assertions.assertTrue(Modifier.isPublic(WrapperProtectedRecordBuilder.class.getModifiers()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMatchesWithModifers() {
|
||||||
|
Assertions.assertFalse(Modifier.isPublic(PackagePrivateRecordWithPublicBuilder.class.getModifiers()));
|
||||||
|
Assertions.assertFalse(Modifier.isPrivate(PackagePrivateRecordWithPublicBuilder.class.getModifiers()));
|
||||||
|
Assertions.assertFalse(Modifier.isProtected(PackagePrivateRecordWithPublicBuilder.class.getModifiers()));
|
||||||
|
|
||||||
|
Assertions.assertTrue(Modifier.isPublic(PackagePrivateRecordWithPublicBuilderBuilder.class.getModifiers()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user