Interface ImportContainer


  • public interface ImportContainer
    Contains the imports associated with a specific file.

    The only required method is importSymbol(software.amazon.smithy.codegen.core.Symbol, java.lang.String), but implementations are expected to also override toString() so that it contains the formatted imports that can be written as code to a file. Other methods can, and should, be added to make working with language specific imports easier too.

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void importSymbol​(Symbol symbol)
      Adds an import for the given symbol if and only if the "namespace" of the provided Symbol differs from the "namespace" associated with the ImportContainer.
      void importSymbol​(Symbol symbol, java.lang.String alias)
      Adds an import for the given symbol if and only if the "namespace" of the provided Symbol differs from the "namespace" associated with the ImportContainer.
      java.lang.String toString()
      Implementations must implement a custom toString method that converts the collected imports to code that can be written to a CodeWriter.
    • Method Detail

      • importSymbol

        void importSymbol​(Symbol symbol,
                          java.lang.String alias)
        Adds an import for the given symbol if and only if the "namespace" of the provided Symbol differs from the "namespace" associated with the ImportContainer.

        "namespace" in this context can mean whatever it needs to mean for the target programming language. In some languages, it might mean the path to a file. In others, it might mean a proper namespace string. It's up to subclasses to both track a current "namespace" and implement this method in a way that makes sense.

        Parameters:
        symbol - Symbol to import if it's in another namespace.
        alias - Alias to import the symbol as.
      • importSymbol

        default void importSymbol​(Symbol symbol)
        Adds an import for the given symbol if and only if the "namespace" of the provided Symbol differs from the "namespace" associated with the ImportContainer.
        Parameters:
        symbol - The symbol to import.
        See Also:
        importSymbol(Symbol, String)
      • toString

        java.lang.String toString()
        Implementations must implement a custom toString method that converts the collected imports to code that can be written to a CodeWriter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        Returns the collected imports as a string.