- java.lang.Object
-
- org.postgresql.pljava.sqlgen.Lexicals.Identifier
-
- org.postgresql.pljava.sqlgen.Lexicals.Identifier.Unqualified<Lexicals.Identifier.Simple>
-
- org.postgresql.pljava.sqlgen.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.postgresql.pljava.sqlgen.Lexicals.Identifier
Lexicals.Identifier.Operator, Lexicals.Identifier.Pseudo, Lexicals.Identifier.Qualified<T extends Lexicals.Identifier.Unqualified<T>>, Lexicals.Identifier.Simple, Lexicals.Identifier.Unqualified<T extends Lexicals.Identifier.Unqualified<T>>
-
-
Field Summary
Fields Modifier and Type Field Description protected String
m_nonFolded
-
Method Summary
Modifier and Type Method Description Lexicals.Identifier.Simple
concat(Object... more)
Concatenates one or more strings or identifiers to the end of this identifier.String
deparse(Charset cs)
This Identifier represented as it would be in SQL source.String
deparse(Lexicals.Identifier.Simple qualifier, Charset cs)
Produce the deparsed form of a qualified identifier with the given qualifier and this as the local part.boolean
equals(Object other, Messager msgr)
For use in an annotation processor, a version ofequals
that can take aMessager
and use it to emit warnings.boolean
folds()
Whether this Identifier case-folds.static Lexicals.Identifier.Simple
from(String s, boolean quoted)
Create anIdentifier.Simple
given its original, non-folded spelling, and whether it represents a quoted identifier.static Lexicals.Identifier.Simple
fromCatalog(String s)
Create anIdentifier.Simple
from a name string found in a PostgreSQL system catalog.static Lexicals.Identifier.Simple
fromJava(String s)
Create anIdentifier.Simple
from a name string supplied in Java source, such as an annotation value.static Lexicals.Identifier.Simple
fromJava(String s, Messager msgr)
Create anIdentifier.Simple
from a name string supplied in Java source, such as an annotation value.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.String
isoFolded()
This Identifier as ISO SQL would case-fold it (or the same as nonFolded if this was quoted and does not fold).String
nonFolded()
This Identifier's original spelling.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).String
pgFolded()
This Identifier as PostgreSQL would case-fold it (or the same as nonFolded if this was quoted and does not fold).Lexicals.Identifier.Qualified<Lexicals.Identifier.Simple>
withQualifier(Lexicals.Identifier.Simple qualifier)
Form anIdentifier.Qualified
with this as the local part.-
Methods inherited from class org.postgresql.pljava.sqlgen.Lexicals.Identifier
equals, toString
-
-
-
-
Field Detail
-
m_nonFolded
protected final String m_nonFolded
-
-
Method Detail
-
from
public static Lexicals.Identifier.Simple from(String s, boolean quoted)
Create anIdentifier.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
- Passtrue
if this was parsed from any quoted external form, false if non-quoted.- Returns:
- A corresponding Identifier.Simple
- Throws:
IllegalArgumentException
- ifquoted
isfalse
buts
cannot be a non-quoted identifier, ors
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 ofCharSequence
, in any combination.The resulting identifier folds if this identifier and all identifier arguments fold and the concatenation (with all
Simple
andCharSequence
components included) still matches theISO_AND_PG_REGULAR_IDENTIFIER
pattern.
-
fromCatalog
public static Lexicals.Identifier.Simple fromCatalog(String s)
Create anIdentifier.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 anIdentifier.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 anIdentifier.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
public Lexicals.Identifier.Qualified<Lexicals.Identifier.Simple> withQualifier(Lexicals.Identifier.Simple qualifier)
Description copied from class:Lexicals.Identifier.Unqualified
Form anIdentifier.Qualified
with this as the local part.- Specified by:
withQualifier
in classLexicals.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 classLexicals.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 classLexicals.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.
-
equals
public boolean equals(Object other, Messager msgr)
Description copied from class:Lexicals.Identifier
For use in an annotation processor, a version ofequals
that can take aMessager
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 classLexicals.Identifier
- Parameters:
other
- Object to compare tomsgr
- a Messager to use for warnings; ifnull
, 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.
-
-