Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add intEnum DirectedCodegen #1434

Merged
merged 1 commit into from
Oct 4, 2022
Merged
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 @@ -35,6 +35,7 @@
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.NodeMapper;
import software.amazon.smithy.model.shapes.EnumShape;
import software.amazon.smithy.model.shapes.IntEnumShape;
import software.amazon.smithy.model.shapes.ResourceShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
Expand Down Expand Up @@ -472,5 +473,12 @@ public Void enumShape(EnumShape shape) {
directedCodegen.generateEnumShape(new GenerateEnumDirective<>(context, serviceShape, shape));
return null;
}

@Override
public Void intEnumShape(IntEnumShape shape) {
LOGGER.finest(() -> "Generating intEnum shape" + shape.getId());
directedCodegen.generateIntEnumShape(new GenerateIntEnumDirective<>(context, serviceShape, shape));
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ default void generateResource(GenerateResourceDirective<C, S> directive) {
*/
void generateEnumShape(GenerateEnumDirective<C, S> directive);

/**
* Generates the code needed for an intEnum shape.
*
* @param directive Directive to perform.
*/
void generateIntEnumShape(GenerateIntEnumDirective<C, S> directive);

/**
* Performs any necessary code generation after all shapes are generated,
* using the created codegen context object before integrations perform
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.codegen.core.directed;

import software.amazon.smithy.codegen.core.CodegenContext;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;

/**
* Directive used to generate an intEnum.
*
* @param <C> CodegenContext type.
* @param <S> Codegen settings type.
* @see DirectedCodegen#generateIntEnumShape
*/
public final class GenerateIntEnumDirective<C extends CodegenContext<S, ?, ?>, S> extends ShapeDirective<Shape, C, S> {

GenerateIntEnumDirective(C context, ServiceShape service, Shape shape) {
super(context, service, shape);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public void generateEnumShape(GenerateEnumDirective<TestContext, TestSettings> d
}
}

@Override
public void generateIntEnumShape(GenerateIntEnumDirective<TestContext, TestSettings> directive) {
generatedShapes.add(directive.shape().getId());
}

@Override
public void customizeBeforeIntegrations(CustomizeDirective<TestContext, TestSettings> directive) {}

Expand Down Expand Up @@ -169,6 +174,7 @@ public void performsCodegen() {
ShapeId.from("smithy.example#ListFooInput"),
ShapeId.from("smithy.example#ListFooOutput"),
ShapeId.from("smithy.example#Status"),
ShapeId.from("smithy.example#FaceCard"),
ShapeId.from("smithy.example#Instruction"),
ShapeId.from("smithy.api#Unit")
));
Expand Down Expand Up @@ -209,6 +215,7 @@ public void performsCodegenWithStringEnumsChangedToEnumShapes() {
ShapeId.from("smithy.example#ListFooInput"),
ShapeId.from("smithy.example#ListFooOutput"),
ShapeId.from("smithy.example#Status"),
ShapeId.from("smithy.example#FaceCard"),
ShapeId.from("smithy.example#Instruction"),
ShapeId.from("smithy.api#Unit")
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ operation ListFoo {
status: Status
items: StringList
instruction: Instruction
facecard: FaceCard
}
}

Expand All @@ -36,6 +37,12 @@ list StringList {
])
string Status

intEnum FaceCard {
JACK = 1
QUEEN = 2
KING = 3
}

union Instruction {
continueIteration: Unit,
stopIteration: Unit
Expand Down