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 as
List<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 of
ShapeId
. 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
. TraitCodegenWriter.CapitalizingFormatter
|'U'
- This formatter will capitalize the first letter of any string literal it is used to format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TraitCodegenWriter.Factory
A factory class to createTraitCodegenWriter
s.
-
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 java.lang.String
getHeader()
java.lang.String
getPackageHeader()
void
newLine()
void
override()
java.lang.String
toString()
Gets the contents of the generated code.void
writeDocString(java.lang.String contents)
Writes the provided text in the format of a Java doc string.-
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
-
writeDocString
public void writeDocString(java.lang.String contents)
Writes the provided text in the format of a Java doc string.- Parameters:
contents
- text to format as a doc string.
-
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()
-
-