Skip to content

Commit ed2bba0

Browse files
fix(go): use shape from the symbol properties in getType utils function (#764)
1 parent 1374493 commit ed2bba0

File tree

5 files changed

+10
-19
lines changed

5 files changed

+10
-19
lines changed

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/codegen/SymbolUtils.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public final class SymbolUtils {
2929
public static final String GO_SLICE = "goSlice";
3030
public static final String GO_MAP = "goMap";
3131
public static final String GO_ELEMENT_TYPE = "goElementType";
32+
public static final String SHAPE = "shape";
3233

3334
// Used when a given shape must be represented differently on input.
3435
public static final String INPUT_VARIANT = "inputVariant";
@@ -66,7 +67,7 @@ public static Symbol.Builder createValueSymbolBuilder(
6667
Shape shape,
6768
String typeName
6869
) {
69-
return createValueSymbolBuilder(typeName).putProperty("shape", shape);
70+
return createValueSymbolBuilder(typeName).putProperty(SHAPE, shape);
7071
}
7172

7273
/**
@@ -80,7 +81,7 @@ public static Symbol.Builder createPointableSymbolBuilder(
8081
Shape shape,
8182
String typeName
8283
) {
83-
return createPointableSymbolBuilder(typeName).putProperty("shape", shape);
84+
return createPointableSymbolBuilder(typeName).putProperty(SHAPE, shape);
8485
}
8586

8687
/**

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/codegen/ValidationGenerator.java

-3
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ private void renderListShape(
514514
);
515515
final var inputType = GoCodegenUtils.getType(
516516
symbolProvider.toSymbol(currentShape),
517-
currentShape,
518517
isExternalShape
519518
);
520519
if (isExternalShape) {
@@ -611,7 +610,6 @@ private void renderMapShape(
611610
);
612611
final var inputType = GoCodegenUtils.getType(
613612
symbolProvider.toSymbol(currentShape),
614-
currentShape,
615613
isExternalShape
616614
);
617615
if (isExternalShape) {
@@ -684,7 +682,6 @@ private void renderUnionShape(
684682
!currShapeNamespace.startsWith("smithy");
685683
final var inputType = GoCodegenUtils.getType(
686684
symbolProvider.toSymbol(currentShape),
687-
currentShape,
688685
isExternalShape
689686
);
690687
if (isExternalShape) {

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/DafnyLocalServiceTypeConversionProtocol.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ public void generateOrphanShapeSerializer(
484484
inputType =
485485
GoCodegenUtils.getType(
486486
context.symbolProvider().toSymbol(resourceOrService),
487-
resourceOrService,
488487
true
489488
);
490489
} else {
@@ -497,7 +496,7 @@ public void generateOrphanShapeSerializer(
497496
.concat(context.symbolProvider().toSymbol(serviceShape).getName());
498497
}
499498
} else {
500-
inputType = GoCodegenUtils.getType(curSymbol, shape, true);
499+
inputType = GoCodegenUtils.getType(curSymbol, true);
501500
outputType = DafnyNameResolver.getDafnyType(shape, curSymbol);
502501
}
503502
writerDelegator.useFileWriter(
@@ -992,11 +991,7 @@ public void generateOrphanShapeDeserializer(
992991
}
993992
} else {
994993
outputType =
995-
GoCodegenUtils.getType(
996-
context.symbolProvider().toSymbol(shape),
997-
shape,
998-
true
999-
);
994+
GoCodegenUtils.getType(context.symbolProvider().toSymbol(shape), true);
1000995
}
1001996
writerDelegator.useFileWriter(
1002997
"%s/%s".formatted(
@@ -1858,7 +1853,6 @@ private void generateSerializerFunctions(
18581853
inputType =
18591854
GoCodegenUtils.getType(
18601855
context.symbolProvider().toSymbol(visitingShape),
1861-
visitingShape,
18621856
true
18631857
);
18641858
Boolean isPointable = context
@@ -1891,7 +1885,6 @@ private void generateSerializerFunctions(
18911885
inputType =
18921886
GoCodegenUtils.getType(
18931887
context.symbolProvider().toSymbol(resourceOrService),
1894-
resourceOrService,
18951888
true
18961889
);
18971890
} else {
@@ -1962,7 +1955,6 @@ private void generateDeserializerFunctions(
19621955
alreadyVisited.add(visitingMemberShape.toShapeId());
19631956
var outputType = GoCodegenUtils.getType(
19641957
context.symbolProvider().toSymbol(visitingShape),
1965-
visitingShape,
19661958
true
19671959
);
19681960
Boolean isPointable = context

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/shapevisitor/DafnyToSmithyShapeVisitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public String listShape(final ListShape shape) {
459459
}
460460
fieldValue = append(fieldValue, %s)}
461461
""".formatted(
462-
GoCodegenUtils.getType(symbol, shape, true),
462+
GoCodegenUtils.getType(symbol, true),
463463
dataSource,
464464
ShapeVisitorHelper.toNativeShapeVisitorWriter(
465465
memberShape,

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/utils/GoCodegenUtils.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ public static String getType(
5454

5555
public static String getType(
5656
final Symbol symbol,
57-
final Shape shape,
5857
final Boolean includeNamespace
5958
) {
6059
if (
6160
symbol.getProperty(SymbolUtils.GO_ELEMENT_TYPE, Symbol.class).isEmpty()
6261
) {
6362
return includeNamespace
64-
? SmithyNameResolver.getSmithyType(shape, symbol)
63+
? SmithyNameResolver.getSmithyType(
64+
symbol.expectProperty(SymbolUtils.SHAPE, Shape.class),
65+
symbol
66+
)
6567
: symbol.getName();
6668
}
6769
var type = getType(
6870
symbol.expectProperty(SymbolUtils.GO_ELEMENT_TYPE, Symbol.class),
69-
shape,
7071
includeNamespace
7172
);
7273
if (symbol.getProperty(SymbolUtils.GO_MAP).isPresent()) {

0 commit comments

Comments
 (0)