Interface UseShapeWriterObserver<T extends CodegenWriter<T,?>>
- Type Parameters:
T- Type of CodegenWriter being used.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
The following example defines a UseShapeWriterObserver that
writes a comment before a shape is written:
public final class MyObserver implements UseShapeWriterObserver<MyWriter> {
\@Override
public void observe(Shape shape, Symbol symbol, SymbolProvider symbolProvider, MyWriter writer) {
writer.write("/// Writing $L", shape.getId());
}
}
-
Method Summary
Modifier and TypeMethodDescriptionvoidobserve(Shape shape, Symbol symbol, SymbolProvider symbolProvider, T writer) Invoked when aCodegenWriterwriter is used viaCodegenWriterDelegator.useShapeWriter(Shape, Consumer).
-
Method Details
-
observe
Invoked when aCodegenWriterwriter is used viaCodegenWriterDelegator.useShapeWriter(Shape, Consumer).This is an extension point that allows code generators to perform any kind of preprocessing they need before code is written to a
CodegenWriterfor a given shape. For example, this could be used to add comments to the generated code to indicate that a file is auto-generated.This method is invoked before the
writerConsumerofCodegenWriterDelegator.useShapeWriter(software.amazon.smithy.model.shapes.Shape, java.util.function.Consumer<T>)is called. This method is invoked within a pushed CodegenWriter state, so any state modifications made to the CodegenWriter will not persist after thewriterConsumerhas completed (e.g., calls to methods likeCodeWriter.indent()are not persisted).- Parameters:
shape- Shape being used.symbol- Symbol of the shape.symbolProvider- SymbolProvider associated with the delegator.writer- Writer being used for the shape.
-