Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.java.codegen.CodegenUtils;
import software.amazon.smithy.java.codegen.sections.MemberDeserializerSection;
import software.amazon.smithy.java.codegen.writer.JavaWriter;
import software.amazon.smithy.java.core.serde.event.EventStream;
import software.amazon.smithy.model.Model;
Expand Down Expand Up @@ -66,7 +67,7 @@ final class DeserializerGenerator extends ShapeVisitor.DataShapeVisitor<Void> im

@Override
public void run() {
writer.pushState();
writer.pushState(new MemberDeserializerSection(shape, schemaName, deserializer));
writer.putContext("schemaName", schemaName);
writer.putContext("deserializer", deserializer);
shape.accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import software.amazon.smithy.codegen.core.directed.ContextualDirective;
import software.amazon.smithy.java.codegen.CodeGenerationContext;
import software.amazon.smithy.java.codegen.CodegenUtils;
import software.amazon.smithy.java.codegen.sections.MemberSerializerSection;
import software.amazon.smithy.java.codegen.writer.JavaWriter;
import software.amazon.smithy.java.core.schema.Unit;
import software.amazon.smithy.model.Model;
Expand Down Expand Up @@ -66,9 +67,10 @@ final class SerializerMemberGenerator extends ShapeVisitor.DataShapeVisitor<Void

@Override
public void run() {
writer.pushState();
var shapeSchemaVariable = "$SCHEMA";
writer.pushState(new MemberSerializerSection(shape, state, shapeSchemaVariable));
writer.putContext("state", state);
writer.putContext("schema", "$SCHEMA");
writer.putContext("schema", shapeSchemaVariable);
shape.accept(this);
writer.popState();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.java.codegen.sections;

import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.utils.CodeSection;

/**
* Adds a section for member deserializer code.
*
* @param targetedShape A shape that the deserializer code section is created for
* @param shapeSchemaVariable Name of a local variable containing the shape's schema
* @param deserializerVariable Name of a local variable containing the deserializer instance
*/
public record MemberDeserializerSection(Shape targetedShape, String shapeSchemaVariable, String deserializerVariable)
implements CodeSection {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.java.codegen.sections;

import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.utils.CodeSection;

/**
* Adds a section for member serializer code.
*
* @param targetedShape A shape that the serializer code section is created for
* @param stateVariable Name of a local variable containing the state to serialize
* @param shapeSchemaVariable Name of a local variable containing the schema for a given {@code targetedShape}
*/
public record MemberSerializerSection(Shape targetedShape, String stateVariable, String shapeSchemaVariable)
implements CodeSection {}