Support [] array ref syntax in SpEL T() construct
Prior to this change, SpEL would not allow the use of '[]' in
expressions like the following:
T(foo.Bar[])
This commit updates TypeReference and InternalSpelExpressionParser to
support this syntax, avoiding the need for workarounds like:
new foo.bar[0].class
Issue: SPR-9203
This commit is contained in:
committed by
Chris Beams
parent
0e8f5d877a
commit
916e9d6efa
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -1175,6 +1175,35 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
Expression expression = null;
|
||||
Object result = null;
|
||||
|
||||
expression = parser.parseExpression("new java.lang.Long[0].class");
|
||||
result = expression.getValue(context, "");
|
||||
assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());
|
||||
|
||||
expression = parser.parseExpression("T(java.lang.Long[])");
|
||||
result = expression.getValue(context, "");
|
||||
assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());
|
||||
|
||||
expression = parser.parseExpression("T(java.lang.String[][][])");
|
||||
result = expression.getValue(context, "");
|
||||
assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
|
||||
assertEquals("T(java.lang.String[][][])",((SpelExpression)expression).toStringAST());
|
||||
|
||||
expression = parser.parseExpression("new int[0].class");
|
||||
result = expression.getValue(context, "");
|
||||
assertEquals("Equal assertion failed: ", "class [I", result.toString());
|
||||
|
||||
expression = parser.parseExpression("T(int[][])");
|
||||
result = expression.getValue(context, "");
|
||||
assertEquals("Equal assertion failed: ", "class [[I", result.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user