Class 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 the TraitCodegenWriter.JavaTypeFormatter.
    TraitCodegenWriter.CapitalizingFormatter|'U'
    This formatter will capitalize the first letter of any string literal it is used to format.
    • 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 class AbstractCodeWriter<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()