public interface ReservedWords
Modifier and Type | Method and Description |
---|---|
static ReservedWords |
compose(ReservedWords... delegates)
Composes multiple instance of
ReservedWords 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.
|
java.lang.String escape(java.lang.String word)
word
- Word to escape.boolean isReserved(java.lang.String word)
word
- Word to check.static ReservedWords identity()
ReservedWords reserved = ReservedWords.identity();
reserved.isReserved("foo"); // always returns false for anything.
static ReservedWords compose(ReservedWords... delegates)
ReservedWords
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"
delegates
- ReservedWords instances to delegate to.ReservedWords
instance.