Skip to content

Commit 0d73ac6

Browse files
committed
Allow subtypes of Map for Collection elements
Related to #693.
1 parent 0fde051 commit 0d73ac6

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/model/TypeProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public FieldSpec asField(MemberModel memberModel, Modifier... modifiers) {
201201
private TypeName listParameterType(ListModel listModel) {
202202
MemberModel elementModel = listModel.getListMemberModel();
203203
TypeName listElementType = parameterType(elementModel);
204-
if (elementModel.isList()) {
204+
if (isContainerType(elementModel)) {
205205
listElementType = WildcardTypeName.subtypeOf(listElementType);
206206
}
207207
return ParameterizedTypeName.get(ClassName.get(Collection.class), listElementType);
@@ -227,4 +227,8 @@ private TypeName mapValueParameterType(MapModel mapModel) {
227227

228228
return valueType;
229229
}
230+
231+
private static boolean isContainerType(MemberModel m) {
232+
return m.isList() || m.isMap();
233+
}
230234
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/alltypesrequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ public interface Builder extends JsonProtocolTestsRequest.Builder, CopyableBuild
757757
* The new value for the ListOfMaps property for this object.
758758
* @return Returns a reference to this object so that method calls can be chained together.
759759
*/
760-
Builder listOfMaps(Collection<Map<String, String>> listOfMaps);
760+
Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps);
761761

762762
/**
763763
* Sets the value of the ListOfMaps property for this object.
@@ -1341,12 +1341,12 @@ public final void setListOfEnums(Collection<String> listOfEnums) {
13411341
this.listOfEnums = ListOfEnumsCopier.copy(listOfEnums);
13421342
}
13431343

1344-
public final Collection<Map<String, String>> getListOfMaps() {
1344+
public final Collection<? extends Map<String, String>> getListOfMaps() {
13451345
return listOfMaps;
13461346
}
13471347

13481348
@Override
1349-
public final Builder listOfMaps(Collection<Map<String, String>> listOfMaps) {
1349+
public final Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13501350
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13511351
return this;
13521352
}
@@ -1358,7 +1358,7 @@ public final Builder listOfMaps(Map<String, String>... listOfMaps) {
13581358
return this;
13591359
}
13601360

1361-
public final void setListOfMaps(Collection<Map<String, String>> listOfMaps) {
1361+
public final void setListOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13621362
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13631363
}
13641364

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/alltypesresponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ public interface Builder extends JsonProtocolTestsResponse.Builder, CopyableBuil
756756
* The new value for the ListOfMaps property for this object.
757757
* @return Returns a reference to this object so that method calls can be chained together.
758758
*/
759-
Builder listOfMaps(Collection<Map<String, String>> listOfMaps);
759+
Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps);
760760

761761
/**
762762
* Sets the value of the ListOfMaps property for this object.
@@ -1334,12 +1334,12 @@ public final void setListOfEnums(Collection<String> listOfEnums) {
13341334
this.listOfEnums = ListOfEnumsCopier.copy(listOfEnums);
13351335
}
13361336

1337-
public final Collection<Map<String, String>> getListOfMaps() {
1337+
public final Collection<? extends Map<String, String>> getListOfMaps() {
13381338
return listOfMaps;
13391339
}
13401340

13411341
@Override
1342-
public final Builder listOfMaps(Collection<Map<String, String>> listOfMaps) {
1342+
public final Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13431343
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13441344
return this;
13451345
}
@@ -1351,7 +1351,7 @@ public final Builder listOfMaps(Map<String, String>... listOfMaps) {
13511351
return this;
13521352
}
13531353

1354-
public final void setListOfMaps(Collection<Map<String, String>> listOfMaps) {
1354+
public final void setListOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13551355
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13561356
}
13571357

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/listofmapstringtostringcopier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@Generated("software.amazon.awssdk:codegen")
1414
final class ListOfMapStringToStringCopier {
15-
static List<Map<String, String>> copy(Collection<Map<String, String>> listOfMapStringToStringParam) {
15+
static List<Map<String, String>> copy(Collection<? extends Map<String, String>> listOfMapStringToStringParam) {
1616
if (listOfMapStringToStringParam == null || listOfMapStringToStringParam instanceof SdkAutoConstructList) {
1717
return DefaultSdkAutoConstructList.getInstance();
1818
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/nonautoconstructcontainers/alltypesrequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ public interface Builder extends JsonProtocolTestsRequest.Builder, CopyableBuild
755755
* The new value for the ListOfMaps property for this object.
756756
* @return Returns a reference to this object so that method calls can be chained together.
757757
*/
758-
Builder listOfMaps(Collection<Map<String, String>> listOfMaps);
758+
Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps);
759759

