Top Description Inners Fields Constructors Methods
org.eclipse.persistence.jpa.jpql

public final Class WordParser

extends Object
Class Inheritance

This "parser/scanner" holds onto the string version of the JPQL query that is parsed into a parsed tree. It uses a cursor that lets the current Expression object to parse its fragment of the query.

Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.

Author
Pascal Filion
Since
2.3
Version
2.5.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
WordParser.WordType

This enumeration determines the type of word that was scanned.

Field Summary

Modifier and TypeField and Description
private int
cursor

The current position of the cursor within the JPQL query.

private final int
length

The length of the JPQL query.

private final CharSequence
text

The string representation of the JPQL query.

private WordParser.WordType
wordType

When WordParser#word(), WordParser#wordEndPosition(), or WordParser#wordEndPosition(int) is called, this is updated to reflect the type of word that is scanned.

Constructor Summary

AccessConstructor and Description
public
WordParser(CharSequence
The string representation of the JPQL query
text
)

Creates a new WordParser.

Method Summary

Modifier and TypeMethod and Description
public char

Returns:

The character retrieved from the string at the current cursor position or '\0' if the position is beyond the end of the text
character
()

Retrieves the character at the current cursor position.

public char

Returns:

The character retrieved from the string at the given position or '\0' if the position is beyond the end of the text
character
(int
The position of the character to return
position
)

Retrieves the character at the given cursor position.

public boolean

Returns:

true if the character sequence represented by the argument is a suffix of the query; false otherwise
endsWith
(int
The position where the check stops
endPosition
,
String
The suffix is the text that is used to match it with the substring within the text
suffix
)

Determines whether the query ends with the given suffix and the end position is the end of the range for testing.

public boolean

Returns:

true if the character sequence represented by the argument is a suffix of the query; false otherwise
endsWithIgnoreCase
(int
The position where the check stops
endPosition
,
String
The suffix is the text that is used to match it with the substring within the text
suffix
)

Determines whether the query ends with the given suffix and the end position is the end of the range for testing.

public String

Returns:

The word in which the cursor is
entireWord
()

Retrieves a word starting at the current position.

public String

Returns:

The word in which the cursor is
entireWord
(int
The position where to retrieve the word
position
)

Retrieves a word starting at the given position.

public WordParser.WordType

Returns:

The category of the word returned by word()
getWordType
()

Returns what the type of word word() returns.

public boolean

Returns:

true if the given character is one of the valid math symbols; false otherwise
isArithmeticSymbol
(char
The character to test if it's a math symbol
character
)

Determines whether the given character is an arithmetic symbol, which is one of the following: { '>', '<', '/', '*', '-', '+', '=', '{'} .

public boolean

Returns:

true if the given character is a delimiter; false otherwise
isDelimiter
(char
The character to test
character
)

Determines whether the given character is a delimiter.

public boolean

Returns:

true if the given character is a digit; false otherwise
isDigit
(char
The character to test if it's a digit
character
)

Determines whether the given character is a character that can be used in a number.

public boolean

Returns:

true if the position of the cursor is at the end of the text; false otherwise
isTail
()

Determines whether the position of the cursor is at the end of the text.

public boolean

Returns:

true if the character can be part of a word; false if it is not an alphanumeric character, which usually means is a whitespace, a delimiter or an arithmetic symbol
isWordSeparator
(char
The character used to determine if it should be part of a word or not
character
)

Determines whether the given character is not considered to be part of a word (which is usually comprise of alphanumeric characters).

public int

Returns:

The total count of characters
length
()

Returns the length of the string value.

public void
moveBackward(CharSequence
The word used to determine how much to move the position forward
word
)

Moves the position of the cursor by the length of the given word.

public void
moveBackward(int
The amount to remove from the current position
position
)

Moves backward the position of the cursor by the given amount.

public String

Returns:

The actual portion of the text that was skipped
moveForward
(CharSequence
The word used to determine how much to move the position forward
word
)

Moves the position of the cursor by the length of the given word.

public String

Returns:

