|
19 | 19 | import io.soabase.recordbuilder.core.RecordBuilder;
|
20 | 20 |
|
21 | 21 | import javax.lang.model.element.Modifier;
|
| 22 | +import java.io.Serial; |
22 | 23 | import java.util.*;
|
23 | 24 | import java.util.regex.Pattern;
|
24 | 25 |
|
25 | 26 | import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.generatedRecordBuilderAnnotation;
|
26 | 27 | import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.recordBuilderGeneratedAnnotation;
|
| 28 | +import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.suppressWarningsAnnotation; |
27 | 29 |
|
28 | 30 | class CollectionBuilderUtils {
|
29 | 31 | private final boolean useImmutableCollections;
|
@@ -384,7 +386,12 @@ private MethodSpec buildShimMethod(String name, TypeName mainType, Class<?> abst
|
384 | 386 | TypeName[] wildCardTypeArguments = parameterizedType.typeArguments.stream().map(WildcardTypeName::subtypeOf)
|
385 | 387 | .toList().toArray(new TypeName[0]);
|
386 | 388 | var extendedParameterizedType = ParameterizedTypeName.get(ClassName.get(abstractType), wildCardTypeArguments);
|
387 |
| - return MethodSpec.methodBuilder(name).addAnnotation(generatedRecordBuilderAnnotation) |
| 389 | + |
| 390 | + MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(name); |
| 391 | + if (!useImmutableCollections) { |
| 392 | + methodBuilder.addAnnotation(suppressWarningsAnnotation); |
| 393 | + } |
| 394 | + return methodBuilder.addAnnotation(generatedRecordBuilderAnnotation) |
388 | 395 | .addModifiers(Modifier.PRIVATE, Modifier.STATIC).addTypeVariables(Arrays.asList(typeVariables))
|
389 | 396 | .returns(parameterizedType).addParameter(extendedParameterizedType, "o").addStatement(code).build();
|
390 | 397 | }
|
@@ -467,6 +474,9 @@ private TypeSpec buildMutableCollectionSubType(String className, ClassName mutab
|
467 | 474 | .addModifiers(Modifier.PRIVATE, Modifier.STATIC)
|
468 | 475 | .superclass(ParameterizedTypeName.get(mutableCollectionType, typeArguments))
|
469 | 476 | .addTypeVariables(Arrays.asList(typeVariables))
|
| 477 | + .addField(FieldSpec |
| 478 | + .builder(TypeName.LONG, "serialVersionUID", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) |
| 479 | + .addAnnotation(Serial.class).initializer("1L").build()) |
470 | 480 | .addMethod(MethodSpec.constructorBuilder().addAnnotation(generatedRecordBuilderAnnotation)
|
471 | 481 | .addStatement("super()").build())
|
472 | 482 | .addMethod(MethodSpec.constructorBuilder().addAnnotation(generatedRecordBuilderAnnotation)
|
|
0 commit comments