Skip to content
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

feat: Support IsLimitSet and similar members #303

Merged
merged 3 commits into from
Nov 16, 2023
Merged
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 @@ -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 true if this struct/member is one of the special ones with a IsXxxSet member
public boolean memberSupportsIsSet(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 true;
}
}
if (parent.equals("QueryInput") && member.equals("Limit")) {
return true;
}
return false;
}

/**
* 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 (memberSupportsIsSet(memberShape)) {
final String isSetMember = nameResolver.isSetMemberForStructureMember(memberShape);
return TokenTree.of(
type,
varName,
"= value.%s".formatted(isSetMember),
"? value.%s :".formatted(propertyName),
"(%s) null;".formatted(type)
);
} else {
return TokenTree.of(
type,
varName,
"= value.%s != null".formatted(propertyName),
"? value.%s :".formatted(propertyName),
"(%s) null;".formatted(type)
);
}
} else {
final String isSetMethod = nameResolver.isSetMethodForStructureMember(memberShape);
return TokenTree.of(
type,
Expand Down
Loading