The actual portion of the text that was skipped
moveForward
(int
The amount to add to the current position
position
)

Moves forward the position of the cursor by the given amount.

public String

Returns:

The actual portion of the text that was skipped
moveForwardIgnoreWhitespace
(CharSequence
The word used to determine how much to move the position forward
word
)

Moves the position of the cursor by the length of the given word and ignore any different in whitespace count.

public String

Returns:

The numeric literal value
numericLiteral
()

Retrieves the numeric literal that should be the current word to parse.

public String

Returns:

The sub-string that is before the position
partialWord
()

Retrieves a word before the current position of the cursor, which determines when the parsing stop.

public String

Returns:

The sub-string that is before the position
partialWord
(int
The position of the cursor
position
)

Retrieves a word before the specified position, which determines when the parsing stop.

public int

Returns:

The position, which is a smaller number or equal, than the given position
partialWordStartPosition
(int
The position from which the search ends
position
)

Finds the beginning of the word and the given position is within that word.

public int

Returns:

The current position of the cursor
position
()

Returns the current position of the cursor.

private int
scanNumericLiteral(int startPosition)

private int

Returns:

The first word contained in the text, if none could be found, then an empty string is returned
scanStringLiteral
(int
the current position that will be used to parse the literal
startPosition
)

Retrieves the first word from the given text starting at the specified position.

public void
setPosition(int
The new position of the cursor
position
)

Manually sets the position of the cursor within the string.

public int

Returns:

The number of whitespace removed
skipLeadingWhitespace
()

Removes the whitespace that starts the given text.

public boolean

Returns:

true if the text starts with the given character at the current position; false otherwise
startsWith
(char
The possible character at the current position
possibleCharacter
)

Determines whether the text starts with the given character.

public boolean

Returns:

true if the character sequence represented by the argument is a prefix of the text; false otherwise
startsWith
(CharSequence
The prefix
prefix
)

Tests whether the query starts with the specified prefix from the current position.

public boolean

Returns:

true if the character sequence represented by the argument is a prefix of the substring of this object starting at index startIndex; false otherwise
startsWith
(CharSequence
The prefix
prefix
,
int
Where to begin looking in the query
startIndex
)

Tests whether the substring of the query beginning at the specified index starts with the specified prefix.

public boolean

Returns:

true if the character at the current position is an arithmetic operator; false otherwise
startsWithArithmeticOperator
()

Determines whether the character at the current position is one of the arithmetic operators: { '+', '-', '*', '/' },

public Boolean

Returns:

true if the text starts with a digit (we'll assume it is a digit if the text starts with a digit or an arithmetic sign followed by a digit), false if it starts with an arithmetic term (we'll assume it is a digit followed by a non-digit character); otherwise returns null
startsWithDigit
()

Determines if the text starts with a digit (true), an arithmetic term (false) or anything else (null).

public boolean

Returns:

true if the text starts with the given text (case is ignored) and the cursor is at the end of the text or is following by a word separator character; false otherwise
startsWithIdentifier
(CharSequence
The JPQL identifier to match with the text at the current position
identifier
)

Determines whether the text at the current position start with the following identifier.

public boolean

Returns:

true if the text starts with the given text (case is ignored) and the cursor is at the end of the text or is following by a word separator character; false otherwise
startsWithIdentifier
(CharSequence
The JPQL identifier to match with the text at the current position
identifier
,
int
The position to start matching the characters
position
)

Determines whether the text at the current position start with the following identifier.

public boolean

Returns:

true if the text starts with the given character at the current position; false otherwise
startsWithIgnoreCase
(char
The possible character at the current position
possibleCharacter
)

Determines whether the text starts with the given character.

public boolean

Returns:

true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals(Object) method
startsWithIgnoreCase
(CharSequence
The prefix to test against
prefix
)

Tests if the string starts with the specified prefix.

public boolean

Returns:

true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise
startsWithIgnoreCase
(CharSequence
The prefix to test against
prefix
,
int
Where to begin looking in this string
offset
)

Tests if the string starts with the specified prefix.

