Interface ReservedWords
-
- All Known Implementing Classes:
MappedReservedWords
public interface ReservedWords
Determines what is reserved and escapes reserved words.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ReservedWords
compose(ReservedWords... delegates)
Composes multiple instance ofReservedWords
into a single implementation that delegates to them one after the other.java.lang.String
escape(java.lang.String word)
Escapes a reserved word.static ReservedWords
identity()
Creates a reserved word implementation that does not modify words.boolean
isReserved(java.lang.String word)
Checks if the given word is reserved.
-
-
-
Method Detail
-
escape
java.lang.String escape(java.lang.String word)
Escapes a reserved word.- Parameters:
word
- Word to escape.- Returns:
- Returns the converted value.
-
isReserved
boolean isReserved(java.lang.String word)
Checks if the given word is reserved.- Parameters:
word
- Word to check.- Returns:
- Returns true if the word is reserved.
-
identity
static ReservedWords identity()
Creates a reserved word implementation that does not modify words.ReservedWords reserved = ReservedWords.identity(); reserved.isReserved("foo"); // always returns false for anything.
- Returns:
- Returns the identity implementation.
-
compose
static ReservedWords compose(ReservedWords... delegates)
Composes multiple instance ofReservedWords
into a single implementation that delegates to them one after the other.Each reserved words implementation is invoked one after the other until one of them returns true for
isReserved(java.lang.String)
.ReservedWords a = MappedReservedWords.builder().put("void", "_void").build(); ReservedWords b = MappedReservedWords.builder().put("foo", "_foo").build(); ReservedWords composed = ReservedWords.compose(a, b); String safeWordA = composed.escape("void"); String safeWordB = composed.escape("foo"); System.out.println(safeWordA + " " + safeWordB); // outputs "_void _foo"
- Parameters:
delegates
- ReservedWords instances to delegate to.- Returns:
- Returns the created
ReservedWords
instance.
-
-