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 1 commit
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 false if this struct/member is one of the special ones with a IsXxxSet member
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// return false if this struct/member is one of the special ones with a IsXxxSet member
// return true if this struct/member is one of the special ones with a IsXxxSet member

public boolean IsNormal(final MemberShape memberShape)
ajewellamz marked this conversation as resolved.
Show resolved Hide resolved
{
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;
ajewellamz marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (parent.equals("QueryInput") && member.equals("Limit")) {
return false;
ajewellamz marked this conversation as resolved.
Show resolved Hide resolved
}
return true;
ajewellamz marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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)) {
ajewellamz marked this conversation as resolved.
Show resolved Hide resolved
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
Loading