Browse Source

SPR-7100: '_' supported as first char of identifier

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3254 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Andy Clement 16 years ago
parent
commit
efc8a513d1
  1. 3
      org.springframework.expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java
  2. 7
      org.springframework.expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java
  3. 4
      org.springframework.expression/src/test/java/org/springframework/expression/spel/testresources/Inventor.java

3
org.springframework.expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java

@ -57,6 +57,9 @@ class Tokenizer {
case '+': case '+':
pushCharToken(TokenKind.PLUS); pushCharToken(TokenKind.PLUS);
break; break;
case '_': // the other way to start an identifier
lexIdentifier();
break;
case '-': case '-':
pushCharToken(TokenKind.MINUS); pushCharToken(TokenKind.MINUS);
break; break;

7
org.springframework.expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java

@ -222,6 +222,12 @@ public class EvaluationTests extends ExpressionTestCase {
evaluateAndCheckError("madeup", SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE, 0, "madeup", evaluateAndCheckError("madeup", SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE, 0, "madeup",
"org.springframework.expression.spel.testresources.Inventor"); "org.springframework.expression.spel.testresources.Inventor");
} }
@Test
public void testPropertyField02_SPR7100() {
evaluate("_name", "Nikola Tesla", String.class);
evaluate("_name_", "Nikola Tesla", String.class);
}
@Test @Test
public void testRogueTrailingDotCausesNPE_SPR6866() { public void testRogueTrailingDotCausesNPE_SPR6866() {
@ -408,6 +414,7 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate("'christian'[8]", "n", String.class); evaluate("'christian'[8]", "n", String.class);
} }
@Test @Test
public void testIndexerError() { public void testIndexerError() {
evaluateAndCheckError("new org.springframework.expression.spel.testresources.Inventor().inventions[1]",SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE); evaluateAndCheckError("new org.springframework.expression.spel.testresources.Inventor().inventions[1]",SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);

4
org.springframework.expression/src/test/java/org/springframework/expression/spel/testresources/Inventor.java

@ -10,6 +10,8 @@ import java.util.Map;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class Inventor { public class Inventor {
private String name; private String name;
public String _name;
public String _name_;
public String publicName; public String publicName;
private PlaceOfBirth placeOfBirth; private PlaceOfBirth placeOfBirth;
private Date birthdate; private Date birthdate;
@ -36,6 +38,8 @@ public class Inventor {
public Inventor(String name, Date birthdate, String nationality) { public Inventor(String name, Date birthdate, String nationality) {
this.name = name; this.name = name;
this._name = name;
this._name_ = name;
this.birthdate = birthdate; this.birthdate = birthdate;
this.nationality = nationality; this.nationality = nationality;
this.arrayContainer = new ArrayContainer(); this.arrayContainer = new ArrayContainer();

Loading…
Cancel
Save