-
Notifications
You must be signed in to change notification settings - Fork 906
Rewrote generated copiers to support builders for arbitrarily nested containers. #2423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
82bbd76
to
33e509f
Compare
<exclude>*.SubscribeToShardEvent$BuilderImpl</exclude> | ||
<exclude>*.ConfigurationEvent$BuilderImpl</exclude> | ||
<exclude>*.IntentResultEvent$BuilderImpl</exclude> | ||
<exclude>*.TextResponseEvent$BuilderImpl</exclude> | ||
<exclude>*.IntentResultEvent$BuilderImpl</exclude> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bean-style getter return type had to be changed.
if (memberModel.hasBuilder()) { | ||
TypeName builderName = poetExtensions.getModelClass(memberModel.getC2jShape()).nestedClass("BuilderImpl"); | ||
return ParameterSpec.builder(builderName, fieldName()).build(); | ||
} | ||
|
||
if (memberModel.isList()) { | ||
if (memberModel.isCollectionWithNestedBuilderMember()) { | ||
MapModel nestedMapModel = memberModel.getListModel().getListMemberModel().getMapModel(); | ||
TypeName nestedMapKeyType = typeProvider.getTypeNameForSimpleType(nestedMapModel.getKeyModel() | ||
.getVariable() | ||
.getVariableType()); | ||
ClassName nestedMapValueType = poetExtensions.getModelClass(nestedMapModel.getValueModel().getC2jShape()); | ||
TypeName nestedMapReturnType = ParameterizedTypeName.get(ClassName.get(Map.class), | ||
nestedMapKeyType, | ||
nestedMapValueType.nestedClass("BuilderImpl")); | ||
TypeName listType = ParameterizedTypeName.get(ClassName.get(Collection.class), nestedMapReturnType); | ||
return ParameterSpec.builder(listType, fieldName()).build(); | ||
} | ||
|
||
MemberModel listMember = memberModel.getListModel().getListMemberModel(); | ||
|
||
if (hasBuilder(listMember)) { | ||
TypeName memberName = poetExtensions.getModelClass(listMember.getC2jShape()).nestedClass("BuilderImpl"); | ||
TypeName listType = ParameterizedTypeName.get(ClassName.get(Collection.class), memberName); | ||
return ParameterSpec.builder(listType, fieldName()).build(); | ||
} else if (listMember.isSdkBytesType()) { | ||
TypeName listType = ParameterizedTypeName.get(Collection.class, ByteBuffer.class); | ||
return ParameterSpec.builder(listType, fieldName()).build(); | ||
} | ||
} | ||
|
||
if (memberModel.isMap()) { | ||
MemberModel keyModel = memberModel.getMapModel().getKeyModel(); | ||
TypeName keyType = typeProvider.getTypeNameForSimpleType(keyModel.getVariable().getVariableType()); | ||
MemberModel valueModel = memberModel.getMapModel().getValueModel(); | ||
TypeName valueType = null; | ||
|
||
if (hasBuilder(valueModel)) { | ||
valueType = poetExtensions.getModelClass(valueModel.getC2jShape()).nestedClass("BuilderImpl"); | ||
} else if (valueModel.isSdkBytesType()) { | ||
valueType = TypeName.get(ByteBuffer.class); | ||
} | ||
|
||
if (valueType != null) { | ||
TypeName mapType = ParameterizedTypeName.get(ClassName.get(Map.class), keyType, valueType); | ||
return ParameterSpec.builder(mapType, fieldName()).build(); | ||
} | ||
} | ||
|
||
if (memberModel.isSdkBytesType()) { | ||
return ParameterSpec.builder(ByteBuffer.class, fieldName()).build(); | ||
} | ||
|
||
return memberAsParameter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for removing this!
@@ -482,4 +350,17 @@ private String memberParamName() { | |||
} | |||
return Utils.unCapitalize(memberModel.getC2jShape()) + "Param"; | |||
} | |||
|
|||
private static final class VariableSource { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class name is too generic for me, I'd prefer if it was renamed to be more specific to its task.
IDK if I love disambiguator but it's the only think I can think of now :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a better name. It provides unique variable names... UniqueVariableSource? VariableUniquifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UniqueVariableSource is better than VariableSource
NONE | ||
} | ||
|
||
public static final class TypeNameOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class makes it much easier to reason around how to build types
…containers. This fixes an issue where DynamoDB types like BatchGetResponse.Builder could not be serialized using a bean-based serializer, because it contained a Map<K, List<Map<K2, V>>.
b352025
to
0dfee39
Compare
Kudos, SonarCloud Quality Gate passed! |
…ed10593a8 Pull request: release <- staging/4849877e-99ce-403a-ad32-ac2ed10593a8
This fixes an issue where DynamoDB types like BatchGetResponse.Builder could not be serialized using
a bean-based serializer, because it contained a Map<K, List<Map<K2, V>>.