Interface ReservedWords
- All Known Implementing Classes:
MappedReservedWords
public interface ReservedWords
Determines what is reserved and escapes reserved words.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ReservedWords
compose
(ReservedWords... delegates) Composes multiple instance ofReservedWords
into a single implementation that delegates to them one after the other.Escapes a reserved word.static ReservedWords
identity()
Creates a reserved word implementation that does not modify words.boolean
isReserved
(String word) Checks if the given word is reserved.
-
Method Details
-
escape
Escapes a reserved word.- Parameters:
word
- Word to escape.- Returns:
- Returns the converted value.
-
isReserved
Checks if the given word is reserved.- Parameters:
word
- Word to check.- Returns:
- Returns true if the word is reserved.
-
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
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.
-