Polish SpEL Tokenizer
This commit is contained in:
@@ -966,7 +966,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
if (desiredTokenKind == TokenKind.IDENTIFIER) {
|
||||
// Might be one of the textual forms of the operators (e.g. NE for != ) -
|
||||
// in which case we can treat it as an identifier. The list is represented here:
|
||||
// Tokenizer.alternativeOperatorNames and those ones are in order in the TokenKind enum.
|
||||
// Tokenizer.ALTERNATIVE_OPERATOR_NAMES and those ones are in order in the TokenKind enum.
|
||||
if (t.kind.ordinal() >= TokenKind.DIV.ordinal() && t.kind.ordinal() <= TokenKind.NOT.ordinal() &&
|
||||
t.data != null) {
|
||||
// if t.data were null, we'd know it wasn't the textual form, it was the symbol form
|
||||
|
||||
@@ -35,7 +35,14 @@ import org.springframework.expression.spel.SpelParseException;
|
||||
*/
|
||||
class Tokenizer {
|
||||
|
||||
// If this gets changed, it must remain sorted...
|
||||
/**
|
||||
* Alternative textual operator names which must match enum constant names
|
||||
* in {@link TokenKind}.
|
||||
* <p>Note that {@code AND} and {@code OR} are also alternative textual
|
||||
* names, but they are handled later in {@link InternalSpelExpressionParser}.
|
||||
* <p>If this list gets changed, it must remain sorted since we use it with
|
||||
* {@link Arrays#binarySearch(Object[], Object)}.
|
||||
*/
|
||||
private static final String[] ALTERNATIVE_OPERATOR_NAMES =
|
||||
{"DIV", "EQ", "GE", "GT", "LE", "LT", "MOD", "NE", "NOT"};
|
||||
|
||||
@@ -448,8 +455,8 @@ class Tokenizer {
|
||||
char[] subarray = subarray(start, this.pos);
|
||||
|
||||
// Check if this is the alternative (textual) representation of an operator (see
|
||||
// alternativeOperatorNames)
|
||||
if ((this.pos - start) == 2 || (this.pos - start) == 3) {
|
||||
// ALTERNATIVE_OPERATOR_NAMES).
|
||||
if (subarray.length == 2 || subarray.length == 3) {
|
||||
String asString = new String(subarray).toUpperCase();
|
||||
int idx = Arrays.binarySearch(ALTERNATIVE_OPERATOR_NAMES, asString);
|
||||
if (idx >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user