Skip to content

Commit 8d84a26

Browse files
timocovmtdowling
authored andcommitted
Added new code sections to support deser overrides
Fixes #1053
1 parent ec4712a commit 8d84a26

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/DeserializerGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import software.amazon.smithy.codegen.core.Symbol;
99
import software.amazon.smithy.codegen.core.SymbolProvider;
1010
import software.amazon.smithy.java.codegen.CodegenUtils;
11+
import software.amazon.smithy.java.codegen.sections.MemberDeserializerSection;
1112
import software.amazon.smithy.java.codegen.writer.JavaWriter;
1213
import software.amazon.smithy.java.core.serde.event.EventStream;
1314
import software.amazon.smithy.model.Model;
@@ -66,7 +67,7 @@ final class DeserializerGenerator extends ShapeVisitor.DataShapeVisitor<Void> im
6667

6768
@Override
6869
public void run() {
69-
writer.pushState();
70+
writer.pushState(new MemberDeserializerSection(shape, schemaName, deserializer));
7071
writer.putContext("schemaName", schemaName);
7172
writer.putContext("deserializer", deserializer);
7273
shape.accept(this);

codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/SerializerMemberGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import software.amazon.smithy.codegen.core.directed.ContextualDirective;
1010
import software.amazon.smithy.java.codegen.CodeGenerationContext;
1111
import software.amazon.smithy.java.codegen.CodegenUtils;
12+
import software.amazon.smithy.java.codegen.sections.MemberSerializerSection;
1213
import software.amazon.smithy.java.codegen.writer.JavaWriter;
1314
import software.amazon.smithy.java.core.schema.Unit;
1415
import software.amazon.smithy.model.Model;
@@ -66,9 +67,10 @@ final class SerializerMemberGenerator extends ShapeVisitor.DataShapeVisitor<Void
6667

6768
@Override
6869
public void run() {
69-
writer.pushState();
70+
var shapeSchemaVariable = "$SCHEMA";
71+
writer.pushState(new MemberSerializerSection(shape, state, shapeSchemaVariable));
7072
writer.putContext("state", state);
71-
writer.putContext("schema", "$SCHEMA");
73+
writer.putContext("schema", shapeSchemaVariable);
7274
shape.accept(this);
7375
writer.popState();
7476
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.java.codegen.sections;
7+
8+
import software.amazon.smithy.model.shapes.Shape;
9+
import software.amazon.smithy.utils.CodeSection;
10+
11+
/**
12+
* Adds a section for member deserializer code.
13+
*
14+
* @param targetedShape A shape that the deserializer code section is created for
15+
* @param shapeSchemaVariable Name of a local variable containing the shape's schema
16+
* @param deserializerVariable Name of a local variable containing the deserializer instance
17+
*/
18+
public record MemberDeserializerSection(Shape targetedShape, String shapeSchemaVariable, String deserializerVariable)
19+
implements CodeSection {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.java.codegen.sections;
7+
8+
import software.amazon.smithy.model.shapes.Shape;
9+
import software.amazon.smithy.utils.CodeSection;
10+
11+
/**
12+
* Adds a section for member serializer code.
13+
*
14+
* @param targetedShape A shape that the serializer code section is created for
15+
* @param stateVariable Name of a local variable containing the state to serialize
16+
* @param shapeSchemaVariable Name of a local variable containing the schema for a given {@code targetedShape}
17+
*/
18+
public record MemberSerializerSection(Shape targetedShape, String stateVariable, String shapeSchemaVariable)
19+
implements CodeSection {}

0 commit comments

Comments
 (0)