Skip to content

Commit

Permalink
Update intEnum generation to use type alias
Browse files Browse the repository at this point in the history
Due to type definitions requiring strict casting and implementation
overhead in protocol generation, this commit uses type aliases to
generate intEnums as an intermediate step until migrating back to
type definitions.

This change is backwards compatible except for the removed `Values()`
method that was on intEnum type definitions, but not definable on type
aliases since defining methods on base types (`int32`) is not permitted.
  • Loading branch information
syall committed Nov 16, 2022
1 parent d88db0e commit a41ec93
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
Expand Up @@ -419,6 +419,7 @@ public static boolean isNumber(Shape shape) {
case BYTE:
case SHORT:
case INTEGER:
case INT_ENUM:
case LONG:
case FLOAT:
case DOUBLE:
Expand Down
Expand Up @@ -48,7 +48,9 @@ final class IntEnumGenerator implements Runnable {
public void run() {
Symbol symbol = symbolProvider.toSymbol(shape);

writer.write("type $L int32", symbol.getName()).write("");
// TODO(smithy): Use type alias instead of type definition until refactoring
// protocol generators is prioritized.
writer.write("type $L = int32", symbol.getName()).write("");

writer.writeDocs(String.format("Enum values for %s", symbol.getName()));
Set<String> constants = new LinkedHashSet<>();
Expand Down Expand Up @@ -84,6 +86,9 @@ public void run() {
}
}).write("");

// TODO(smithy): type aliases don't allow defining methods on base types (e.g. int32).
// Uncomment generating the Value() method when the type alias is migrated to type definition.
/*
writer.writeDocs(String.format("Values returns all known values for %s. Note that this can be expanded in the "
+ "future, and so it is only as up to date as the client.%n%nThe ordering of this slice is not "
+ "guaranteed to be stable across updates.", symbol.getName()));
Expand All @@ -94,5 +99,6 @@ public void run() {
}
});
});
*/
}
}
Expand Up @@ -304,6 +304,7 @@ protected void writeScalarPointerInline(GoWriter writer, MemberShape member, Nod
funcName = "Int16";
break;
case INTEGER:
case INT_ENUM:
funcName = "Int32";
break;
case LONG:
Expand Down Expand Up @@ -669,6 +670,7 @@ public Void numberNode(NumberNode node) {
case BYTE:
case SHORT:
case INTEGER:
case INT_ENUM:
case LONG:
case FLOAT:
case DOUBLE:
Expand Down
Expand Up @@ -767,6 +767,7 @@ private void writeHttpBindingSetter(
locationEncoder.accept(writer, "Short(" + operand + ")");
break;
case INTEGER:
case INT_ENUM:
locationEncoder.accept(writer, "Integer(" + operand + ")");
break;
case LONG:
Expand Down Expand Up @@ -1211,6 +1212,7 @@ private String generateHttpHeaderValue(
writer.write("if err != nil { return err }");
return "int16(vv)";
case INTEGER:
case INT_ENUM:
writer.addUseImports(SmithyGoDependency.STRCONV);
writer.write("vv, err := strconv.ParseInt($L, 0, 32)", operand);
writer.write("if err != nil { return err }");
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a41ec93

Please sign in to comment.