public String

Returns:

The remain of the string starting at the current position
substring
()

Returns a substring that is within the current position of the cursor and the end of the text.

public String

Returns:

The remain of the string starting at the given position
substring
(int
The beginning of the substring, inclusive
startIndex
)

Returns a substring that is within the given position and the end of the text.

public String

Returns:

The remain of the string that is within the given positions
substring
(int
The beginning of the substring, inclusive
startIndex
,
int
The end of the substring, exclusive
endIndex
)

Returns a substring that is within the given positions.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public int

Returns:

The count of consecutive whitespace found from the current position
whitespaceCount
()

Calculates the number of whitespace that are in the query.

public int

Returns:

The count of consecutive whitespace found from the given position
whitespaceCount
(int
The position from where the scan starts
position
)

Calculates the number of whitespace that are in the query.

public String

Returns:

The first word contained in the text, if none could be found, then an empty string is returned
word
()

Retrieves the first word starting at the current position.

public int

Returns:

The position where the current word ends
wordEndPosition
()

Returns the position a word would end based on the current cursor position.

public int

Returns:

The position where the current word ends
wordEndPosition
(int
The position to start scanning the text
position
)

Returns the position a word would end based on the given start position.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cursorback to summary
private int cursor

The current position of the cursor within the JPQL query.

lengthback to summary
private final int length

The length of the JPQL query.

textback to summary
private final CharSequence text

The string representation of the JPQL query.

wordTypeback to summary
private WordParser.WordType wordType

When WordParser#word(), WordParser#wordEndPosition(), or WordParser#wordEndPosition(int) is called, this is updated to reflect the type of word that is scanned.

Since
2.4

Constructor Detail

WordParserback to summary
public WordParser(CharSequence text)

Creates a new WordParser.

Parameters
text:CharSequence

The string representation of the JPQL query

Method Detail

characterback to summary
public char character()

Retrieves the character at the current cursor position.

Returns:char

The character retrieved from the string at the current cursor position or '\0' if the position is beyond the end of the text

characterback to summary
public char character(int position)

Retrieves the character at the given cursor position.

Parameters
position:int

The position of the character to return

Returns:char

The character retrieved from the string at the given position or '\0' if the position is beyond the end of the text

endsWithback to summary
public boolean endsWith(int endPosition, String suffix)

Determines whether the query ends with the given suffix and the end position is the end of the range for testing.

Parameters
endPosition:int

The position where the check stops

suffix:String

The suffix is the text that is used to match it with the substring within the text

Returns:boolean

true if the character sequence represented by the argument is a suffix of the query; false otherwise

endsWithIgnoreCaseback to summary
public boolean endsWithIgnoreCase(int endPosition, String suffix)

Determines whether the query ends with the given suffix and the end position is the end of the range for testing. The case of the character is ignored.

Parameters
endPosition:int

The position where the check stops

suffix:String

The suffix is the text that is used to match it with the substring within the text

Returns:boolean

true if the character sequence represented by the argument is a suffix of the query; false otherwise

Since
2.5
entireWordback to summary
public String entireWord()

Retrieves a word starting at the current position. The text before and after the position will be part of the returned value.

For instance, "SELECT AVG(e.age) FROM Employee e":

  • Position 3, result is "SELECT";
  • Position 6, result is "SELECT";
  • Position 7, result is an empty string.
  • Position 11, result is an empty string.
  • Position 13, result is "e.".
Returns:String

The word in which the cursor is

entireWordback to summary
public String entireWord(int position)

Retrieves a word starting at the given position. The text before and after the position will be part of the returned value.

For instance, "SELECT AVG(e.age) FROM Employee e":

  • Position 3, result is "SELECT";
  • Position 6, result is "SELECT";
  • Position 7, result is an empty string.
  • Position 11, result is an empty string.
  • Position 13, result is "e.".
Parameters
position:int

The position where to retrieve the word

Returns:String

The word in which the cursor is

getWordTypeback to summary
public WordParser.WordType getWordType()

Returns what the type of word word() returns.

