Skip to content

Commit 1f943c6

Browse files
committed
Add intEnum DirectedCodegen
1 parent a78799f commit 1f943c6

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CodegenDirector.java

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import software.amazon.smithy.model.node.Node;
3636
import software.amazon.smithy.model.node.NodeMapper;
3737
import software.amazon.smithy.model.shapes.EnumShape;
38+
import software.amazon.smithy.model.shapes.IntEnumShape;
3839
import software.amazon.smithy.model.shapes.ResourceShape;
3940
import software.amazon.smithy.model.shapes.ServiceShape;
4041
import software.amazon.smithy.model.shapes.Shape;
@@ -472,5 +473,12 @@ public Void enumShape(EnumShape shape) {
472473
directedCodegen.generateEnumShape(new GenerateEnumDirective<>(context, serviceShape, shape));
473474
return null;
474475
}
476+
477+
@Override
478+
public Void intEnumShape(IntEnumShape shape) {
479+
LOGGER.finest(() -> "Generating intEnum shape" + shape.getId());
480+
directedCodegen.generateIntEnumShape(new GenerateIntEnumDirective<>(context, serviceShape, shape));
481+
return null;
482+
}
475483
}
476484
}

smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/DirectedCodegen.java

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ default void generateResource(GenerateResourceDirective<C, S> directive) {
9999
*/
100100
void generateEnumShape(GenerateEnumDirective<C, S> directive);
101101

102+
/**
103+
* Generates the code needed for an intEnum shape.
104+
*
105+
* @param directive Directive to perform.
106+
*/
107+
void generateIntEnumShape(GenerateIntEnumDirective<C, S> directive);
108+
102109
/**
103110
* Performs any necessary code generation after all shapes are generated,
104111
* using the created codegen context object before integrations perform
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.smithy.codegen.core.directed;
17+
18+
import software.amazon.smithy.codegen.core.CodegenContext;
19+
import software.amazon.smithy.model.shapes.ServiceShape;
20+
import software.amazon.smithy.model.shapes.Shape;
21+
22+
/**
23+
* Directive used to generate an intEnum.
24+
*
25+
* @param <C> CodegenContext type.
26+
* @param <S> Codegen settings type.
27+
* @see DirectedCodegen#generateIntEnumShape
28+
*/
29+
public final class GenerateIntEnumDirective<C extends CodegenContext<S, ?, ?>, S> extends ShapeDirective<Shape, C, S> {
30+
31+
GenerateIntEnumDirective(C context, ServiceShape service, Shape shape) {
32+
super(context, service, shape);
33+
}
34+
}

smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CodegenDirectorTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public void generateEnumShape(GenerateEnumDirective<TestContext, TestSettings> d
101101
}
102102
}
103103

104+
@Override
105+
public void generateIntEnumShape(GenerateIntEnumDirective<TestContext, TestSettings> directive) {
106+
generatedShapes.add(directive.shape().getId());
107+
}
108+
104109
@Override
105110
public void customizeBeforeIntegrations(CustomizeDirective<TestContext, TestSettings> directive) {}
106111

@@ -169,6 +174,7 @@ public void performsCodegen() {
169174
ShapeId.from("smithy.example#ListFooInput"),
170175
ShapeId.from("smithy.example#ListFooOutput"),
171176
ShapeId.from("smithy.example#Status"),
177+
ShapeId.from("smithy.example#FaceCard"),
172178
ShapeId.from("smithy.example#Instruction"),
173179
ShapeId.from("smithy.api#Unit")
174180
));
@@ -209,6 +215,7 @@ public void performsCodegenWithStringEnumsChangedToEnumShapes() {
209215
ShapeId.from("smithy.example#ListFooInput"),
210216
ShapeId.from("smithy.example#ListFooOutput"),
211217
ShapeId.from("smithy.example#Status"),
218+
ShapeId.from("smithy.example#FaceCard"),
212219
ShapeId.from("smithy.example#Instruction"),
213220
ShapeId.from("smithy.api#Unit")
214221
));

smithy-codegen-core/src/test/resources/software/amazon/smithy/codegen/core/directed/directed-model.smithy

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ operation ListFoo {
2323
status: Status
2424
items: StringList
2525
instruction: Instruction
26+
facecard: FaceCard
2627
}
2728
}
2829

@@ -36,6 +37,12 @@ list StringList {
3637
])
3738
string Status
3839

40+
intEnum FaceCard {
41+
JACK = 1
42+
QUEEN = 2
43+
KING = 3
44+
}
45+
3946
union Instruction {
4047
continueIteration: Unit,
4148
stopIteration: Unit

0 commit comments

Comments
 (0)