Amplication AST Libraries Documentation
    Preparing search index...

    The Writer class is responsible for writing Java code with proper formatting. It handles indentation, imports, and provides utility methods for writing code. This class is the core component for generating properly formatted Java source code.

    Implements

    Index

    Constructors

    • Creates a new Writer instance with the specified configuration.

      Parameters

      Returns Writer

    Methods

    • Increases the current indentation level by one. Used for proper code formatting.

      Returns void

    • Decreases the current indentation level by one. Used for proper code formatting.

      Returns void

    • Writes text to the buffer without adding a new line.

      Parameters

      • text: string

        The text to write

      Returns void

    • Writes a line of text to the buffer with proper indentation. If no text is provided, only writes a new line.

      Parameters

      • Optionaltext: string

        The text to write (optional)

      Returns void

    • Adds a new line to the buffer.

      Returns void

    • Adds a new line to the buffer only if the last character isn't already a new line. This prevents multiple consecutive empty lines.

      Returns void

    • Adds a class reference to be imported. References from the same package are not added.

      Parameters

      Returns void

    • Adds an import statement to the list of imports.

      Parameters

      • importName: string

        The full import path

      Returns void

    • Generates the final Java code with imports and package declaration.

      Returns string

      The complete Java code as a string

    • Formats the output code to have consistent spacing.

      Parameters

      • code: string

        The code to format

      Returns string

      The formatted code