Returns:WordParser.WordType

The category of the word returned by word()

Since
2.4
isArithmeticSymbolback to summary
public boolean isArithmeticSymbol(char character)

Determines whether the given character is an arithmetic symbol, which is one of the following: { '>', '<', '/', '*', '-', '+', '=', '{'} .

Parameters
character:char

The character to test if it's a math symbol

Returns:boolean

true if the given character is one of the valid math symbols; false otherwise

isDelimiterback to summary
public boolean isDelimiter(char character)

Determines whether the given character is a delimiter. The delimiter are '(', ')' and ','.

Parameters
character:char

The character to test

Returns:boolean

true if the given character is a delimiter; false otherwise

isDigitback to summary
public boolean isDigit(char character)

Determines whether the given character is a character that can be used in a number. This only includes the numeric characters [0, 9] and the period character. This method should only be used to determine if a word starts with a digit character.

Parameters
character:char

The character to test if it's a digit

Returns:boolean

true if the given character is a digit; false otherwise

isTailback to summary
public boolean isTail()

Determines whether the position of the cursor is at the end of the text.

Returns:boolean

true if the position of the cursor is at the end of the text; false otherwise

isWordSeparatorback to summary
public boolean isWordSeparator(char character)

Determines whether the given character is not considered to be part of a word (which is usually comprise of alphanumeric characters).

Parameters
character:char

The character used to determine if it should be part of a word or not

Returns:boolean

true if the character can be part of a word; false if it is not an alphanumeric character, which usually means is a whitespace, a delimiter or an arithmetic symbol

See Also
ExpressionTools#isWhiteSpace(char), isArithmeticSymbol(char), isDelimiter(char)
lengthback to summary
public int length()

Returns the length of the string value.

Returns:int

The total count of characters

moveBackwardback to summary
public void moveBackward(CharSequence word)

Moves the position of the cursor by the length of the given word.

Parameters
word:CharSequence

The word used to determine how much to move the position forward

moveBackwardback to summary
public void moveBackward(int position)

Moves backward the position of the cursor by the given amount.

Parameters
position:int

The amount to remove from the current position

moveForwardback to summary
public String moveForward(CharSequence word)

Moves the position of the cursor by the length of the given word.

Parameters
word:CharSequence

The word used to determine how much to move the position forward

Returns:String

The actual portion of the text that was skipped

moveForwardback to summary
public String moveForward(int position)

Moves forward the position of the cursor by the given amount.

Parameters
position:int

The amount to add to the current position

Returns:String

The actual portion of the text that was skipped

moveForwardIgnoreWhitespaceback to summary
public String moveForwardIgnoreWhitespace(CharSequence word)

Moves the position of the cursor by the length of the given word and ignore any different in whitespace count. If the text has more than one whitespace and the given word usually has one, then only one will be part of the returned substring.

Parameters
word:CharSequence

The word used to determine how much to move the position forward

Returns:String

The actual portion of the text that was skipped

Since
2.4.3
numericLiteralback to summary
public String numericLiteral()

Retrieves the numeric literal that should be the current word to parse.

Returns:String

The numeric literal value

partialWordback to summary
public String partialWord()

Retrieves a word before the current position of the cursor, which determines when the parsing stop.

For instance, "SELECT AVG(e.age) FROM Employee e":

  • Position 3, result is "SEL";
  • Position 6, result is "SELECT";
  • Position 7, result is an empty string.
  • Position 11, result is an empty string.
  • Position 13, result is "e.".
Returns:String

The sub-string that is before the position

partialWordback to summary
public String partialWord(int position)

Retrieves a word before the specified position, which determines when the parsing stop.

For instance, "SELECT AVG(e.age) FROM Employee e":

  • Position 3, result is "SEL";
  • Position 6, result is "SELECT";
  • Position 7, result is an empty string.
  • Position 11, result is an empty string.
  • Position 13, result is "e.".
Parameters
position:int

The position of the cursor

Returns:String

The sub-string that is before the position

partialWordStartPositionback to summary
public int partialWordStartPosition(int position)

