Interface ReservedWords

  • All Known Implementing Classes:
    MappedReservedWords

    public interface ReservedWords
    Determines what is reserved and escapes reserved words.
    • 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 of 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"
         
         
        Parameters:
        delegates - ReservedWords instances to delegate to.
        Returns:
        Returns the created ReservedWords instance.