Class TraitCodegenWriter
- java.lang.Object
-
- software.amazon.smithy.utils.AbstractCodeWriter<W>
-
- software.amazon.smithy.codegen.core.SymbolWriter<TraitCodegenWriter,software.amazon.smithy.traitcodegen.writer.TraitCodegenImportContainer>
-
- software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter
-
- All Implemented Interfaces:
SymbolDependencyContainer
public class TraitCodegenWriter extends SymbolWriter<TraitCodegenWriter,software.amazon.smithy.traitcodegen.writer.TraitCodegenImportContainer>
Writes Java code for trait definitions.This writer supports two custom formatters, a Java type formatter '$T' and a Base type formatter '$B'.
TraitCodegenWriter.JavaTypeFormatter
|'T'
: This formatter handles the formatting of Java types and also ensures that parameterized types (such asList<String>
are written correctly.TraitCodegenWriter.BaseTypeFormatter
|'B'
: This formatter allows you to use the base type for a trait. For example a String Trait may have a base type ofShapeId
. To write this base type, use the$B
formatter and provide the trait symbol. Note that if no base type is found (i.e. type is not a trait) then this formatter behaves exactly the same as theTraitCodegenWriter.JavaTypeFormatter
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class software.amazon.smithy.codegen.core.SymbolWriter
SymbolWriter.Factory<W extends SymbolWriter<W,? extends ImportContainer>>
-
-
Constructor Summary
Constructors Constructor Description TraitCodegenWriter(java.lang.String fileName, java.lang.String namespace, TraitCodegenSettings settings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeDocstring()
java.lang.String
getHeader()
java.lang.String
getPackageHeader()
void
newLine()
void
openDocstring()
void
override()
java.lang.String
toString()
Gets the contents of the generated code.void
writeDocStringContents(java.lang.String contents)
void
writeDocStringContents(java.lang.String contents, java.lang.Object... args)
-
Methods inherited from class software.amazon.smithy.codegen.core.SymbolWriter
addDependency, addImport, addUseImports, addUseImports, getDependencies, getImportContainer, setRelativizeSymbols
-
Methods inherited from class software.amazon.smithy.utils.AbstractCodeWriter
call, closeBlock, consumer, copySettingsFrom, dedent, dedent, disableNewlines, enableNewlines, enableStackTraceComments, ensureNewline, format, formatLiteral, formatWithStackTraceElement, getContext, getContext, getDebugInfo, getDebugInfo, getExpressionStart, getIndentLevel, getIndentText, getInsertTrailingNewline, getNewline, getNewlinePrefix, getTrimBlankLines, getTrimTrailingSpaces, indent, indent, injectSection, insertTrailingNewline, insertTrailingNewline, isStackTraceRelevant, onSection, onSection, openBlock, openBlock, openBlock, openBlock, openBlock, openBlock, openBlock, openBlock, popState, pushFilteredState, pushState, pushState, pushState, putContext, putContext, putFormatter, removeContext, setExpressionStart, setIndentText, setNewline, setNewline, setNewlinePrefix, trimBlankLines, trimBlankLines, trimTrailingSpaces, trimTrailingSpaces, unwrite, write, writeInline, writeInlineWithNoFormatting, writeOptional, writeWithNoFormatting
-
-
-
-
Constructor Detail
-
TraitCodegenWriter
public TraitCodegenWriter(java.lang.String fileName, java.lang.String namespace, TraitCodegenSettings settings)
-
-
Method Detail
-
openDocstring
public void openDocstring()
-
writeDocStringContents
public void writeDocStringContents(java.lang.String contents)
-
writeDocStringContents
public void writeDocStringContents(java.lang.String contents, java.lang.Object... args)
-
closeDocstring
public void closeDocstring()
-
toString
public java.lang.String toString()
Description copied from class:AbstractCodeWriter
Gets the contents of the generated code.The result will have an appended newline if the AbstractCodeWriter is configured to always append a newline. A newline is only appended in these cases if the result does not already end with a newline.
- Overrides:
toString
in classAbstractCodeWriter<TraitCodegenWriter>
- Returns:
- Returns the generated code.
-
getPackageHeader
public java.lang.String getPackageHeader()
-
getHeader
public java.lang.String getHeader()
-
newLine
public void newLine()
-
override
public void override()
-
-