Finds the beginning of the word and the given position is within that word.

For instance, "SELECT AVG(e.age) FROM Employee e":

  • Position 3, result is 0;
  • Position 8, result is 7;
Parameters
position:int

The position from which the search ends

Returns:int

The position, which is a smaller number or equal, than the given position

positionback to summary
public int position()

Returns the current position of the cursor.

Returns:int

The current position of the cursor

scanNumericLiteralback to summary
private int scanNumericLiteral(int startPosition)
scanStringLiteralback to summary
private int scanStringLiteral(int startPosition)

Retrieves the first word from the given text starting at the specified position.

Parameters
startPosition:int

the current position that will be used to parse the literal

Returns:int

The first word contained in the text, if none could be found, then an empty string is returned

setPositionback to summary
public void setPosition(int position)

Manually sets the position of the cursor within the string. If the position is a negative number, the position will be 0.

Parameters
position:int

The new position of the cursor

skipLeadingWhitespaceback to summary
public int skipLeadingWhitespace()

Removes the whitespace that starts the given text.

Returns:int

The number of whitespace removed

startsWithback to summary
public boolean startsWith(char possibleCharacter)

Determines whether the text starts with the given character. The case of the character is not ignored.

Parameters
possibleCharacter:char

The possible character at the current position

Returns:boolean

true if the text starts with the given character at the current position; false otherwise

startsWithback to summary
public boolean startsWith(CharSequence prefix)

Tests whether the query starts with the specified prefix from the current position.

Parameters
prefix:CharSequence

The prefix

Returns:boolean

true if the character sequence represented by the argument is a prefix of the text; false otherwise

startsWithback to summary
public boolean startsWith(CharSequence prefix, int startIndex)

Tests whether the substring of the query beginning at the specified index starts with the specified prefix.

Parameters
prefix:CharSequence

The prefix

startIndex:int

Where to begin looking in the query

Returns:boolean

true if the character sequence represented by the argument is a prefix of the substring of this object starting at index startIndex; false otherwise

startsWithArithmeticOperatorback to summary
public boolean startsWithArithmeticOperator()

Determines whether the character at the current position is one of the arithmetic operators: { '+', '-', '*', '/' },

Returns:boolean

true if the character at the current position is an arithmetic operator; false otherwise

startsWithDigitback to summary
public Boolean startsWithDigit()

Determines if the text starts with a digit (true), an arithmetic term (false) or anything else (null).

Returns:Boolean

true if the text starts with a digit (we'll assume it is a digit if the text starts with a digit or an arithmetic sign followed by a digit), false if it starts with an arithmetic term (we'll assume it is a digit followed by a non-digit character); otherwise returns null

startsWithIdentifierback to summary
public boolean startsWithIdentifier(CharSequence identifier)

Determines whether the text at the current position start with the following identifier.

Parameters
identifier:CharSequence

The JPQL identifier to match with the text at the current position

Returns:boolean

true if the text starts with the given text (case is ignored) and the cursor is at the end of the text or is following by a word separator character; false otherwise

startsWithIdentifierback to summary
public boolean startsWithIdentifier(CharSequence identifier, int position)

Determines whether the text at the current position start with the following identifier.

Parameters
identifier:CharSequence

The JPQL identifier to match with the text at the current position

position:int

The position to start matching the characters

Returns:boolean

true if the text starts with the given text (case is ignored) and the cursor is at the end of the text or is following by a word separator character; false otherwise

startsWithIgnoreCaseback to summary
public boolean startsWithIgnoreCase(char possibleCharacter)

Determines whether the text starts with the given character. The case of the character is ignored.

Parameters
possibleCharacter:char

The possible character at the current position

Returns:boolean

true if the text starts with the given character at the current position; false otherwise

startsWithIgnoreCaseback to summary
public boolean startsWithIgnoreCase(CharSequence prefix)

Tests if the string starts with the specified prefix. The case of the character is ignored.

Parameters
prefix:CharSequence

The prefix to test against

Returns:boolean

