Class CodegenDirector<W extends SymbolWriter<W,? extends ImportContainer>,I extends SmithyIntegration<S,W,C>,C extends CodegenContext<S,W,I>,S>
- java.lang.Object
-
- software.amazon.smithy.codegen.core.directed.CodegenDirector<W,I,C,S>
-
- Type Parameters:
W
- Type ofSymbolWriter
used to generate code.I
- Type ofSmithyIntegration
to apply.C
- Type ofCodegenContext
to create and use.S
- Type of settings object to pass to directed methods.
public final class CodegenDirector<W extends SymbolWriter<W,? extends ImportContainer>,I extends SmithyIntegration<S,W,C>,C extends CodegenContext<S,W,I>,S> extends java.lang.Object
Performs directed code generation of aDirectedCodegen
.
-
-
Constructor Summary
Constructors Constructor Description CodegenDirector()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeStringEnumsToEnumShapes(boolean synthesizeEnumNames)
Changes each compatible string shape with the enum trait to an enum shape.void
createDedicatedInputsAndOutputs()
Generates dedicated input and output shapes for every operation if the operation doesn't already have them.void
createDedicatedInputsAndOutputs(java.lang.String inputSuffix, java.lang.String outputSuffix)
Generates dedicated input and output shapes for every operation if the operation doesn't already have them.void
directedCodegen(DirectedCodegen<C,S,I> directedCodegen)
Sets the requiredDirectedCodegen
implementation to invoke.void
fileManifest(FileManifest fileManifest)
Sets the required file manifest used to write files to disk.void
integrationClass(java.lang.Class<I> integrationClass)
Sets the required class used for SmithyIntegrations.void
integrationClassLoader(java.lang.ClassLoader classLoader)
Sets a custom class loader for finding implementations ofSmithyIntegration
.void
integrationFinder(java.util.function.Supplier<java.lang.Iterable<I>> integrationFinder)
Sets a custom implementation for findingSmithyIntegration
s.void
integrationSettings(ObjectNode integrationSettings)
Sets the settings node to be passed to integrations.void
model(Model model)
Sets the required model to generate from.void
performDefaultCodegenTransforms()
Set to true to applysimplifyModelForServiceCodegen(software.amazon.smithy.model.Model, software.amazon.smithy.model.shapes.ShapeId, software.amazon.smithy.model.transform.ModelTransformer)
prior to code generation.void
run()
Finalizes the Runner and performs directed code generation.void
service(ShapeId service)
Sets the required service being generated.S
settings(java.lang.Class<S> settingsType, Node settingsNode)
Sets the required settings object used for code generation using aNode
.void
settings(S settings)
Sets the required settings object used for code generation.void
shapeGenerationOrder(ShapeGenerationOrder order)
Sets the shapes order for code generation.static Model
simplifyModelForServiceCodegen(Model model, ShapeId service, ModelTransformer transformer)
Simplifies a Smithy model for code generation of a single service.void
sortMembers()
Sorts all members of the model prior to codegen.
-
-
-
Method Detail
-
simplifyModelForServiceCodegen
public static Model simplifyModelForServiceCodegen(Model model, ShapeId service, ModelTransformer transformer)
Simplifies a Smithy model for code generation of a single service.- Flattens error hierarchies onto every operation.
- Flattens mixins
Note: This transform is applied automatically by a code generator if
performDefaultCodegenTransforms()
is set to true.- Parameters:
model
- Model being code generated.service
- Service being generated.transformer
- Model transformer to use.- Returns:
- Returns the updated model.
-
integrationClass
public void integrationClass(java.lang.Class<I> integrationClass)
Sets the required class used for SmithyIntegrations.- Parameters:
integrationClass
- SmithyIntegration class.
-
service
public void service(ShapeId service)
Sets the required service being generated.- Parameters:
service
- Service to generate.
-
directedCodegen
public void directedCodegen(DirectedCodegen<C,S,I> directedCodegen)
Sets the requiredDirectedCodegen
implementation to invoke.- Parameters:
directedCodegen
- Directed code generator to run.
-
model
public void model(Model model)
Sets the required model to generate from.- Parameters:
model
- Model to generate from.
-
settings
public void settings(S settings)
Sets the required settings object used for code generation.integrationSettings
MUST also be set.- Parameters:
settings
- Settings object.
-
settings
public S settings(java.lang.Class<S> settingsType, Node settingsNode)
Sets the required settings object used for code generation using aNode
.A Node value is used by Smithy-Build plugins to configure settings. This method is a helper method that uses Smithy's fairly simple object-mapper to deserialize a node into the desired settings type. You will need to manually deserialize your settings if using types that are not supported by Smithy's
NodeMapper
.This will also set
integrationSettings
if theintegrations
key is present.- Parameters:
settingsType
- Settings type to deserialize into.settingsNode
- Settings node value to deserialize.- Returns:
- Returns the deserialized settings as this is needed to provide a service shape ID.
-
integrationSettings
public void integrationSettings(ObjectNode integrationSettings)
Sets the settings node to be passed to integrations.Generators MUST set this with the
integrations
key from their plugin settings.{ "version": "1.0", "projections": { "codegen-projection": { "plugins": { "code-generator": { "service": "com.example#DocumentedService", "integrations": { "my-integration": { "example-setting": "foo" } } } } } } }
In this example, the value of the
integrations
key is what must be passed to this method. The value of themy-integration
key will then be provided to an integration with the namemy-integration
.- Parameters:
integrationSettings
- Settings used to configure integrations.
-
fileManifest
public void fileManifest(FileManifest fileManifest)
Sets the required file manifest used to write files to disk.- Parameters:
fileManifest
- File manifest to write files.
-
integrationFinder
public void integrationFinder(java.util.function.Supplier<java.lang.Iterable<I>> integrationFinder)
Sets a custom implementation for findingSmithyIntegration
s.Most implementations can use
integrationClassLoader(ClassLoader)
.- Parameters:
integrationFinder
- Smithy integration finder.
-
integrationClassLoader
public void integrationClassLoader(java.lang.ClassLoader classLoader)
Sets a custom class loader for finding implementations ofSmithyIntegration
.- Parameters:
classLoader
- Class loader to find integrations.* @return Returns self.
-
performDefaultCodegenTransforms
public void performDefaultCodegenTransforms()
Set to true to applysimplifyModelForServiceCodegen(software.amazon.smithy.model.Model, software.amazon.smithy.model.shapes.ShapeId, software.amazon.smithy.model.transform.ModelTransformer)
prior to code generation.
-
createDedicatedInputsAndOutputs
public void createDedicatedInputsAndOutputs()
Generates dedicated input and output shapes for every operation if the operation doesn't already have them.This method uses "Input" as the default suffix for input, and "Output" as the default suffix for output shapes. Use
createDedicatedInputsAndOutputs(String, String)
to use custom suffixes.
-
createDedicatedInputsAndOutputs
public void createDedicatedInputsAndOutputs(java.lang.String inputSuffix, java.lang.String outputSuffix)
Generates dedicated input and output shapes for every operation if the operation doesn't already have them.- Parameters:
inputSuffix
- Suffix to use for input shapes (e.g., "Input").outputSuffix
- Suffix to use for output shapes (e.g., "Output").- See Also:
ModelTransformer.createDedicatedInputAndOutput(Model, String, String)
-
changeStringEnumsToEnumShapes
public void changeStringEnumsToEnumShapes(boolean synthesizeEnumNames)
Changes each compatible string shape with the enum trait to an enum shape.- Parameters:
synthesizeEnumNames
- Whether enums without names should have names synthesized if possible.- See Also:
ModelTransformer.changeStringEnumsToEnumShapes(Model, boolean)
-
shapeGenerationOrder
public void shapeGenerationOrder(ShapeGenerationOrder order)
Sets the shapes order for code generation.CodegenDirector order the shapes appropriately before passing them to the code generators. The default order is topological, and can be overridden with this method
- Parameters:
order
- the order to use for the shape generation process.
-
sortMembers
public void sortMembers()
Sorts all members of the model prior to codegen.This should only be used by languages where changing the order of members in a structure or union is a backward compatible change (i.e., not C, C++, Rust, etc). Once this is performed, there's no need to ever explicitly sort members throughout the rest of code generation.
-
run
public void run()
Finalizes the Runner and performs directed code generation.- Throws:
java.lang.IllegalStateException
- if a required value has not been provided.
-
-