Class Lexicals.Identifier.Simple

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Lexicals.Identifier.Pseudo
Enclosing class:
Lexicals.Identifier

public static class Lexicals.Identifier.Simple
extends Lexicals.Identifier.Unqualified<Lexicals.Identifier.Simple>
Class representing an unqualified identifier in the form of a name (whether a case-insensitive "regular identifier" without quotes, or a delimited form).
See Also:
Serialized Form
  • Field Details

    • m_nonFolded

      protected final String m_nonFolded
  • Method Details

    • from

      public static Lexicals.Identifier.Simple from​(String s, boolean quoted)
      Create an Identifier.Simple given its original, non-folded spelling, and whether it represents a quoted identifier.
      Parameters:
      s - The exact, internal, non-folded spelling of the identifier (unwrapped from any quoting in its external form).
      quoted - Pass true if this was parsed from any quoted external form, false if non-quoted.
      Returns:
      A corresponding Identifier.Simple
      Throws:
      IllegalArgumentException - if quoted is false but s cannot be a non-quoted identifier, or s is empty or longer than the ISO SQL maximum 128 codepoints.
    • concat

      public Lexicals.Identifier.Simple concat​(Object... more)
      Concatenates one or more strings or identifiers to the end of this identifier.

      The arguments may be instances of Simple or of CharSequence, in any combination.

      The resulting identifier folds if this identifier and all identifier arguments fold and the concatenation (with all Simple and CharSequence components included) still matches the ISO_AND_PG_REGULAR_IDENTIFIER pattern.

    • fromCatalog

      public static Lexicals.Identifier.Simple fromCatalog​(String s)
      Create an Identifier.Simple from a name string found in a PostgreSQL system catalog.

      There is not an explicit indication in the catalog of whether the name was originally quoted. It must have been, however, if it does not have the form of a regular identifier, or if it has that form but does not match its pgFold-ed form (without quotes, PG would have folded it in that case).

      Parameters:
      s - name of the simple identifier, as found in a system catalog.
      Returns:
      an Identifier.Simple or subclass appropriate to the form of the name.
    • fromJava

      public static Lexicals.Identifier.Simple fromJava​(String s)
      Create an Identifier.Simple from a name string supplied in Java source, such as an annotation value.

      Equivalent to fromJava(s, null).

    • fromJava

      public static Lexicals.Identifier.Simple fromJava​(String s, Messager msgr)
      Create an Identifier.Simple from a name string supplied in Java source, such as an annotation value.

      Historically, PL/Java has treated these identifiers as regular ones, requiring delimited ones to be represented by adding quotes explicitly at start and end, and doubling internal quotes, all escaped for Java, naturally. This method accepts either of those forms, and will also accept a string that neither qualifies as a regular identifier nor starts and ends with quotes. Such a string will be treated as if it were a delimited identifier with the start/end quotes already stripped and internal ones already undoubled.

      The SQL Unicode escape syntax is not accepted here. Java already has its own Unicode escape syntax, which is what should be used.

      Parameters:
      s - name of the simple identifier, as found in Java source.
      msgr - a Messager for reporting diagnostics at compile time, or null if not in a compilation context.
      Returns:
      an Identifier.Simple or subclass appropriate to the form of the name.
    • withQualifier

      Description copied from class: Lexicals.Identifier.Unqualified
      Form an Identifier.Qualified with this as the local part.
      Specified by:
      withQualifier in class Lexicals.Identifier.Unqualified<Lexicals.Identifier.Simple>
    • deparse

      public String deparse​(Charset cs)
      Description copied from class: Lexicals.Identifier
      This Identifier represented as it would be in SQL source.

      The passed Charset indicates the character encoding in which the deparsed result will be stored; the method should verify that the characters can be encoded there, or use the Unicode delimited identifier form and escape the ones that cannot.

      Specified by:
      deparse in class Lexicals.Identifier
      Returns:
      The identifier, quoted, unless it is folding.
    • deparse

      public String deparse​(Lexicals.Identifier.Simple qualifier, Charset cs)
      Description copied from class: Lexicals.Identifier.Unqualified
      Produce the deparsed form of a qualified identifier with the given qualifier and this as the local part.
      Specified by:
      deparse in class Lexicals.Identifier.Unqualified<Lexicals.Identifier.Simple>
    • folds

      public boolean folds()
      Whether this Identifier case-folds.
      Returns:
      true if this Identifier was non-quoted in the source, false if it was quoted.
    • nonFolded

      public String nonFolded()
      This Identifier's original spelling.
      Returns:
      The spelling as seen in the source, with no case folding.
    • pgFolded

      public String pgFolded()
      This Identifier as PostgreSQL would case-fold it (or the same as nonFolded if this was quoted and does not fold).
      Returns:
      The spelling with ASCII letters (only) folded to lowercase, if this Identifier folds.
    • isoFolded

      public String isoFolded()
      This Identifier as ISO SQL would case-fold it (or the same as nonFolded if this was quoted and does not fold).
      Returns:
      The spelling with lowercase and titlecase letters folded to (possibly length-changing) uppercase equivalents, if this Identifier folds.
    • hashCode

      public int hashCode()
      For a quoted identifier that could not match any non-quoted one, the hash code of its non-folded spelling is good enough. In other cases, the code must be derived more carefully.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals​(Object other, Messager msgr)
      Description copied from class: Lexicals.Identifier
      For use in an annotation processor, a version of equals that can take a Messager and use it to emit warnings. It will emit a warning whenever it compares two Identifiers that are equal by one or the other of PostgreSQL's or ISO SQL's rules but not both.
      Specified by:
      equals in class Lexicals.Identifier
      Parameters:
      other - Object to compare to
      msgr - a Messager to use for warnings; if null, no warnings will be generated.
      Returns:
      true if two quoted Identifiers match exactly, or two non-quoted ones match in either the PostgreSQL or ISO SQL folded form, or a quoted one exactly matches either folded form of a non-quoted one.
    • pgFold

      public static String pgFold​(String s)
      Case-fold a string by the PostgreSQL rules (assuming a multibyte server encoding, where only the 26 uppercase ASCII letters fold to lowercase).
      Parameters:
      s - The non-folded value.
      Returns:
      The folded value.