Class ReservedWordSymbolProvider

java.lang.Object
software.amazon.smithy.codegen.core.ReservedWordSymbolProvider
All Implemented Interfaces:
SymbolProvider

public final class ReservedWordSymbolProvider extends Object implements SymbolProvider
Decorates a SymbolProvider by passing values through context specific ReservedWords implementations.

A specific ReservedWords implementation can be registered for each kind of symbol provided by the delegated SymbolProvider. For example, reserved words can be created that are specific to class names.

This motivation behind this class is to allow more general purpose implementations of SymbolProvider and ReservedWords to be composed.

A warning is logged each time a symbol is renamed by a reserved words implementation.

SymbolProvider implementations that need to recursively call themselves in a way that requires recursive symbols to be escaped will need to manually make calls into ReservedWordSymbolProvider.Escaper and cannot be decorated by an instance of ReservedWordSymbolProvider. For example, this is the case if a list of strings needs to be turned into something like "Array[%s]" where "%s" is the symbol name of the targeted member.

  • Method Details

    • builder

      public static ReservedWordSymbolProvider.Builder builder()
      Builder to create a ReservedWordSymbolProvider instance.
      Returns:
      Returns a new builder.
    • toSymbol

      public Symbol toSymbol(Shape shape)
      Description copied from interface: SymbolProvider
      Gets the symbol to define for the given shape.

      A "symbol" represents the qualified name of a type in a target programming language.

      • When given a structure, union, resource, or service shape, this method should provide the namespace and name of the type to generate.
      • When given a simple type like a string, number, or timestamp, this method should return the language-specific type of the shape.
      • When given a member shape, this method should return the language specific type to use as the target of the member.
      • When given a list, set, or map, this method should return the language specific type to use for the shape (e.g., a map shape for a Python code generator might return "dict".
      Specified by:
      toSymbol in interface SymbolProvider
      Parameters:
      shape - Shape to get the class name of.
      Returns:
      Returns the generated class name.
    • toMemberName

      public String toMemberName(MemberShape shape)
      Description copied from interface: SymbolProvider
      Converts a member shape to a member/property name of a containing data structure.

      The default implementation will return the member name of the provided shape ID and should be overridden if necessary.

      Specified by:
      toMemberName in interface SymbolProvider
      Parameters:
      shape - Shape to convert.
      Returns:
      Returns the converted member name.