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 of SymbolWriter used to generate code.
I - Type of SmithyIntegration to apply.
C - Type of CodegenContext 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 Object
Performs directed code generation of a DirectedCodegen.
  • Constructor Details

    • CodegenDirector

      public CodegenDirector()
  • Method Details

    • 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(Class<I> integrationClass)
      Sets the required class used for SmithyIntegrations.
      Parameters:
      integrationClass - SmithyIntegration class.
    • service

      public void service(ShapeId service)
      Sets the service being generated.

      At least one of service or shapeClosure must be set. Setting only a service generates the closure of shapes connected to that service. Setting both a service and a shape closure enables "combined mode", where the shape closure is the generated set, and the service is the designated primary service (it must be a member of that closure).

      Parameters:
      service - Service to generate.
    • shapeClosure

      public void shapeClosure(String shapeClosure)
      Sets the shape closure being generated by its metadata-defined id.

      At least one of service or shapeClosure must be set. Setting a shape closure generates the shapes in that closure without requiring a service shape to anchor them. A service may also be set to enable combined mode (see service(ShapeId)).

      Parameters:
      shapeClosure - ID of the shape closure to generate.
    • shapeClosure

      public void shapeClosure(ShapeClosure shapeClosure)
      Sets the shape closure being generated from a ShapeClosure object.

      This lets a generator hand the director a closure it computed in code rather than one authored as model metadata. Before resolution, the closure is injected into the model's shapeClosures metadata and then resolved through the same ShapeClosureIndex path as a metadata-authored closure, keyed by the object's id. The id must not collide with a closure already declared in the model.

      Injecting into the model (rather than resolving the object directly) is deliberate: ShapeClosureIndex is a knowledge index that is computed once and cached for the lifetime of the model, so resolving through it reuses that cache instead of recomputing the closure at the index's many call sites, and the closure is validated by ShapeClosureValidator along the same path as a metadata-authored one. The injected metadata must survive integration preprocessModel for resolution to work; injection happens in run() before integrations are applied, and integrations do not drop the shapeClosures metadata.

      Parameters:
      shapeClosure - Shape closure to inject and generate.
    • generateDataShapesOnly

      public void generateDataShapesOnly()
      Generates only data shapes, never invoking the generateService, generateResource, or generateOperation methods of the DirectedCodegen.

      This enables "type codegen", where only the shapes that carry data are generated. Service, resource, and operation shapes are removed from the set of generated shapes even when they are present in the generated closure (for example, when generating the data shapes of a service's closure). The data shapes reachable through removed operations (their inputs, outputs, and errors) are unaffected and are still generated.

    • requireCaseInsensitiveNames

      public void requireCaseInsensitiveNames()
      Requires that the names of the shapes being generated are case-insensitively unique, failing code generation if they are not.

      Unlike service closures, shape closures do not require their shape names to be case-insensitively unique. Code generators that cannot represent such conflicts can call this to enforce uniqueness. The check is performed on the actual shapes being generated after model transforms are applied and with closure renames applied, and it fails regardless of whether the related validation event was suppressed.

      Applying this to service-based generation is a no-op.

    • directedCodegen

      public void directedCodegen(DirectedCodegen<C,S,I> directedCodegen)
      Sets the required DirectedCodegen 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(Class<S> settingsType, Node settingsNode)
      Sets the required settings object used for code generation using a Node.

      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 the integrations 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 the my-integration key will then be provided to an integration with the name my-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.
    • sharedFileManifest

      public void sharedFileManifest(FileManifest sharedFileManifest)
      Sets the FileManifest used to create files in the projection's shared file space.

      All files written by a generator should either be written using this manifest or the generator's isolated manifest (fileManifest).

      Files written to this manifest may be read or modified by other Smithy build plugins. Generators SHOULD NOT write files to this manifest unless they specifically intend for them to be consumed by other plugins. Files that are not intended to be shared should be written to the manifest from fileManifest.

      Parameters:
      sharedFileManifest - FileManifest to use for shared files.
    • integrationFinder

      public void integrationFinder(Supplier<Iterable<I>> integrationFinder)
      Sets a custom implementation for finding SmithyIntegrations.

      Most implementations can use integrationClassLoader(ClassLoader).

      Parameters:
      integrationFinder - Smithy integration finder.
    • integrationClassLoader

      public void integrationClassLoader(ClassLoader classLoader)
      Sets a custom class loader for finding implementations of SmithyIntegration.
      Parameters:
      classLoader - Class loader to find integrations.* @return Returns self.
    • performDefaultCodegenTransforms

      public void performDefaultCodegenTransforms()
    • 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.

      See Also:
    • createDedicatedInputsAndOutputs

      public void createDedicatedInputsAndOutputs(String inputSuffix, 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:
    • removeShapesDeprecatedBeforeDate

      public void removeShapesDeprecatedBeforeDate(String relativeDate)
      Removes any shapes deprecated before the specified date.
      Parameters:
      relativeDate - Relative date, in YYYY-MM-DD format, to use to filter out deprecated shapes.
      See Also:
    • removeShapesDeprecatedBeforeVersion

      public void removeShapesDeprecatedBeforeVersion(String relativeVersion)
      Removes any shapes deprecated before the specified version.
      Parameters:
      relativeVersion - Version, in SemVer format, to use to filter out deprecated shapes.
      See Also:
    • makeIdempotencyTokensClientOptional

      public void makeIdempotencyTokensClientOptional()
      Makes idempotencyToken fields clientOptional.
      See Also:
    • 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:
    • flattenPaginationInfoIntoOperations

      public void flattenPaginationInfoIntoOperations()
      Flattens service-level pagination information into operation pagination traits.
      See Also:
    • 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:
      IllegalStateException - if a required value has not been provided.