Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
17c88107
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
17c88107
编写于
9月 15, 2008
作者:
A
Andy Clement
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removing functionality. Removed expression list support, cannot say (foo();bar()) any more
上级
4d437688
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
10037 addition
and
9728 deletion
+10037
-9728
org.springframework.expression/src/main/java/org/springframework/expression/PropertyAccessor.java
...java/org/springframework/expression/PropertyAccessor.java
+4
-5
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions.g
...ngframework/expression/spel/generated/SpringExpressions.g
+1
-7
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions.tokens
...mework/expression/spel/generated/SpringExpressions.tokens
+54
-54
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressionsLexer.java
...ork/expression/spel/generated/SpringExpressionsLexer.java
+2884
-2803
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressionsParser.java
...rk/expression/spel/generated/SpringExpressionsParser.java
+6933
-6626
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions__.g
...framework/expression/spel/generated/SpringExpressions__.g
+62
-62
org.springframework.expression/src/main/java/org/springframework/expression/spel/reflection/ReflectionUtils.java
...framework/expression/spel/reflection/ReflectionUtils.java
+6
-7
org.springframework.expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java
.../org/springframework/expression/spel/EvaluationTests.java
+35
-63
org.springframework.expression/src/test/java/org/springframework/expression/spel/LiteralTests.java
...ava/org/springframework/expression/spel/LiteralTests.java
+23
-23
org.springframework.expression/src/test/java/org/springframework/expression/spel/ParserErrorMessagesTests.java
...ngframework/expression/spel/ParserErrorMessagesTests.java
+0
-17
org.springframework.expression/src/test/java/org/springframework/expression/spel/ParsingTests.java
...ava/org/springframework/expression/spel/ParsingTests.java
+12
-40
org.springframework.expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java
...ngframework/expression/spel/VariableAndFunctionTests.java
+23
-21
未找到文件。
org.springframework.expression/src/main/java/org/springframework/expression/PropertyAccessor.java
浏览文件 @
17c88107
...
...
@@ -24,10 +24,10 @@ package org.springframework.expression;
* turn. The only rule that affects the call order is that any naming the target class directly in
* getSpecifiedTargetClasses() will be called first, before the general resolvers.
* <p>
* If the cost of locating the property is expensive, in relation to actually retrieving its value, consider
*
extending CacheablePropertyAccessor rather than directly implementing PropertyAccessor. A CacheablePropertyAccessor
*
enables the discovery (resolution) of the property to be done once and then an object (an executor) returned
*
and cached by the
infrastructure that can be used repeatedly to retrieve the property value.
* If the cost of locating the property is expensive, in relation to actually retrieving its value, consider
extending
*
CacheablePropertyAccessor rather than directly implementing PropertyAccessor. A CacheablePropertyAccessor enables the
*
discovery (resolution) of the property to be done once and then an object (an executor) returned and cached by the
* infrastructure that can be used repeatedly to retrieve the property value.
*
* @author Andy Clement
*/
...
...
@@ -39,7 +39,6 @@ public interface PropertyAccessor {
*
* @return an array of classes that this resolver is suitable for (or null if a general resolver)
*/
@SuppressWarnings
(
"unchecked"
)
public
Class
[]
getSpecificTargetClasses
();
/**
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions.g
浏览文件 @
17c88107
...
...
@@ -59,10 +59,6 @@ tokens {
}
expr: expression EOF!;
exprList
: LPAREN expression (SEMI expression)+ (SEMIRPAREN | RPAREN)
-> ^(EXPRESSIONLIST expression+);
SEMIRPAREN : ';)'; // recoveryrelated: allows us to cope with a rogue superfluous semicolon before the rparen in an expression list
...
...
@@ -102,8 +98,7 @@ primaryExpression
startNode
:
(LPAREN expression SEMI) => exprList
| parenExpr
parenExpr
| methodOrProperty
| functionOrVar
| localFunctionOrVar
...
...
@@ -135,7 +130,6 @@ dottedNode
| selection
| firstSelection
| lastSelection
| exprList
))
;
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions.tokens
浏览文件 @
17c88107
GREATER_THAN_OR_EQUAL=7
9
SELECT_FIRST=5
8
COMMA=5
1
GREATER_THAN_OR_EQUAL=7
8
SELECT_FIRST=5
7
COMMA=5
0
HOLDER=14
GREATER_THAN=7
8
TYPE=
60
GREATER_THAN=7
7
TYPE=
59
EXPRESSIONLIST=4
MINUS=4
1
MINUS=4
0
MAP_ENTRY=25
SELECT_LAST=5
9
SELECT_LAST=5
8
NUMBER=29
LESS_THAN=7
6
BANG=4
6
LESS_THAN=7
5
BANG=4
5
ARGLIST=11
FALSE=
70
FALSE=
69
METHOD=26
PROPERTY_OR_FIELD=9
LBRACKET=53
MOD=44
LBRACKET=52
INDEXER=10
MOD=43
CONSTRUCTOR_ARRAY=15
FUNCTIONREF=17
NULL_LITERAL=6
6
NULL_LITERAL=6
5
NAMED_ARGUMENT=16
OR=3
8
PIPE=6
2
DOT=4
7
RCURLY=5
6
OR=3
7
PIPE=6
1
DOT=4
6
RCURLY=5
5
EXPRESSION=6
AND=3
9
LCURLY=6
3
AND=3
8
LCURLY=6
2
DATE_LITERAL=13
REAL_TYPE_SUFFIX=89
STRING_LITERAL=6
4
SELECT=5
7
STRING_LITERAL=6
3
SELECT=5
6
QUALIFIED_IDENTIFIER=7
RBRACKET=5
4
RBRACKET=5
3
SUBTRACT=28
ASSIGN=3
4
BETWEEN=8
2
RPAREN=3
3
ASSIGN=3
1
BETWEEN=8
1
RPAREN=3
6
SIGN=90
LPAREN=3
0
HEX_DIGIT=7
3
PLUS=
40
LPAREN=3
5
HEX_DIGIT=7
2
PLUS=
39
LIST_INITIALIZER=21
APOS=84
INTEGER_LITERAL=5
AT=5
2
ID=4
9
NOT_EQUAL=7
5
AT=5
1
ID=4
8
NOT_EQUAL=7
4
RANGE=19
POWER=4
5
POWER=4
4
TYPEREF=18
DECIMAL_DIGIT=7
1
DECIMAL_DIGIT=7
0
WS=86
IS=8
1
DOLLAR=
50
LESS_THAN_OR_EQUAL=7
7
SEMIRPAREN=3
2
DQ_STRING_LITERAL=6
5
HEXADECIMAL_INTEGER_LITERAL=6
7
IS=8
0
DOLLAR=
49
LESS_THAN_OR_EQUAL=7
6
SEMIRPAREN=3
0
DQ_STRING_LITERAL=6
4
HEXADECIMAL_INTEGER_LITERAL=6
6
MAP_INITIALIZER=22
LAMBDA=6
1
LAMBDA=6
0
LOCALFUNC=24
IN=80
IN=79
SEMI=83
CONSTRUCTOR=12
SEMI=31
INTEGER_TYPE_SUFFIX=72
EQUAL=74
MATCHES=83
INTEGER_TYPE_SUFFIX=71
EQUAL=73
MATCHES=82
DOT_ESCAPED=85
UPTO=87
QMARK=3
6
QMARK=3
3
REFERENCE=8
PROJECT=5
5
DEFAULT=3
5
COLON=3
7
DIV=4
3
PROJECT=5
4
DEFAULT=3
2
COLON=3
4
DIV=4
2
LOCALVAR=23
STAR=4
2
REAL_LITERAL=6
8
STAR=4
1
REAL_LITERAL=6
7
VARIABLEREF=20
EXPONENT_PART=88
TRUE=6
9
TRUE=6
8
ADD=27
POUND=4
8
POUND=4
7
'date'=92
'new'=91
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressionsLexer.java
浏览文件 @
17c88107
此差异已折叠。
点击以展开。
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressionsParser.java
浏览文件 @
17c88107
此差异已折叠。
点击以展开。
org.springframework.expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions__.g
浏览文件 @
17c88107
此差异已折叠。
点击以展开。
org.springframework.expression/src/main/java/org/springframework/expression/spel/reflection/ReflectionUtils.java
浏览文件 @
17c88107
...
...
@@ -182,7 +182,6 @@ public class ReflectionUtils {
* match an expected type
* @return a MatchInfo object indicating what kind of match it was or null if it was not a match
*/
@SuppressWarnings
(
"unchecked"
)
private
static
ArgumentsMatchInfo
compareArguments
(
Class
[]
expectedArgTypes
,
Class
[]
suppliedArgTypes
,
TypeConverter
typeConverter
,
boolean
conversionAllowed
)
{
ArgsMatchKind
match
=
ArgsMatchKind
.
EXACT
;
...
...
@@ -230,7 +229,6 @@ public class ReflectionUtils {
* match an expected type
* @return a MatchInfo object indicating what kind of match it was or null if it was not a match
*/
@SuppressWarnings
(
"unchecked"
)
private
static
ArgumentsMatchInfo
compareArgumentsVarargs
(
Class
[]
expectedArgTypes
,
Class
[]
suppliedArgTypes
,
TypeConverter
typeConverter
,
boolean
conversionAllowed
)
{
ArgsMatchKind
match
=
ArgsMatchKind
.
EXACT
;
...
...
@@ -484,9 +482,9 @@ public class ReflectionUtils {
}
else
{
targetType
=
parameterTypes
[
i
];
}
if
(
converter
==
null
)
{
throw
new
SpelException
(
SpelMessages
.
PROBLEM_DURING_TYPE_CONVERSION
,
"No converter available to convert '"
+
arguments
[
i
]
+
" to type '"
+
targetType
+
"'"
);
if
(
converter
==
null
)
{
throw
new
SpelException
(
SpelMessages
.
PROBLEM_DURING_TYPE_CONVERSION
,
"No converter available to convert '"
+
arguments
[
i
]
+
" to type '"
+
targetType
+
"'"
);
}
try
{
if
(
arguments
[
i
]
!=
null
&&
arguments
[
i
].
getClass
()
!=
targetType
)
{
...
...
@@ -495,8 +493,9 @@ public class ReflectionUtils {
}
catch
(
EvaluationException
e
)
{
// allows for another type converter throwing a different kind of EvaluationException
if
(!(
e
instanceof
SpelException
))
{
throw
new
SpelException
(
e
,
SpelMessages
.
PROBLEM_DURING_TYPE_CONVERSION
,
"Converter failed to convert '"
+
arguments
[
i
].
getClass
().
getName
()
+
"' to type '"
+
targetType
+
"'"
);
throw
new
SpelException
(
e
,
SpelMessages
.
PROBLEM_DURING_TYPE_CONVERSION
,
"Converter failed to convert '"
+
arguments
[
i
].
getClass
().
getName
()
+
"' to type '"
+
targetType
+
"'"
);
}
throw
e
;
}
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java
浏览文件 @
17c88107
...
...
@@ -180,19 +180,11 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate
(
"#{1:'January', 2:'February', 3:'March'}.get(2)"
,
"February"
,
String
.
class
);
}
public
void
testInlineMapCreation06
()
{
evaluate
(
"(#pos=3;#{1:'January', 2:'February', 3:'March'}[#pos])"
,
"March"
,
String
.
class
);
}
// set construction
public
void
testSetConstruction01
()
{
evaluate
(
"new HashSet().addAll({'a','b','c'})"
,
"true"
,
Boolean
.
class
);
}
public
void
testSets01
()
{
evaluate
(
"(#var=new HashSet();#var.addAll({'a','b','c'});#var[1])"
,
"c"
,
String
.
class
);
}
// constructors
public
void
testConstructorInvocation01
()
{
evaluate
(
"new String('hello')"
,
"hello"
,
String
.
class
);
...
...
@@ -323,19 +315,6 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate
(
"#var1='value1'"
,
"value1"
,
String
.
class
);
}
public
void
testAssignmentToVariables02
()
{
evaluate
(
"(#var1='value1';#var1)"
,
"value1"
,
String
.
class
,
true
);
}
// Property setting
public
void
testAssignmentToProperty01
()
{
evaluate
(
"placeOfBirth.city='SmilJan'"
,
"SmilJan"
,
String
.
class
);
evaluate
(
"(#oldPOB = placeOfBirth.city;placeOfBirth.city='FairOak';'From ' + #oldPOB + ' to ' + placeOfBirth.city)"
,
"From SmilJan to FairOak"
,
String
.
class
);
evaluate
(
"placeOfBirth.city='SmilJan'"
,
"SmilJan"
,
String
.
class
);
}
// Ternary operator
public
void
testTernaryOperator01
()
{
evaluate
(
"{1}.#isEven(#this[0]) == 'y'?'it is even':'it is odd'"
,
"it is odd"
,
String
.
class
);
...
...
@@ -389,10 +368,6 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate
(
"@(apple).color.getRGB() == T(java.awt.Color).green.getRGB()"
,
"true"
,
Boolean
.
class
);
}
public
void
testReferences06b
()
{
evaluate
(
"(#t='Color';@(apple).color.getRGB() == T(java.awt.Color).green.getRGB())"
,
"true"
,
Boolean
.
class
);
}
public
void
testReferences07
()
{
evaluate
(
"@(apple).color.getRGB().equals(T(java.awt.Color).green.getRGB())"
,
"true"
,
Boolean
.
class
);
}
...
...
@@ -424,49 +399,46 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate
(
"{|| true }"
,
"{|| true }"
,
Lambda
.
class
);
}
public
void
testLambdaNoArgsReferenced
()
{
evaluate
(
"(#fn={|| false };#fn)"
,
"{|| false }"
,
Lambda
.
class
,
true
);
}
public
void
testLambda01
()
{
evaluate
(
"{|x,y| $x > $y ? $x : $y }"
,
"{|x,y| ($x > $y) ? $x : $y }"
,
org
.
springframework
.
expression
.
spel
.
ast
.
Lambda
.
class
);
}
public
void
testLambda02
()
{
evaluate
(
"(#max={|x,y| $x > $y ? $x : $y };true)"
,
"true"
,
Boolean
.
class
);
}
public
void
testLambdaMax
()
{
evaluate
(
"(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))"
,
"25"
,
Integer
.
class
);
}
public
void
testLambdaFactorial01
()
{
evaluate
(
"(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))"
,
"120"
,
Integer
.
class
);
}
public
void
testLambdaFactorial02
()
{
evaluate
(
"(#fact = {|n| $n <= 1 ? 1 : #fact($n-1) * $n }; #fact(5))"
,
"120"
,
Integer
.
class
);
}
public
void
testLambdaAlphabet01
()
{
evaluate
(
"(#alpha = {|l,s| $l>'z'?$s:#alpha($l+1,$s+$l)};#alphabet={||#alpha('a','')}; #alphabet())"
,
"abcdefghijklmnopqrstuvwxyz"
,
String
.
class
);
}
public
void
testLambdaAlphabet02
()
{
evaluate
(
"(#alphabet = {|l,s| $l>'z'?$s:#alphabet($l+1,$s+$l)};#alphabet('a',''))"
,
"abcdefghijklmnopqrstuvwxyz"
,
String
.
class
);
}
public
void
testLambdaDelegation01
()
{
evaluate
(
"(#sqrt={|n| T(Math).sqrt($n)};#delegate={|f,n| $f($n)};#delegate(#sqrt,4))"
,
"2.0"
,
Double
.
class
);
}
public
void
testVariableReferences
()
{
evaluate
(
"(#answer=42;#answer)"
,
"42"
,
Integer
.
class
,
true
);
evaluate
(
"($answer=42;$answer)"
,
"42"
,
Integer
.
class
,
true
);
}
//
// public void testLambda02() {
// evaluate("(#max={|x,y| $x > $y ? $x : $y };true)", "true", Boolean.class);
// }
//
// public void testLambdaMax() {
// evaluate("(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))", "25", Integer.class);
// }
//
// public void testLambdaFactorial01() {
// evaluate("(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))", "120", Integer.class);
// }
//
// public void testLambdaFactorial02() {
// evaluate("(#fact = {|n| $n <= 1 ? 1 : #fact($n-1) * $n }; #fact(5))", "120", Integer.class);
// }
//
// public void testLambdaAlphabet01() {
// evaluate("(#alpha = {|l,s| $l>'z'?$s:#alpha($l+1,$s+$l)};#alphabet={||#alpha('a','')}; #alphabet())",
// "abcdefghijklmnopqrstuvwxyz", String.class);
// }
//
// public void testLambdaAlphabet02() {
// evaluate("(#alphabet = {|l,s| $l>'z'?$s:#alphabet($l+1,$s+$l)};#alphabet('a',''))",
// "abcdefghijklmnopqrstuvwxyz", String.class);
// }
//
// public void testLambdaDelegation01() {
// evaluate("(#sqrt={|n| T(Math).sqrt($n)};#delegate={|f,n| $f($n)};#delegate(#sqrt,4))", "2.0", Double.class);
// }
//
// public void testVariableReferences() {
// evaluate("(#answer=42;#answer)", "42", Integer.class, true);
// evaluate("($answer=42;$answer)", "42", Integer.class, true);
// }
// type references
public
void
testTypeReferences01
()
{
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/LiteralTests.java
浏览文件 @
17c88107
...
...
@@ -90,27 +90,27 @@ public class LiteralTests extends ExpressionTestCase {
}
public
void
testLiteralReal01_CreatingDoubles
()
{
evaluate
(
"1.25"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25d"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99d"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141d"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25D"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99D"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141D"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25d"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99d"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141d"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25D"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99D"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141D"
,
-
3.141d
,
Double
.
class
);
}
public
void
testLiteralReal02_CreatingFloats
()
{
// For now, everything becomes a double...
evaluate
(
"1.25f"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99f"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141f"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25F"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99F"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141F"
,
-
3.141d
,
Double
.
class
);
}
evaluate
(
"1.25f"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99f"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141f"
,
-
3.141d
,
Double
.
class
);
evaluate
(
"1.25F"
,
1.25d
,
Double
.
class
);
evaluate
(
"2.99F"
,
2.99d
,
Double
.
class
);
evaluate
(
"-3.141F"
,
-
3.141d
,
Double
.
class
);
}
public
void
testLiteralReal03_UsingExponents
()
{
evaluate
(
"6.0221415E+23"
,
"6.0221415E23"
,
Double
.
class
);
evaluate
(
"6.0221415e+23"
,
"6.0221415E23"
,
Double
.
class
);
...
...
@@ -121,10 +121,10 @@ public class LiteralTests extends ExpressionTestCase {
}
public
void
testLiteralReal04_BadExpressions
()
{
parseAndCheckError
(
"6.1e23e22"
,
SpelMessages
.
PARSE_PROBLEM
,
6
,
"mismatched input 'e22' expecting EOF"
);
parseAndCheckError
(
"6.1f23e22"
,
SpelMessages
.
PARSE_PROBLEM
,
4
,
"mismatched input '23e22' expecting EOF"
);
parseAndCheckError
(
"6.1e23e22"
,
SpelMessages
.
PARSE_PROBLEM
,
6
,
"mismatched input 'e22' expecting EOF"
);
parseAndCheckError
(
"6.1f23e22"
,
SpelMessages
.
PARSE_PROBLEM
,
4
,
"mismatched input '23e22' expecting EOF"
);
}
public
void
testLiteralNull01
()
{
evaluate
(
"null"
,
null
,
null
);
}
...
...
@@ -156,10 +156,10 @@ public class LiteralTests extends ExpressionTestCase {
// int year convertable from number to string
parseAndCheckError
(
"date(2008,'yyyy').getTime()>0"
,
SpelMessages
.
PARSE_PROBLEM
);
}
public
void
testConversions
()
{
// getting the expression type to be what we want - either:
evaluate
(
"
(#foo=37;#foo.byteValue())"
,(
byte
)
37
,
Byte
.
class
);
// calling byteValue() on Integer.class
evaluateAndAskForReturnType
(
"
(#foo=37;#foo)"
,(
byte
)
37
,
Byte
.
class
);
// relying on registered type converters
evaluate
(
"
new Integer(37).byteValue()"
,
(
byte
)
37
,
Byte
.
class
);
// calling byteValue() on Integer.class
evaluateAndAskForReturnType
(
"
new Integer(37)"
,
(
byte
)
37
,
Byte
.
class
);
// relying on registered type converters
}
}
org.springframework.expression/src/test/java/org/springframework/expression/spel/ParserErrorMessagesTests.java
浏览文件 @
17c88107
...
...
@@ -35,12 +35,6 @@ public class ParserErrorMessagesTests extends ExpressionTestCase {
parseAndCheckError
(
"0xB0BG"
,
SpelMessages
.
PARSE_PROBLEM
,
5
,
"mismatched input 'G' expecting EOF"
);
}
public
void
testBrokenExpression03
()
{
// too many closing brackets
parseAndCheckError
(
"((3;4;)+(5;6;)))"
,
SpelMessages
.
PARSE_PROBLEM
,
15
,
"mismatched input ')' expecting EOF"
);
evaluate
(
"((3;4;)+(5;6;))"
,
10
/* 4+6 */
,
Integer
.
class
);
}
public
void
testBrokenExpression04
()
{
// missing right operand
parseAndCheckError
(
"true or "
,
SpelMessages
.
PARSE_PROBLEM
,
-
1
,
"no viable alternative at input '<EOF>'"
);
// POOR
...
...
@@ -51,21 +45,10 @@ public class ParserErrorMessagesTests extends ExpressionTestCase {
parseAndCheckError
(
"1 + "
,
SpelMessages
.
PARSE_PROBLEM
,
-
1
,
"no viable alternative at input '<EOF>'"
);
// POOR
}
public
void
testBrokenExpression06
()
{
// expression list missing surrounding parentheses
parseAndCheckError
(
"1;2;3"
,
SpelMessages
.
PARSE_PROBLEM
,
1
,
"mismatched input ';' expecting EOF"
);
// POOR
evaluate
(
"(1;2;3)"
,
3
,
Integer
.
class
);
}
public
void
testBrokenExpression07
()
{
// T() can only take an identifier (possibly qualified), not a literal
// message ought to say identifier rather than ID
parseAndCheckError
(
"null is T('a')"
,
SpelMessages
.
PARSE_PROBLEM
,
10
,
"mismatched input ''a'' expecting ID"
);
// POOR
}
public
void
testExpressionLists02a
()
{
// either missing semi or rogue 5. RPAREN should at least be ')', and why doesn't it give the other possibles?
parseAndCheckError
(
"( (3;4)5)"
,
SpelMessages
.
PARSE_PROBLEM
,
7
,
"mismatched input '5' expecting RPAREN"
);
// POOR
}
}
org.springframework.expression/src/test/java/org/springframework/expression/spel/ParsingTests.java
浏览文件 @
17c88107
...
...
@@ -22,7 +22,7 @@ import org.springframework.expression.ParseException;
/**
* Parse some expressions and check we get the AST we expect. Rather than inspecting each node in the AST, we ask it to
* write itself to a string form and check that is as expected.
*
*
* @author Andy Clement
*/
public
class
ParsingTests
extends
TestCase
{
...
...
@@ -360,14 +360,15 @@ public class ParsingTests extends TestCase {
parseCheck
(
"{|x,y| $x > $y ? $x : $y }"
,
"{|x,y| ($x > $y) ? $x : $y }"
);
}
public
void
testLambdaMax
()
{
parseCheck
(
"(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))"
,
"(#max={|x,y| ($x > $y) ? $x : $y };#max(5,25))"
);
}
public
void
testLambdaFactorial
()
{
parseCheck
(
"(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))"
,
"(#fact={|n| ($n <= 1) ? 1 : ($n * #fact(($n - 1))) };#fact(5))"
);
}
// 120
//
// public void testLambdaMax() {
// parseCheck("(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))", "(#max={|x,y| ($x > $y) ? $x : $y };#max(5,25))");
// }
//
// public void testLambdaFactorial() {
// parseCheck("(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))",
// "(#fact={|n| ($n <= 1) ? 1 : ($n * #fact(($n - 1))) };#fact(5))");
// } // 120
// Type references
public
void
testTypeReferences01
()
{
...
...
@@ -378,39 +379,10 @@ public class ParsingTests extends TestCase {
parseCheck
(
"T(String)"
);
}
// Nesting expressions and expression lists
public
void
testExpressionLists01
()
{
parseCheck
(
"(3;4;5)"
);
}
public
void
testExpressionLists02
()
{
parseCheck
(
"( (3;4);5)"
,
"((3;4);5)"
);
}
public
void
testExpressionLists03
()
{
parseCheck
(
"(3;(4;5))"
);
}
public
void
testExpressionLists04
()
{
parseCheck
(
"((3;4;5))"
,
"(3;4;5)"
);
}
public
void
testExpressionLists05
()
{
parseCheck
(
"((3;4)+(5;6))"
,
"((3;4) + (5;6))"
);
}
public
void
testExpressionLists06
()
{
parseCheck
(
"((3;4;)+(5;6))"
,
"((3;4) + (5;6))"
);
}
public
void
testExpressionLists07
()
{
parseCheck
(
"((3;4;)+(5;6;))"
,
"((3;4) + (5;6))"
);
}
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the same
* as the original expression.
*
*
* @param expression the expression to parse *and* the expected value of the string form of the resultant AST
*/
public
void
parseCheck
(
String
expression
)
{
...
...
@@ -420,7 +392,7 @@ public class ParsingTests extends TestCase {
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
* expected value.
*
*
* @param expression the expression to parse
* @param expectedStringFormOfAST the expected string form of the AST
*/
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java
浏览文件 @
17c88107
...
...
@@ -26,7 +26,6 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
public
void
testVariableAccess
()
{
evaluate
(
"#answer"
,
"42"
,
Integer
.
class
,
SHOULD_BE_WRITABLE
);
evaluate
(
"(#i=5;#i)"
,
5
,
Integer
.
class
,
SHOULD_BE_WRITABLE
);
evaluate
(
"#answer / 2"
,
21
,
Integer
.
class
,
SHOULD_NOT_BE_WRITABLE
);
}
...
...
@@ -40,40 +39,43 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
evaluate
(
"#reverseString('hello')"
,
"olleh"
,
String
.
class
);
evaluate
(
"#reverseString(37)"
,
"73"
,
String
.
class
);
// requires type conversion of 37 to '37'
}
public
void
testCallVarargsFunction
()
{
evaluate
(
"#varargsFunctionReverseStringsAndMerge('a','b','c')"
,
"cba"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('a')"
,
"a"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge()"
,
""
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('b',25)"
,
"25b"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge(25)"
,
"25"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(1,'a','b','c')"
,
"1cba"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(2,'a')"
,
"2a"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(3)"
,
"3"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(4,'b',25)"
,
"425b"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(5,25)"
,
"525"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('a','b','c')"
,
"cba"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('a')"
,
"a"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge()"
,
""
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('b',25)"
,
"25b"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge(25)"
,
"25"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(1,'a','b','c')"
,
"1cba"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(2,'a')"
,
"2a"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(3)"
,
"3"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(4,'b',25)"
,
"425b"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(5,25)"
,
"525"
,
String
.
class
);
}
public
void
testCallingFunctionsIncorrectly
()
{
evaluateAndCheckError
(
"#varargsFunctionReverseStringsAndMerge(new StringBuilder())"
,
SpelMessages
.
TYPE_CONVERSION_ERROR
);
evaluateAndCheckError
(
"#varargsFunctionReverseStringsAndMerge(new StringBuilder())"
,
SpelMessages
.
TYPE_CONVERSION_ERROR
);
}
public
void
testCallingIllegalFunctions
()
throws
Exception
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
StandardEvaluationContext
ctx
=
new
StandardEvaluationContext
();
ctx
.
setVariable
(
"notStatic"
,
this
.
getClass
().
getMethod
(
"nonStatic"
));
ctx
.
setVariable
(
"notStatic"
,
this
.
getClass
().
getMethod
(
"nonStatic"
));
try
{
@SuppressWarnings
(
"unused"
)
Object
v
=
parser
.
parseExpression
(
"#notStatic()"
).
getValue
(
ctx
);
fail
(
"Should have failed with exception - cannot call non static method that way"
);
}
catch
(
SpelException
se
)
{
if
(
se
.
getMessageUnformatted
()
!=
SpelMessages
.
FUNCTION_MUST_BE_STATIC
)
{
if
(
se
.
getMessageUnformatted
()
!=
SpelMessages
.
FUNCTION_MUST_BE_STATIC
)
{
se
.
printStackTrace
();
fail
(
"Should have failed a message about the function needing to be static, not: "
+
se
.
getMessageUnformatted
());
fail
(
"Should have failed a message about the function needing to be static, not: "
+
se
.
getMessageUnformatted
());
}
}
}
public
void
nonStatic
()
{}
public
void
nonStatic
()
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录