Allow NEW and T to be used as unquoted map keys in SpEL
This change provides support for map[NEW], map[new], map[T] and map[t]. Prior to this change the 'new' and 't' had to be quoted because they were keywords in SpEL for a constructor reference and type reference respectively. Issue: SPR-11783
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -556,7 +556,13 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
if (!typeName.stringValue().equals("T")) {
|
||||
return false;
|
||||
}
|
||||
nextToken();
|
||||
// It looks like a type reference but is T being used as a map key?
|
||||
Token t = nextToken();
|
||||
if (peekToken(TokenKind.RSQUARE)) {
|
||||
// looks like 'T]' (T is map key)
|
||||
push(new PropertyOrFieldReference(false,t.data,toPos(t)));
|
||||
return true;
|
||||
}
|
||||
eatToken(TokenKind.LPAREN);
|
||||
SpelNodeImpl node = eatPossiblyQualifiedId();
|
||||
// dotted qualified id
|
||||
@@ -754,6 +760,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
private boolean maybeEatConstructorReference() {
|
||||
if (peekIdentifierToken("new")) {
|
||||
Token newToken = nextToken();
|
||||
// It looks like a constructor reference but is NEW being used as a map key?
|
||||
if (peekToken(TokenKind.RSQUARE)) {
|
||||
// looks like 'NEW]' (so NEW used as map key)
|
||||
push(new PropertyOrFieldReference(false,newToken.data,toPos(newToken)));
|
||||
return true;
|
||||
}
|
||||
SpelNodeImpl possiblyQualifiedConstructorName = eatPossiblyQualifiedId();
|
||||
List<SpelNodeImpl> nodes = new ArrayList<SpelNodeImpl>();
|
||||
nodes.add(possiblyQualifiedConstructorName);
|
||||
|
||||
Reference in New Issue
Block a user