Skip to content

Commit

Permalink
Revert "Bring function name generator in a constant utils file"
Browse files Browse the repository at this point in the history
This reverts commit f7340ed.
  • Loading branch information
rishav-karanjit committed Oct 17, 2024
1 parent def5351 commit ba5c82b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.model.traits.UnitTypeTrait;

import static software.amazon.polymorph.smithygo.utils.Constants.funcNameGenerator;

public class DafnyAwsSdkClientTypeConversionProtocol
implements ProtocolGenerator {

Expand Down Expand Up @@ -599,7 +597,7 @@ func Error_ToDafny(err error)($L.Error) {
}
""",
DafnyNameResolver.dafnyTypesNamespace(serviceShape),
writer.consumer(w -> {
writer.consumer(w -> {
for (final var error : errorShapes) {
w.write(
"""
Expand Down Expand Up @@ -808,7 +806,7 @@ private void generateSerializerFunctions(final GenerationContext context, final
return $L
}
""",
funcNameGenerator(
ShapeVisitorHelper.funcNameGenerator(
visitingMemberShape,
"ToDafny"
),
Expand Down Expand Up @@ -858,7 +856,7 @@ private void generateDeserializerFunctions(final GenerationContext context, fina
func $L(input $L)($L) {
return $L
}""",
funcNameGenerator(
ShapeVisitorHelper.funcNameGenerator(
visitingMemberShape,
"FromDafny"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.traits.EnumTrait;

import static software.amazon.polymorph.smithygo.utils.Constants.funcNameGenerator;

public class ShapeVisitorHelper {

private static final Map<MemberShape, Boolean> optionalShapesToDafny =
Expand All @@ -36,17 +34,17 @@ public static boolean isToNativeShapePointable(final MemberShape shape) {
* @param suffix Suffix to add to the function. As of this writing, we only put FromDafny or ToNative suffix.
* @return the function Name
*/
// public static String funcNameGenerator(
// final MemberShape memberShape,
// final String suffix
// ) {
// return memberShape
// .getId()
// .toString()
// .replaceAll("[.$#]", "_")
// .concat("_")
// .concat(suffix);
// }
public static String funcNameGenerator(
final MemberShape memberShape,
final String suffix
) {
return memberShape
.getId()
.toString()
.replaceAll("[.$#]", "_")
.concat("_")
.concat(suffix);
}

public static String toNativeShapeVisitorWriter(
final MemberShape memberShape,
Expand Down Expand Up @@ -137,8 +135,11 @@ public static String toDafnyShapeVisitorWriter(
)
);
}
final String funcName = funcNameGenerator(memberShape, "ToDafny");
nextVisitorFunction = funcName.concat("(").concat(dataSource).concat(")");
final String funcName =
(memberShape.getId().toString().replaceAll("[.$#]", "_")).concat(
"_ToDafny("
);
nextVisitorFunction = funcName.concat(dataSource).concat(")");
return nextVisitorFunction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import software.amazon.smithy.model.traits.UnitTypeTrait;
import software.amazon.polymorph.smithygo.utils.GoCodegenUtils;

import static software.amazon.polymorph.smithygo.utils.Constants.funcNameGenerator;

public class DafnyLocalServiceTypeConversionProtocol
implements ProtocolGenerator {

Expand Down Expand Up @@ -1315,7 +1313,7 @@ private void generateSerializerFunctions(final GenerationContext context, final
return $L
}
""",
funcNameGenerator(
ShapeVisitorHelper.funcNameGenerator(
visitingMemberShape,
"ToDafny"
),
Expand Down Expand Up @@ -1385,7 +1383,7 @@ private void generateDeserializerFunctions(final GenerationContext context, fina
func $L(input interface{})($L) {
$L
}""",
funcNameGenerator(
ShapeVisitorHelper.funcNameGenerator(
visitingMemberShape,
"FromDafny"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.Shape;

import static software.amazon.polymorph.smithygo.utils.Constants.funcNameGenerator;

public class ShapeVisitorHelper {

private static final Map<MemberShape, Boolean> optionalShapesToDafny =
Expand All @@ -21,6 +19,25 @@ public static boolean isToDafnyShapeOptional(final MemberShape shape) {
return optionalShapesToDafny.get(shape);
}

/**
* Generates functions Name for To Dafny and To Native conversion.
*
* @param memberShape MemberShape to generate function name for.
* @param suffix Suffix to add to the function. As of this writing, we only put FromDafny or ToNative suffix.
* @return the function Name
*/
public static String funcNameGenerator(
final MemberShape memberShape,
final String suffix
) {
return memberShape
.getId()
.toString()
.replaceAll("[.$#]", "_")
.concat("_")
.concat(suffix);
}

public static String toNativeShapeVisitorWriter(
final MemberShape memberShape,
final GenerationContext context,
Expand Down Expand Up @@ -129,8 +146,11 @@ public static String toDafnyShapeVisitorWriter(
)
);
}
final String funcName = funcNameGenerator(memberShape, "ToDafny");
nextVisitorFunction = funcName.concat("(").concat(dataSource).concat(")");
final String funcName =
(memberShape.getId().toString().replaceAll("[.$#]", "_")).concat(
"_ToDafny("
);
nextVisitorFunction = funcName.concat(dataSource).concat(")");
return nextVisitorFunction;
}
}

This file was deleted.

0 comments on commit ba5c82b

Please sign in to comment.