Class MappedReservedWords
java.lang.Object
software.amazon.smithy.codegen.core.MappedReservedWords
- All Implemented Interfaces:
ReservedWords
A reserved words implementation that maps known words to other words.
The following example shows how to use this class to make reserved words safe for the targeted code:
ReservedWords reserved = MappedReservedWords.builder()
.put("exception", "apiException")
.put("void", "void_")
.build();
String safeWord = reserved.escape("exception");
System.out.println(safeWord); // outputs "apiException"
The detection of reserved words can be made case-insensitive such that "bar", "BAR", "Bar", etc., can be detected as reserved words.
ReservedWords reserved = MappedReservedWords.builder()
.put("foo", "Hi")
.putCaseInsensitive("bar", "bam")
.build();
assert(reserved.escape("foo").equals("Hi"));
assert(reserved.escape("Foo").equals("Foo"));
assert(reserved.escape("BAR").equals("bam"));
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder to create a newMappedReservedWords
instance. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MappedReservedWords.Builder
builder()
Escapes a reserved word.boolean
isReserved
(String word) Checks if the given word is reserved.
-
Constructor Details
-
MappedReservedWords
- Parameters:
mappings
- Map of reserved word to replacement words.caseInsensitiveMappings
- Map of case-insensitive reserved word to replacement words.
-
-
Method Details
-
builder
- Returns:
- Creates a new Builder.
-
escape
Description copied from interface:ReservedWords
Escapes a reserved word.- Specified by:
escape
in interfaceReservedWords
- Parameters:
word
- Word to escape.- Returns:
- Returns the converted value.
-
isReserved
Description copied from interface:ReservedWords
Checks if the given word is reserved.- Specified by:
isReserved
in interfaceReservedWords
- Parameters:
word
- Word to check.- Returns:
- Returns true if the word is reserved.
-