S
- The settings object used to configure the generator.W
- The type of AbstractCodeWriter used by the generator.C
- The CodegenContext value used by the generator.public interface SmithyIntegration<S,W extends SymbolWriter<W,?>,C extends CodegenContext<S,W>>
This class provides the bare minimum that most Smithy code generators can implement as a tool to customize generators. Code generators are expected to extend this interface to add various hooks to their generator (e.g., register protocol generators, register auth scheme integrations, attach middleware, intercept and augment CodeWriter sections, etc).
This interface is currently unstable as more requirements may be added in the future.
Modifier and Type | Method and Description |
---|---|
default void |
customize(C codegenContext)
Allows generators to write additional files, perform additional tasks, and
interact directly with a
FileManifest used to write files to the plugin's
output. |
default SymbolProvider |
decorateSymbolProvider(Model model,
S settings,
SymbolProvider symbolProvider)
Updates the
SymbolProvider used when generating code. |
default java.util.List<? extends CodeInterceptor<? extends CodeSection,W>> |
interceptors(C codegenContext)
Gets a list of
CodeInterceptor s to register with the AbstractCodeWriter s
created by the code generator. |
default java.lang.String |
name()
Gets the name of the integration.
|
default Model |
preprocessModel(Model model,
S settings)
Preprocess the model before code generation.
|
default byte |
priority()
Gets the priority ordering relative to the topologically ordered integration graph
determined by
runBefore() and runAfter() . |
default java.util.List<java.lang.String> |
runAfter()
Gets the name of the integrations that this integration must come after.
|
default java.util.List<java.lang.String> |
runBefore()
Gets the names of integrations that this integration must come before.
|
static <I extends SmithyIntegration<?,?,?>> |
sort(java.lang.Iterable<I> integrations)
Topologically sorts a list of integrations based on priority,
runBefore, and runAfter, and integration names.
|
default java.lang.String name()
This name is referred to when ordering the graph of integrations. The name defaults to the canonical class name if not overridden.
default byte priority()
runBefore()
and runAfter()
.
Higher numbers come before lower numbers.
When ordering, implementations must not allow cycles, and no two integrations may have the same name.
default java.util.List<java.lang.String> runBefore()
Dependencies are soft. Dependencies on integration names that cannot be found log a warning and are ignored.
default java.util.List<java.lang.String> runAfter()
Dependencies are soft. Dependencies on integration names that cannot be found log a warning and are ignored.
default Model preprocessModel(Model model, S settings)
This can be used to remove unsupported features, remove traits from shapes (e.g., make members optional), etc.
By default, this method will return the given model
as-is.
model
- Model being generated.settings
- Setting used to generate code.default SymbolProvider decorateSymbolProvider(Model model, S settings, SymbolProvider symbolProvider)
SymbolProvider
used when generating code.
This can be used to customize the names of shapes, the package that code is generated into, add dependencies, add imports, etc.
By default, this method will return the given symbolProvider
as-is.
This integration method should be called only after preprocessModel(software.amazon.smithy.model.Model, S)
.
model
- Model being generated.settings
- Setting used to generate.symbolProvider
- The original SymbolProvider
.SymbolProvider
.default java.util.List<? extends CodeInterceptor<? extends CodeSection,W>> interceptors(C codegenContext)
CodeInterceptor
s to register with the AbstractCodeWriter
s
created by the code generator.
This integration method should be called only after preprocessModel(software.amazon.smithy.model.Model, S)
and decorateSymbolProvider(software.amazon.smithy.model.Model, S, software.amazon.smithy.codegen.core.SymbolProvider)
.
codegenContext
- Code generation context that can be queried when creating interceptors.CodeInterceptor
s.default void customize(C codegenContext)
FileManifest
used to write files to the plugin's
output.
This method should generally be invoked at the end of the code generation process.
codegenContext
- Code generation context that can be queried when writing additional files.static <I extends SmithyIntegration<?,?,?>> java.util.List<I> sort(java.lang.Iterable<I> integrations)
I
- The type of integration to sort.integrations
- Integrations to sort.java.lang.IllegalArgumentException
- If a cycle is found between integrations.java.lang.IllegalArgumentException
- If multiple integrations share the same name.