Class ReservedWordSymbolProvider
- java.lang.Object
-
- software.amazon.smithy.codegen.core.ReservedWordSymbolProvider
-
- All Implemented Interfaces:
SymbolProvider
public final class ReservedWordSymbolProvider extends java.lang.Object implements SymbolProvider
Decorates aSymbolProvider
by passing values through context specificReservedWords
implementations.A specific
ReservedWords
implementation can be registered for each kind of symbol provided by the delegatedSymbolProvider
. 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
andReservedWords
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 ofReservedWordSymbolProvider
. 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReservedWordSymbolProvider.Builder
Builder to build aReservedWordSymbolProvider
.static class
ReservedWordSymbolProvider.Escaper
Uses to manually escapeSymbol
s and member names.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ReservedWordSymbolProvider.Builder
builder()
Builder to create a ReservedWordSymbolProvider instance.java.lang.String
toMemberName(MemberShape shape)
Converts a member shape to a member/property name of a containing data structure.Symbol
toSymbol(Shape shape)
Gets the symbol to define for the given shape.
-
-
-
Method Detail
-
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 interfaceSymbolProvider
- Parameters:
shape
- Shape to get the class name of.- Returns:
- Returns the generated class name.
-
toMemberName
public java.lang.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 interfaceSymbolProvider
- Parameters:
shape
- Shape to convert.- Returns:
- Returns the converted member name.
-
-