Skip to content

Commit 7a91d95

Browse files
committed
Use isStringEnumShape, reorder when conditions
1 parent 8281792 commit 7a91d95

File tree

1 file changed

+9
-9
lines changed
  • codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/serde

1 file changed

+9
-9
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/serde/XmlParserGenerator.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,15 @@ open class XmlParserGenerator(
579579
val parseFn = when {
580580
target.type == ShapeType.BLOB -> writer.format("#T { it.#T() } ", RuntimeTypes.Serde.parse, RuntimeTypes.Core.Text.Encoding.decodeBase64Bytes)
581581
target.type == ShapeType.BOOLEAN -> writer.format("#T()", RuntimeTypes.Serde.parseBoolean)
582-
target.type == ShapeType.STRING && !target.hasTrait<EnumTrait>() -> {
582+
target.isStringEnumShape -> {
583+
if (!textExprIsResult) {
584+
writer.write("#T.fromValue(#L)", ctx.symbolProvider.toSymbol(target), textExpr)
585+
return
586+
} else {
587+
writer.format("#T { #T.fromValue(it) } ", RuntimeTypes.Serde.parse, ctx.symbolProvider.toSymbol(target))
588+
}
589+
}
590+
target.type == ShapeType.STRING -> {
583591
if (!textExprIsResult) {
584592
writer.write(textExpr)
585593
return
@@ -601,14 +609,6 @@ open class XmlParserGenerator(
601609
target.type == ShapeType.DOUBLE -> writer.format("#T()", RuntimeTypes.Serde.parseDouble)
602610
target.type == ShapeType.BIG_DECIMAL -> writer.format("#T()", RuntimeTypes.Serde.parseBigDecimal)
603611
target.type == ShapeType.BIG_INTEGER -> writer.format("#T()", RuntimeTypes.Serde.parseBigInteger)
604-
target.type == ShapeType.ENUM || (target.type == ShapeType.STRING && target.hasTrait<EnumTrait>()) -> {
605-
if (!textExprIsResult) {
606-
writer.write("#T.fromValue(#L)", ctx.symbolProvider.toSymbol(target), textExpr)
607-
return
608-
} else {
609-
writer.format("#T { #T.fromValue(it) } ", RuntimeTypes.Serde.parse, ctx.symbolProvider.toSymbol(target))
610-
}
611-
}
612612
target.type == ShapeType.INT_ENUM -> {
613613
writer.format("#T { #T.fromValue(it.toInt()) } ", RuntimeTypes.Serde.parse, ctx.symbolProvider.toSymbol(target))
614614
}

0 commit comments

Comments
 (0)