true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals(Object) method

startsWithIgnoreCaseback to summary
public boolean startsWithIgnoreCase(CharSequence prefix, int offset)

Tests if the string starts with the specified prefix. The case of the character is ignored.

Parameters
prefix:CharSequence

The prefix to test against

offset:int

Where to begin looking in this string

Returns:boolean

true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise

substringback to summary
public String substring()

Returns a substring that is within the current position of the cursor and the end of the text.

Returns:String

The remain of the string starting at the current position

substringback to summary
public String substring(int startIndex)

Returns a substring that is within the given position and the end of the text.

Parameters
startIndex:int

The beginning of the substring, inclusive

Returns:String

The remain of the string starting at the given position

substringback to summary
public String substring(int startIndex, int endIndex)

Returns a substring that is within the given positions.

Parameters
startIndex:int

The beginning of the substring, inclusive

endIndex:int

The end of the substring, exclusive

Returns:String

The remain of the string that is within the given positions

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
whitespaceCountback to summary
public int whitespaceCount()

Calculates the number of whitespace that are in the query. The check starts at the current position.

Returns:int

The count of consecutive whitespace found from the current position

whitespaceCountback to summary
public int whitespaceCount(int position)

Calculates the number of whitespace that are in the query. The check starts at the current position.

Parameters
position:int

The position from where the scan starts

Returns:int

The count of consecutive whitespace found from the given position

wordback to summary
public String word()

Retrieves the first word starting at the current position.

Returns:String

The first word contained in the text, if none could be found, then an empty string is returned

wordEndPositionback to summary
public int wordEndPosition()

Returns the position a word would end based on the current cursor position. getWordType() can be used to determine the type of word that was scanned.

Returns:int

The position where the current word ends

See Also
WordParser.word(), WordType
wordEndPositionback to summary
public int wordEndPosition(int position)

Returns the position a word would end based on the given start position. getWordType() can be used to determine the type of word that was scanned.

Parameters
position:int

The position to start scanning the text

Returns:int

The position where the current word ends

See Also
WordParser.word(), WordType
org.eclipse.persistence.jpa.jpql back to summary

public final Enum WordParser.WordType

extends Enum<WordParser.WordType>
Class Inheritance

This enumeration determines the type of word that was scanned. It will be set by WordParser#word(), WordParser#wordEndPosition(), WordParser#wordEndPosition(int).

Field Summary

Modifier and TypeField and Description
public static final WordParser.WordType
INPUT_PARAMETER

The word being scanned is an input parameter, it starts with either ':' or '?'.

public static final WordParser.WordType
NUMERIC_LITERAL

The word being scanned is a numeric literal (decimal or hexadecimal number).

public static final WordParser.WordType
STRING_LITERAL

The word being scanned is a string literal, it starts with either ''' or '"'.

public static final WordParser.WordType
UNDEFINED

No word was scanned, this is usually set when the cursor is at the end of the text.

public static final WordParser.WordType
WORD

The word being scanned anything else other than an input parameter, numeric literal or string literal.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static WordParser.WordType
public static WordParser.WordType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INPUT_PARAMETERback to summary
public static final WordParser.WordType INPUT_PARAMETER

The word being scanned is an input parameter, it starts with either ':' or '?'.

NUMERIC_LITERALback to summary
public static final WordParser.WordType NUMERIC_LITERAL

The word being scanned is a numeric literal (decimal or hexadecimal number).

STRING_LITERALback to summary
public static final WordParser.WordType STRING_LITERAL

The word being scanned is a string literal, it starts with either ''' or '"'.

UNDEFINEDback to summary
public static final WordParser.WordType UNDEFINED

No word was scanned, this is usually set when the cursor is at the end of the text.

WORDback to summary
public static final WordParser.WordType WORD

The word being scanned anything else other than an input parameter, numeric literal or string literal.

Constructor Detail

WordTypeback to summary
private WordType()

Method Detail

valueOfback to summary
public static WordParser.WordType valueOf(String name)
valuesback to summary
public static WordParser.WordType[] values()