Skip to content

Commit

Permalink
feat: Support IsLimitSet and similar members
Browse files Browse the repository at this point in the history
  • Loading branch information
ajewellamz committed Nov 16, 2023
1 parent 2b138b9 commit e346017
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ public String isSetMethodForStructureMember(final MemberShape memberShape) {
return "IsSet%s".formatted(classPropertyForStructureMember(memberShape));
}

/**
* Returns the name of the given member shape's IsSet member
*/
public String isSetMemberForStructureMember(final MemberShape memberShape) {
return "Is%sSet".formatted(classPropertyForStructureMember(memberShape));
}

/**
* Returns the name of the class property fur use as a variable name, i.e. the first letter is lower case
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,24 @@ private String generateConstructorArg(final MemberShape memberShape) {
nameResolver.classPropertyForStructureMember(memberShape));
}

// return false if this struct/member is one of the special ones with a IsXxxSet member
public boolean IsNormal(final MemberShape memberShape)
{
String parent = memberShape.getId().getName();
String member = nameResolver.classPropertyForStructureMember(memberShape);
if (parent.equals("ScanInput")) {
if (member.equals("TotalSegments") ||
member.equals("Segment") ||
member.equals("Limit")) {
return false;
}
}
if (parent.equals("QueryInput") && member.equals("Limit")) {
return false;
}
return true;
}

/**
* Returns:
* "type varName = value.IsSetPropertyName() ? value.PropertyName : (type) null;"
Expand All @@ -488,14 +506,25 @@ public TokenTree generateExtractOptionalMember(final MemberShape memberShape) {
final String varName = nameResolver.variableNameForClassProperty(memberShape);
final String propertyName = nameResolver.classPropertyForStructureMember(memberShape);
if (AwsSdkNameResolverHelpers.isInAwsSdkNamespace(memberShape.getId())) {
return TokenTree.of(
type,
varName,
"= value.%s != null".formatted(propertyName),
"? value.%s :".formatted(propertyName),
"(%s) null;".formatted(type)
);
} else {
if (IsNormal(memberShape)) {
return TokenTree.of(
type,
varName,
"= value.%s != null".formatted(propertyName),
"? value.%s :".formatted(propertyName),
"(%s) null;".formatted(type)
);
} else {
final String isSetMethod = nameResolver.isSetMemberForStructureMember(memberShape);
return TokenTree.of(
type,
varName,
"= value.%s".formatted(isSetMethod),
"? value.%s :".formatted(propertyName),
"(%s) null;".formatted(type)
);
}
} else {
final String isSetMethod = nameResolver.isSetMethodForStructureMember(memberShape);
return TokenTree.of(
type,
Expand Down

0 comments on commit e346017

Please sign in to comment.