Skip to content

Commit

Permalink
fix: change function name for positional trait (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit authored Nov 13, 2024
1 parent b4b811e commit 78b79ae
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ private void renderListShape(
) {
final String funcName = Constants.funcNameGenerator(
memberShape,
"Validate"
"Validate",
context.model()
);
final String funcInput = dataSource.startsWith("input") ? "" : dataSource;
if (!funcInput.isEmpty()) {
Expand Down Expand Up @@ -567,7 +568,11 @@ private void renderMapShape(
!validationFuncMap.containsKey(memberShape) &&
(!keyValidation.isEmpty() || !valueValidation.isEmpty())
) {
final var funcName = Constants.funcNameGenerator(memberShape, "Validate");
final var funcName = Constants.funcNameGenerator(
memberShape,
"Validate",
context.model()
);
final var funcInput = dataSource.startsWith("input") ? "" : dataSource;
if (!funcInput.isEmpty()) {
final var currServiceShapeNamespace = SmithyNameResolver.shapeNamespace(
Expand Down Expand Up @@ -634,7 +639,11 @@ private void renderUnionShape(
final StringBuilder validationCode,
final String dataSource
) {
final var funcName = Constants.funcNameGenerator(memberShape, "Validate");
final var funcName = Constants.funcNameGenerator(
memberShape,
"Validate",
context.model()
);
final var funcInput = dataSource.startsWith("input") ? "" : dataSource;
var dataSourceForUnion = dataSource;
final var currServiceShapeNamespace =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,11 @@ private void generateSerializerFunctions(
return $L
}
""",
Constants.funcNameGenerator(visitingMemberShape, "ToDafny"),
Constants.funcNameGenerator(
visitingMemberShape,
"ToDafny",
context.model()
),
inputType,
outputType,
SmithyToDafnyShapeVisitor.getConversionFunc(visitingMemberShape)
Expand Down Expand Up @@ -1560,7 +1564,11 @@ private void generateDeserializerFunctions(
func $L(input interface{})($L) {
$L
}""",
Constants.funcNameGenerator(visitingMemberShape, "FromDafny"),
Constants.funcNameGenerator(
visitingMemberShape,
"FromDafny",
context.model()
),
outputType,
DafnyToSmithyShapeVisitor.getConversionFunc(visitingMemberShape)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public static String toNativeShapeVisitorWriter(
}
final String funcName = Constants.funcNameGenerator(
memberShape,
"FromDafny"
"FromDafny",
context.model()
);
return (funcName.concat("(").concat(dataSource).concat(")"));
}
Expand Down Expand Up @@ -145,7 +146,11 @@ public static String toDafnyShapeVisitorWriter(
)
);
}
final String funcName = Constants.funcNameGenerator(memberShape, "ToDafny");
final String funcName = Constants.funcNameGenerator(
memberShape,
"ToDafny",
context.model()
);
return (funcName.concat("(").concat(dataSource).concat(")"));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package software.amazon.polymorph.smithygo.utils;

import software.amazon.polymorph.traits.PositionalTrait;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.utils.StringUtils;

public class Constants {

Expand All @@ -9,7 +13,31 @@ public class Constants {

// TODO: Is it possible to make this function name shorter and in camelCase?
/**
* Generates a function name for shape visitors for AWS SDK and localservice.
* Generates a function name for memberShapes.
* Generates private function for all shape excepts memberShape whose containerShape has positional trait
*
* @param memberShape The visiting MemberShape
* @param suffix A string to be appended at the end of the generated function name
* @param model The smithy model being used
* @return A string representing the generated function name
*/
public static String funcNameGenerator(
final MemberShape memberShape,
final String suffix,
final Model model
) {
String funcName = funcNameGenerator(memberShape, suffix);
final Shape containerShape = model.expectShape(memberShape.getContainer());
// membershape inside a container shape with positional trait has to be exposed.
if (containerShape.hasTrait(PositionalTrait.class)) {
funcName = StringUtils.capitalize(funcName);
}
return funcName;
}

/**
* Generates a function name for memberShapes.
* Always generates private function for all shape
*
* @param memberShape The visiting MemberShape
* @param suffix A string to be appended at the end of the generated function name
Expand Down

0 comments on commit 78b79ae

Please sign in to comment.