760760
/**
761761
* Sets the value of the ListOfMaps property for this object.
@@ -1339,12 +1339,12 @@ public final void setListOfEnums(Collection<String> listOfEnums) {
13391339
this.listOfEnums = ListOfEnumsCopier.copy(listOfEnums);
13401340
}
13411341

1342-
public final Collection<Map<String, String>> getListOfMaps() {
1342+
public final Collection<? extends Map<String, String>> getListOfMaps() {
13431343
return listOfMaps;
13441344
}
13451345

13461346
@Override
1347-
public final Builder listOfMaps(Collection<Map<String, String>> listOfMaps) {
1347+
public final Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13481348
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13491349
return this;
13501350
}
@@ -1356,7 +1356,7 @@ public final Builder listOfMaps(Map<String, String>... listOfMaps) {
13561356
return this;
13571357
}
13581358

1359-
public final void setListOfMaps(Collection<Map<String, String>> listOfMaps) {
1359+
public final void setListOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13601360
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13611361
}
13621362

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/nonautoconstructcontainers/alltypesresponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ public interface Builder extends JsonProtocolTestsResponse.Builder, CopyableBuil
754754
* The new value for the ListOfMaps property for this object.
755755
* @return Returns a reference to this object so that method calls can be chained together.
756756
*/
757-
Builder listOfMaps(Collection<Map<String, String>> listOfMaps);
757+
Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps);
758758

759759
/**
760760
* Sets the value of the ListOfMaps property for this object.
@@ -1332,12 +1332,12 @@ public final void setListOfEnums(Collection<String> listOfEnums) {
13321332
this.listOfEnums = ListOfEnumsCopier.copy(listOfEnums);
13331333
}
13341334

1335-
public final Collection<Map<String, String>> getListOfMaps() {
1335+
public final Collection<? extends Map<String, String>> getListOfMaps() {
13361336
return listOfMaps;
13371337
}
13381338

13391339
@Override
1340-
public final Builder listOfMaps(Collection<Map<String, String>> listOfMaps) {
1340+
public final Builder listOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13411341
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13421342
return this;
13431343
}
@@ -1349,7 +1349,7 @@ public final Builder listOfMaps(Map<String, String>... listOfMaps) {
13491349
return this;
13501350
}
13511351

1352-
public final void setListOfMaps(Collection<Map<String, String>> listOfMaps) {
1352+
public final void setListOfMaps(Collection<? extends Map<String, String>> listOfMaps) {
13531353
this.listOfMaps = ListOfMapStringToStringCopier.copy(listOfMaps);
13541354
}
13551355

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/nonautoconstructcontainers/listofmapstringtostringcopier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@Generated("software.amazon.awssdk:codegen")
1212
final class ListOfMapStringToStringCopier {
13-
static List<Map<String, String>> copy(Collection<Map<String, String>> listOfMapStringToStringParam) {
13+
static List<Map<String, String>> copy(Collection<? extends Map<String, String>> listOfMapStringToStringParam) {
1414
if (listOfMapStringToStringParam == null) {
1515
return null;
1616
}

0 commit comments

Comments
 (0)