Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.*;
import java.util.regex.Pattern;

import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.generatedRecordBuilderAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.recordBuilderGeneratedAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.suppressWarningsAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.*;

class CollectionBuilderUtils {
private final boolean useImmutableCollections;
Expand Down Expand Up @@ -388,9 +386,6 @@ private MethodSpec buildShimMethod(String name, TypeName mainType, Class<?> abst
var extendedParameterizedType = ParameterizedTypeName.get(ClassName.get(abstractType), wildCardTypeArguments);

MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(name);
if (!useImmutableCollections) {
methodBuilder.addAnnotation(suppressWarningsAnnotation);
}
return methodBuilder.addAnnotation(generatedRecordBuilderAnnotation)
.addModifiers(Modifier.PRIVATE, Modifier.STATIC).addTypeVariables(Arrays.asList(typeVariables))
.returns(parameterizedType).addParameter(extendedParameterizedType, "o").addStatement(code).build();
Expand Down Expand Up @@ -486,6 +481,8 @@ private TypeSpec buildMutableCollectionSubType(String className, ClassName mutab
builder.addAnnotation(recordBuilderGeneratedAnnotation);
}

builder.addAnnotation(suppressWarningsAnnotation);

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
import static io.soabase.recordbuilder.processor.ElementUtils.hasAnnotationTarget;
import static io.soabase.recordbuilder.processor.InternalRecordBuilderProcessor.capitalize;
import static io.soabase.recordbuilder.processor.ParameterSpecUtil.createParameterSpec;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.generatedRecordBuilderAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.recordBuilderGeneratedAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.*;

class InternalDeconstructorProcessor {
private final String packageName;
Expand Down Expand Up @@ -112,6 +111,8 @@ class InternalDeconstructorProcessor {
builder.addAnnotation(recordBuilderGeneratedAnnotation);
}

builder.addAnnotation(suppressWarningsAnnotation);

addVisibility(element.getModifiers());
addRecordComponents();
addDeconstructorMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import static io.soabase.recordbuilder.processor.CollectionBuilderUtils.SingleItemsMetaDataMode.STANDARD_FOR_SETTER;
import static io.soabase.recordbuilder.processor.ElementUtils.*;
import static io.soabase.recordbuilder.processor.ParameterSpecUtil.createParameterSpec;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.generatedRecordBuilderAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.recordBuilderGeneratedAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.*;
import static javax.tools.Diagnostic.Kind.ERROR;

class InternalRecordBuilderProcessor {
Expand Down Expand Up @@ -88,6 +87,7 @@ class InternalRecordBuilderProcessor {
if (metaData.addClassRetainedGenerated()) {
builder.addAnnotation(recordBuilderGeneratedAnnotation);
}
builder.addAnnotation(suppressWarningsAnnotation);

if (!validateMethodNameConflicts(processingEnv, recordFacade.element())) {
builderType = Optional.empty();
Expand Down Expand Up @@ -264,6 +264,7 @@ private void addStagedBuilderClasses() {
if (metaData.addClassRetainedGenerated()) {
classBuilder.addAnnotation(recordBuilderGeneratedAnnotation);
}
classBuilder.addAnnotation(suppressWarningsAnnotation);

MethodSpec buildMethod = buildMethod().addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
.addStatement("return $L().$L()", metaData.builderMethodName(), metaData.buildMethodName()).build();
Expand Down Expand Up @@ -313,6 +314,7 @@ private void add1StagedBuilderClass(RecordClassType component, Optional<RecordCl
if (metaData.addClassRetainedGenerated()) {
classBuilder.addAnnotation(recordBuilderGeneratedAnnotation);
}
classBuilder.addAnnotation(suppressWarningsAnnotation);

var returnType = nextComponent.map(this::stagedBuilderType)
.orElseGet(() -> stagedBuilderType(builderClassType));
Expand Down Expand Up @@ -375,6 +377,7 @@ private void addWithNestedClass() {
if (metaData.addClassRetainedGenerated()) {
classBuilder.addAnnotation(recordBuilderGeneratedAnnotation);
}
classBuilder.addAnnotation(suppressWarningsAnnotation);
recordComponents.forEach(component -> addNestedGetterMethod(classBuilder, component, component.name()));
addWithBuilderMethod(classBuilder);
addWithSuppliedBuilderMethod(classBuilder);
Expand All @@ -398,7 +401,7 @@ private void addBeanNestedClass() {
var classBuilder = TypeSpec.interfaceBuilder(metaData.beanClassName())
.addAnnotation(generatedRecordBuilderAnnotation)
.addJavadoc("Add getters to {@code $L}\n", recordClassType.name()).addModifiers(Modifier.PUBLIC)
.addTypeVariables(typeVariables);
.addTypeVariables(typeVariables).addAnnotation(suppressWarningsAnnotation);
recordComponents.forEach(component -> {
if (prefixedName(component, true).equals(component.name())) {
return;
Expand Down Expand Up @@ -754,6 +757,7 @@ private void addFromWithClass() {
if (metaData.addClassRetainedGenerated()) {
fromWithClassBuilder.addAnnotation(recordBuilderGeneratedAnnotation);
}
fromWithClassBuilder.addAnnotation(suppressWarningsAnnotation);

fromWithClassBuilder.addField(recordClassType.typeName(), "from", Modifier.PRIVATE, Modifier.FINAL);
MethodSpec constructorSpec = MethodSpec.constructorBuilder().addParameter(recordClassType.typeName(), "from")
Expand Down Expand Up @@ -1216,7 +1220,8 @@ private TypeSpec buildFunctionalInterface(String className, boolean isMap) {
}
return TypeSpec.interfaceBuilder(className).addAnnotation(generatedRecordBuilderAnnotation)
.addAnnotation(FunctionalInterface.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addTypeVariables(localTypeVariables).addMethod(methodBuilder.build()).build();
.addTypeVariables(localTypeVariables).addMethod(methodBuilder.build())
.addAnnotation(suppressWarningsAnnotation).build();
}

private String prefixedName(RecordClassType component, boolean isGetter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import java.util.stream.Collectors;

import static io.soabase.recordbuilder.processor.ElementUtils.generateName;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.generatedRecordInterfaceAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.recordBuilderGeneratedAnnotation;
import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.*;

class InternalRecordInterfaceProcessor {
private final ProcessingEnvironment processingEnv;
Expand Down Expand Up @@ -95,6 +94,8 @@ private record Component(ExecutableElement element, Optional<String> alternateNa
}
}

builder.addAnnotation(suppressWarningsAnnotation);

addAlternateMethods(builder, recordComponents);

recordType = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class RecordBuilderProcessor extends AbstractProcessor {
static final AnnotationSpec generatedRecordBuilderAnnotation = AnnotationSpec.builder(Generated.class)
.addMember("value", "$S", RecordBuilder.class.getName()).build();
static final AnnotationSpec suppressWarningsAnnotation = AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "unchecked").build();
.addMember("value", "{$S, $S}", "all", "cast").build();
static final AnnotationSpec generatedRecordInterfaceAnnotation = AnnotationSpec.builder(Generated.class)
.addMember("value", "$S", RecordInterface.class.getName()).build();
static final AnnotationSpec recordBuilderGeneratedAnnotation = AnnotationSpec.builder(RecordBuilderGenerated.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019 The original author or authors
*
* 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;

import io.soabase.recordbuilder.core.RecordBuilder;

@RecordBuilder
public record DeprecatedComponentRecord(@Deprecated String oldField, String newField)
implements DeprecatedComponentRecordBuilder.With {
}
Loading