Class CodegenWriterDelegator<T extends CodegenWriter<T,?>>
- java.lang.Object
-
- software.amazon.smithy.codegen.core.writer.CodegenWriterDelegator<T>
-
- Type Parameters:
T- The type ofCodegenWriterto create and manage.
@Deprecated public class CodegenWriterDelegator<T extends CodegenWriter<T,?>> extends java.lang.ObjectDeprecated.preferWriterDelegator. This class will be removed in a future release.Creates and manages
CodegenWriters for files and namespaces based onSymbols created for aShape.Overview
CodegenWriterDelegatoris designed to generate code in files returned by theSymbol.getDefinitionFile()method of aSymbol. If multipleSymbols are created that need to be defined in the same file, then theCodegenWriterDelegatorensures that the state of code generator associated with the file is persisted and only written when all shapes have been generated.CodegenWriters are lazily created each time a new filename is requested. If aCodegenWriteris already associated with a filename, a newline (\n) is written to the file before providing access to theCodegenWriter. All of the files and CodegenWriters stored in the delegator are eventually written to the providedFileManifestwhen theflushWriters()method is called.This class is not thread-safe.
Extending
CodegenWriterDelegatorLanguage-specific code generators that utilize
SymbolandSymbolDependencyshould extend bothCodegenWriterDelegatorandCodegenWriterto implement language specific functionality. Extending these classes also makes it easier to create new instances of them because they will be easier to work with since generic types aren't needed in concrete implementations.
-
-
Constructor Summary
Constructors Constructor Description CodegenWriterDelegator(FileManifest fileManifest, SymbolProvider symbolProvider, CodegenWriterFactory<T> codegenWriterFactory)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidflushWriters()Deprecated.Writes each pendingCodegenWriterto theFileManifest.java.util.List<SymbolDependency>getDependencies()Deprecated.Gets all of the dependencies that have been registered in writers created by theCodegenWriterDelegator.java.util.Map<java.lang.String,T>getWriters()Deprecated.Returns an immutableMapof createdCodegenWriters.voidsetAutomaticSeparator(java.lang.String automaticSeparator)Deprecated.Sets the automatic separator that is written to aCodegenWritereach time the writer is reused.voiduseFileWriter(java.lang.String filename, java.lang.String namespace, java.util.function.Consumer<T> writerConsumer)Deprecated.Gets a previously created writer or creates a new one if needed.voiduseFileWriter(java.lang.String filename, java.util.function.Consumer<T> writerConsumer)Deprecated.Gets a previously createdCodegenWriteror creates a new one if needed.voiduseShapeWriter(Shape shape, java.util.function.Consumer<T> writerConsumer)Deprecated.
-
-
-
Constructor Detail
-
CodegenWriterDelegator
public CodegenWriterDelegator(FileManifest fileManifest, SymbolProvider symbolProvider, CodegenWriterFactory<T> codegenWriterFactory)
Deprecated.- Parameters:
fileManifest- Where code is written whenflushWriters()is called.symbolProvider- MapsShapetoSymbolto determine the "namespace" and file of a shape.codegenWriterFactory- Factory used to create newCodegenWriters.
-
-
Method Detail
-
getDependencies
public java.util.List<SymbolDependency> getDependencies()
Deprecated.Gets all of the dependencies that have been registered in writers created by theCodegenWriterDelegator.This method essentially just aggregates the results of calling
CodegenWriter.getDependencies()of each created writer into a single array.This method may be overridden as needed (for example, to add in some list of default dependencies or to inject other generative dependencies).
- Returns:
- Returns all the dependencies used in each
CodegenWriter.
-
flushWriters
public void flushWriters()
Deprecated.Writes each pendingCodegenWriterto theFileManifest.The
toStringmethod is called on each writer to generate the code to write to the manifest.This method clears out the managed
CodegenWriters, meaning a subsequent call togetWriters()will return an empty map.This method may be overridden as needed.
-
getWriters
public final java.util.Map<java.lang.String,T> getWriters()
Deprecated.Returns an immutableMapof createdCodegenWriters.Each map key is the relative filename where the code will be written in the
FileManifest, and each map value is the associatedCodegenWriterof typeT.- Returns:
- Returns the immutable map of files to writers.
-
useFileWriter
public final void useFileWriter(java.lang.String filename, java.util.function.Consumer<T> writerConsumer)Deprecated.Gets a previously createdCodegenWriteror creates a new one if needed.If a writer already exists, a newline is automatically appended to the writer (either a newline or whatever value was set on
setAutomaticSeparator(java.lang.String)).- Parameters:
filename- Name of the file to create.writerConsumer- Consumer that is expected to write to theCodegenWriter.
-
useFileWriter
public final void useFileWriter(java.lang.String filename, java.lang.String namespace, java.util.function.Consumer<T> writerConsumer)Deprecated.Gets a previously created writer or creates a new one if needed.If a writer already exists, a newline is automatically appended to the writer (either a newline or whatever value was set on
setAutomaticSeparator(java.lang.String)).- Parameters:
filename- Name of the file to create.namespace- Namespace associated with the file (or an empty string).writerConsumer- Consumer that is expected to write to theCodegenWriter.
-
useShapeWriter
public final void useShapeWriter(Shape shape, java.util.function.Consumer<T> writerConsumer)
Deprecated.Gets or creates a writer for aShapeby converting theShapeto aSymbol.Any dependencies (i.e.,
SymbolDependency) required by theSymbolare automatically registered with the writer.Any imports required to declare the
Symbolin code (i.e.,SymbolReference.ContextOption.DECLARE) are automatically registered with the writer.If a writer already exists, a newline is automatically appended to the writer (either a newline or whatever value was set on
setAutomaticSeparator(java.lang.String)).- Parameters:
shape- Shape to create the writer for.writerConsumer- Consumer that is expected to write to theCodegenWriter.
-
setAutomaticSeparator
public final void setAutomaticSeparator(java.lang.String automaticSeparator)
Deprecated.Sets the automatic separator that is written to aCodegenWritereach time the writer is reused.The default line separator is a newline ("\n"), but some implementations may wish to use an alternative value (e.g., "\r\n") or to disable the newline separator altogether by proving an empty string.
- Parameters:
automaticSeparator- The non-null line separator to use.
-
-