Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
14eba503
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
14eba503
编写于
11月 24, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent ExpressionException-style quoting of expression string and position
Issue: SPR-14942
上级
b10045dc
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
151 addition
and
143 deletion
+151
-143
spring-expression/src/main/java/org/springframework/expression/EvaluationException.java
...a/org/springframework/expression/EvaluationException.java
+21
-16
spring-expression/src/main/java/org/springframework/expression/ExpressionException.java
...a/org/springframework/expression/ExpressionException.java
+29
-26
spring-expression/src/main/java/org/springframework/expression/ParseException.java
...n/java/org/springframework/expression/ParseException.java
+4
-4
spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java
...ingframework/expression/spel/SpelEvaluationException.java
+13
-27
spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java
...java/org/springframework/expression/spel/SpelMessage.java
+31
-12
spring-expression/src/main/java/org/springframework/expression/spel/SpelParseException.java
...g/springframework/expression/spel/SpelParseException.java
+8
-18
spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java
...a/org/springframework/expression/spel/SpelReproTests.java
+10
-10
spring-expression/src/test/java/org/springframework/expression/spel/standard/SpelParserTests.java
...ngframework/expression/spel/standard/SpelParserTests.java
+35
-30
未找到文件。
spring-expression/src/main/java/org/springframework/expression/EvaluationException.java
浏览文件 @
14eba503
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -26,7 +26,24 @@ package org.springframework.expression;
public
class
EvaluationException
extends
ExpressionException
{
/**
* Creates a new expression evaluation exception.
* Create a new expression evaluation exception.
* @param message description of the problem that occurred
*/
public
EvaluationException
(
String
message
)
{
super
(
message
);
}
/**
* Create a new expression evaluation exception.
* @param message description of the problem that occurred
* @param cause the underlying cause of this exception
*/
public
EvaluationException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
/**
* Create a new expression evaluation exception.
* @param position the position in the expression where the problem occurred
* @param message description of the problem that occurred
*/
...
...
@@ -35,7 +52,7 @@ public class EvaluationException extends ExpressionException {
}
/**
* Create
s
a new expression evaluation exception.
* Create a new expression evaluation exception.
* @param expressionString the expression that could not be evaluated
* @param message description of the problem that occurred
*/
...
...
@@ -44,7 +61,7 @@ public class EvaluationException extends ExpressionException {
}
/**
* Create
s
a new expression evaluation exception.
* Create a new expression evaluation exception.
* @param position the position in the expression where the problem occurred
* @param message description of the problem that occurred
* @param cause the underlying cause of this exception
...
...
@@ -53,16 +70,4 @@ public class EvaluationException extends ExpressionException {
super
(
position
,
message
,
cause
);
}
/**
* Creates a new expression evaluation exception.
* @param message description of the problem that occurred
*/
public
EvaluationException
(
String
message
)
{
super
(
message
);
}
public
EvaluationException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
spring-expression/src/main/java/org/springframework/expression/ExpressionException.java
浏览文件 @
14eba503
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -20,6 +20,7 @@ package org.springframework.expression;
* Super class for exceptions that can occur whilst processing expressions.
*
* @author Andy Clement
* @author Phil Webb
* @since 3.0
*/
@SuppressWarnings
(
"serial"
)
...
...
@@ -27,68 +28,68 @@ public class ExpressionException extends RuntimeException {
protected
String
expressionString
;
protected
int
position
;
// -1 if not known
- but
should be known in all reasonable cases
protected
int
position
;
// -1 if not known
;
should be known in all reasonable cases
/**
* Construct a new expression exception.
* @param expressionString the expression string
* @param message a descriptive message
*/
public
ExpressionException
(
String
expressionString
,
String
message
)
{
public
ExpressionException
(
String
message
)
{
super
(
message
);
this
.
position
=
-
1
;
this
.
expressionString
=
expressionString
;
}
/**
* Construct a new expression exception.
* @param expressionString the expression string
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
* @param cause the underlying cause of this exception
*/
public
ExpressionException
(
String
expressionString
,
int
position
,
String
message
)
{
super
(
message
);
this
.
position
=
position
;
this
.
expressionString
=
expressionString
;
public
ExpressionException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
/**
* Construct a new expression exception.
* @param
position the position in the expression string where the problem occurred
* @param
expressionString the expression string
* @param message a descriptive message
*/
public
ExpressionException
(
int
position
,
String
message
)
{
public
ExpressionException
(
String
expressionString
,
String
message
)
{
super
(
message
);
this
.
position
=
position
;
this
.
expressionString
=
expressionString
;
this
.
position
=
-
1
;
}
/**
* Construct a new expression exception.
* @param expressionString the expression string
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
* @param cause the underlying cause of this exception
*/
public
ExpressionException
(
int
position
,
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
public
ExpressionException
(
String
expressionString
,
int
position
,
String
message
)
{
super
(
message
);
this
.
expressionString
=
expressionString
;
this
.
position
=
position
;
}
/**
* Construct a new expression exception.
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
*/
public
ExpressionException
(
String
message
)
{
public
ExpressionException
(
int
position
,
String
message
)
{
super
(
message
);
this
.
position
=
position
;
}
/**
* Construct a new expression exception.
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
* @param cause the underlying cause of this exception
*/
public
ExpressionException
(
String
message
,
Throwable
cause
)
{
public
ExpressionException
(
int
position
,
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
position
=
position
;
}
...
...
@@ -107,8 +108,9 @@ public class ExpressionException extends RuntimeException {
}
/**
* Return the exception message. Since Spring 4.0 this method returns the
* same result as {@link #toDetailedString()}.
* Return the exception message.
* As of Spring 4.0, this method returns the same result as {@link #toDetailedString()}.
* @see #getSimpleMessage()
* @see java.lang.Throwable#getMessage()
*/
@Override
...
...
@@ -123,11 +125,11 @@ public class ExpressionException extends RuntimeException {
public
String
toDetailedString
()
{
if
(
this
.
expressionString
!=
null
)
{
StringBuilder
output
=
new
StringBuilder
();
output
.
append
(
"Expression
'
"
);
output
.
append
(
"Expression
[
"
);
output
.
append
(
this
.
expressionString
);
output
.
append
(
"
'
"
);
if
(
this
.
position
!=
-
1
)
{
output
.
append
(
" @
"
);
output
.
append
(
"
]
"
);
if
(
this
.
position
>=
0
)
{
output
.
append
(
" @"
);
output
.
append
(
this
.
position
);
}
output
.
append
(
": "
);
...
...
@@ -142,6 +144,7 @@ public class ExpressionException extends RuntimeException {
/**
* Return the exception simple message without including the expression
* that caused the failure.
* @since 4.0
*/
public
String
getSimpleMessage
()
{
return
super
.
getMessage
();
...
...
spring-expression/src/main/java/org/springframework/expression/ParseException.java
浏览文件 @
14eba503
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -26,7 +26,7 @@ package org.springframework.expression;
public
class
ParseException
extends
ExpressionException
{
/**
* Create
s
a new expression parsing exception.
* Create a new expression parsing exception.
* @param expressionString the expression string that could not be parsed
* @param position the position in the expression string where the problem occurred
* @param message description of the problem that occurred
...
...
@@ -36,7 +36,7 @@ public class ParseException extends ExpressionException {
}
/**
* Create
s
a new expression parsing exception.
* Create a new expression parsing exception.
* @param position the position in the expression string where the problem occurred
* @param message description of the problem that occurred
* @param cause the underlying cause of this exception
...
...
@@ -46,7 +46,7 @@ public class ParseException extends ExpressionException {
}
/**
* Create
s
a new expression parsing exception.
* Create a new expression parsing exception.
* @param position the position in the expression string where the problem occurred
* @param message description of the problem that occurred
*/
...
...
spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java
浏览文件 @
14eba503
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.expression.spel
;
import
org.springframework.expression.EvaluationException
;
...
...
@@ -23,6 +24,7 @@ import org.springframework.expression.EvaluationException;
* message. See {@link SpelMessage} for the list of all possible messages that can occur.
*
* @author Andy Clement
* @author Juergen Hoeller
* @since 3.0
*/
@SuppressWarnings
(
"serial"
)
...
...
@@ -34,62 +36,46 @@ public class SpelEvaluationException extends EvaluationException {
public
SpelEvaluationException
(
SpelMessage
message
,
Object
...
inserts
)
{
super
(
message
.
formatMessage
(
0
,
inserts
));
// TODO poor position information, can the callers not really supply something?
super
(
message
.
formatMessage
(
inserts
));
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
public
SpelEvaluationException
(
int
position
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
position
,
message
.
formatMessage
(
position
,
inserts
));
super
(
position
,
message
.
formatMessage
(
inserts
));
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
public
SpelEvaluationException
(
int
position
,
Throwable
cause
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
position
,
message
.
formatMessage
(
position
,
inserts
),
cause
);
public
SpelEvaluationException
(
int
position
,
Throwable
cause
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
position
,
message
.
formatMessage
(
inserts
),
cause
);
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
public
SpelEvaluationException
(
Throwable
cause
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
message
.
formatMessage
(
0
,
inserts
),
cause
);
super
(
message
.
formatMessage
(
inserts
),
cause
);
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
/**
*
@return a formatted message with inserts applied
*
Set the position in the related expression which gave rise to this exception.
*/
@Override
public
String
getMessage
()
{
if
(
this
.
message
!=
null
)
{
return
this
.
message
.
formatMessage
(
this
.
position
,
this
.
inserts
);
}
else
{
return
super
.
getMessage
();
}
public
void
setPosition
(
int
position
)
{
this
.
position
=
position
;
}
/**
*
@return the message code
*
Return the message code.
*/
public
SpelMessage
getMessageCode
()
{
return
this
.
message
;
}
/**
* Set the position in the related expression which gave rise to this exception.
*
* @param position the position in the expression that gave rise to the exception
*/
public
void
setPosition
(
int
position
)
{
this
.
position
=
position
;
}
/**
* @return the message inserts
* Return the message inserts.
*/
public
Object
[]
getInserts
()
{
return
this
.
inserts
;
...
...
spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java
浏览文件 @
14eba503
...
...
@@ -24,16 +24,13 @@ import java.text.MessageFormat;
* expect particular code numbers rather than particular text, enabling the message text
* to more easily be modified and the tests to run successfully in different locales.
*
* <p>When a message is formatted, it will have this kind of form
* <p>When a message is formatted, it will have this kind of form, capturing the prefix
* and the error kind:
*
* <pre class="code">
* EL1004E: (pos 34): Type cannot be found 'String'
* </pre>
*
* The prefix captures the code and the error kind, whilst the position is included
* if it is known.
* <pre class="code">EL1004E: Type cannot be found 'String'</pre>
*
* @author Andy Clement
* @author Juergen Hoeller
* @since 3.0
*/
public
enum
SpelMessage
{
...
...
@@ -175,7 +172,7 @@ public enum SpelMessage {
"Cannot find terminating \" for string"
),
NON_TERMINATING_QUOTED_STRING
(
Kind
.
ERROR
,
1046
,
"Cannot find terminating ' for string"
),
"Cannot find terminating '
'
for string"
),
MISSING_LEADING_ZERO_FOR_NUMBER
(
Kind
.
ERROR
,
1047
,
"A real number must be prefixed by zero, it cannot start with just ''.''"
),
...
...
@@ -190,7 +187,7 @@ public enum SpelMessage {
"The arguments '(...)' for the constructor call are missing"
),
RUN_OUT_OF_ARGUMENTS
(
Kind
.
ERROR
,
1051
,
"Unexpected ran out of arguments"
),
"Unexpected
ly
ran out of arguments"
),
UNABLE_TO_GROW_COLLECTION
(
Kind
.
ERROR
,
1052
,
"Unable to grow collection"
),
...
...
@@ -262,20 +259,42 @@ public enum SpelMessage {
private
final
String
message
;
private
SpelMessage
(
Kind
kind
,
int
code
,
String
message
)
{
SpelMessage
(
Kind
kind
,
int
code
,
String
message
)
{
this
.
kind
=
kind
;
this
.
code
=
code
;
this
.
message
=
message
;
}
/**
* Produce a complete message including the prefix and with the inserts
* applied to the message.
* @param inserts the inserts to put into the formatted message
* @return a formatted message
* @since 4.3.5
*/
public
String
formatMessage
(
Object
...
inserts
)
{
StringBuilder
formattedMessage
=
new
StringBuilder
();
formattedMessage
.
append
(
"EL"
).
append
(
this
.
code
);
switch
(
this
.
kind
)
{
case
ERROR:
formattedMessage
.
append
(
"E"
);
break
;
}
formattedMessage
.
append
(
": "
);
formattedMessage
.
append
(
MessageFormat
.
format
(
this
.
message
,
inserts
));
return
formattedMessage
.
toString
();
}
/**
* Produce a complete message including the prefix, the position (if known)
* and with the inserts applied to the message.
* @param pos the position (ignored and not included in the message if less than 0)
* @param inserts the inserts to put into the formatted message
* @return a formatted message
* @deprecated as of Spring 4.3.5, in favor of {@link #formatMessage(Object...)}
*/
@Deprecated
public
String
formatMessage
(
int
pos
,
Object
...
inserts
)
{
StringBuilder
formattedMessage
=
new
StringBuilder
();
formattedMessage
.
append
(
"EL"
).
append
(
this
.
code
);
...
...
@@ -285,7 +304,7 @@ public enum SpelMessage {
break
;
}
formattedMessage
.
append
(
":"
);
if
(
pos
!=
-
1
)
{
if
(
pos
>=
0
)
{
formattedMessage
.
append
(
"(pos "
).
append
(
pos
).
append
(
"): "
);
}
formattedMessage
.
append
(
MessageFormat
.
format
(
this
.
message
,
inserts
));
...
...
@@ -293,6 +312,6 @@ public enum SpelMessage {
}
public
static
enum
Kind
{
INFO
,
WARNING
,
ERROR
}
public
enum
Kind
{
INFO
,
WARNING
,
ERROR
}
}
spring-expression/src/main/java/org/springframework/expression/spel/SpelParseException.java
浏览文件 @
14eba503
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.expression.spel
;
import
org.springframework.expression.ParseException
;
...
...
@@ -23,6 +24,7 @@ import org.springframework.expression.ParseException;
* message. See {@link SpelMessage} for the list of all possible messages that can occur.
*
* @author Andy Clement
* @author Juergen Hoeller
* @since 3.0
*/
@SuppressWarnings
(
"serial"
)
...
...
@@ -34,45 +36,33 @@ public class SpelParseException extends ParseException {
public
SpelParseException
(
String
expressionString
,
int
position
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
expressionString
,
position
,
message
.
formatMessage
(
position
,
inserts
));
this
.
position
=
position
;
super
(
expressionString
,
position
,
message
.
formatMessage
(
inserts
));
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
public
SpelParseException
(
int
position
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
position
,
message
.
formatMessage
(
position
,
inserts
));
this
.
position
=
position
;
super
(
position
,
message
.
formatMessage
(
inserts
));
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
public
SpelParseException
(
int
position
,
Throwable
cause
,
SpelMessage
message
,
Object
...
inserts
)
{
super
(
position
,
message
.
formatMessage
(
position
,
inserts
),
cause
);
this
.
position
=
position
;
super
(
position
,
message
.
formatMessage
(
inserts
),
cause
);
this
.
message
=
message
;
this
.
inserts
=
inserts
;
}
/**
* @return a formatted message with inserts applied
*/
@Override
public
String
getMessage
()
{
return
(
this
.
message
!=
null
?
this
.
message
.
formatMessage
(
this
.
position
,
this
.
inserts
)
:
super
.
getMessage
());
}
/**
* @return the message code
* Return the message code.
*/
public
SpelMessage
getMessageCode
()
{
return
this
.
message
;
}
/**
*
@return the message inserts
*
Return the message inserts.
*/
public
Object
[]
getInserts
()
{
return
this
.
inserts
;
...
...
spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java
浏览文件 @
14eba503
...
...
@@ -1663,15 +1663,15 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
public
void
SPR10146_malformedExpressions
()
throws
Exception
{
doTestSpr10146
(
"/foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
"*foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
"%foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
"<foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
">foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
"&&foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
"||foo"
,
"EL1070E:
(pos 0):
Problem parsing left operand"
);
doTestSpr10146
(
"&foo"
,
"EL1069E:
(pos 0):
missing expected character '&'"
);
doTestSpr10146
(
"|foo"
,
"EL1069E:
(pos 0):
missing expected character '|'"
);
doTestSpr10146
(
"/foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
"*foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
"%foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
"<foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
">foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
"&&foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
"||foo"
,
"EL1070E: Problem parsing left operand"
);
doTestSpr10146
(
"&foo"
,
"EL1069E: missing expected character '&'"
);
doTestSpr10146
(
"|foo"
,
"EL1069E: missing expected character '|'"
);
}
private
void
doTestSpr10146
(
String
expression
,
String
expectedMessage
)
{
...
...
@@ -1702,7 +1702,7 @@ public class SpelReproTests extends AbstractExpressionTests {
@Test
public
void
SPR10328
()
throws
Exception
{
thrown
.
expect
(
SpelParseException
.
class
);
thrown
.
expectMessage
(
"EL1071E:
(pos 2):
A required selection expression has not been specified"
);
thrown
.
expectMessage
(
"EL1071E: A required selection expression has not been specified"
);
Expression
exp
=
parser
.
parseExpression
(
"$[]"
);
exp
.
getValue
(
Arrays
.
asList
(
"foo"
,
"bar"
,
"baz"
));
}
...
...
spring-expression/src/test/java/org/springframework/expression/spel/standard/SpelParserTests.java
浏览文件 @
14eba503
...
...
@@ -19,7 +19,6 @@ package org.springframework.expression.spel.standard;
import
org.junit.Test
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.ExpressionException
;
import
org.springframework.expression.ParseException
;
import
org.springframework.expression.spel.SpelMessage
;
...
...
@@ -33,11 +32,12 @@ import static org.junit.Assert.*;
/**
* @author Andy Clement
* @author Juergen Hoeller
*/
public
class
SpelParserTests
{
@Test
public
void
theMostBasic
()
throws
EvaluationException
,
ParseException
{
public
void
theMostBasic
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"2"
);
assertNotNull
(
expr
);
...
...
@@ -48,7 +48,7 @@ public class SpelParserTests {
}
@Test
public
void
valueType
()
throws
Exception
{
public
void
valueType
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
EvaluationContext
ctx
=
new
StandardEvaluationContext
();
Class
<?>
c
=
parser
.
parseRaw
(
"2"
).
getValueType
();
...
...
@@ -64,7 +64,7 @@ public class SpelParserTests {
}
@Test
public
void
whitespace
()
throws
EvaluationException
,
ParseException
{
public
void
whitespace
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"2 + 3"
);
assertEquals
(
5
,
expr
.
getValue
());
...
...
@@ -77,7 +77,7 @@ public class SpelParserTests {
}
@Test
public
void
arithmeticPlus1
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPlus1
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"2+2"
);
assertNotNull
(
expr
);
...
...
@@ -86,14 +86,14 @@ public class SpelParserTests {
}
@Test
public
void
arithmeticPlus2
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPlus2
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"37+41"
);
assertEquals
(
78
,
expr
.
getValue
());
}
@Test
public
void
arithmeticMultiply1
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticMultiply1
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"2*3"
);
assertNotNull
(
expr
);
...
...
@@ -103,15 +103,14 @@ public class SpelParserTests {
}
@Test
public
void
arithmeticPrecedence1
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPrecedence1
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"2*3+5"
);
assertEquals
(
11
,
expr
.
getValue
());
}
@Test
public
void
generalExpressions
()
throws
Exception
{
public
void
generalExpressions
()
{
try
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
parser
.
parseRaw
(
"new String"
);
...
...
@@ -122,6 +121,7 @@ public class SpelParserTests {
SpelParseException
spe
=
(
SpelParseException
)
ex
;
assertEquals
(
SpelMessage
.
MISSING_CONSTRUCTOR_ARGS
,
spe
.
getMessageCode
());
assertEquals
(
10
,
spe
.
getPosition
());
assertTrue
(
ex
.
getMessage
().
contains
(
ex
.
getExpressionString
()));
}
try
{
...
...
@@ -134,6 +134,7 @@ public class SpelParserTests {
SpelParseException
spe
=
(
SpelParseException
)
ex
;
assertEquals
(
SpelMessage
.
RUN_OUT_OF_ARGUMENTS
,
spe
.
getMessageCode
());
assertEquals
(
10
,
spe
.
getPosition
());
assertTrue
(
ex
.
getMessage
().
contains
(
ex
.
getExpressionString
()));
}
try
{
...
...
@@ -146,6 +147,7 @@ public class SpelParserTests {
SpelParseException
spe
=
(
SpelParseException
)
ex
;
assertEquals
(
SpelMessage
.
RUN_OUT_OF_ARGUMENTS
,
spe
.
getMessageCode
());
assertEquals
(
10
,
spe
.
getPosition
());
assertTrue
(
ex
.
getMessage
().
contains
(
ex
.
getExpressionString
()));
}
try
{
...
...
@@ -158,6 +160,7 @@ public class SpelParserTests {
SpelParseException
spe
=
(
SpelParseException
)
ex
;
assertEquals
(
SpelMessage
.
RUN_OUT_OF_ARGUMENTS
,
spe
.
getMessageCode
());
assertEquals
(
10
,
spe
.
getPosition
());
assertTrue
(
ex
.
getMessage
().
contains
(
ex
.
getExpressionString
()));
}
try
{
...
...
@@ -170,6 +173,7 @@ public class SpelParserTests {
SpelParseException
spe
=
(
SpelParseException
)
ex
;
assertEquals
(
SpelMessage
.
NON_TERMINATING_DOUBLE_QUOTED_STRING
,
spe
.
getMessageCode
());
assertEquals
(
0
,
spe
.
getPosition
());
assertTrue
(
ex
.
getMessage
().
contains
(
ex
.
getExpressionString
()));
}
try
{
...
...
@@ -182,43 +186,44 @@ public class SpelParserTests {
SpelParseException
spe
=
(
SpelParseException
)
ex
;
assertEquals
(
SpelMessage
.
NON_TERMINATING_QUOTED_STRING
,
spe
.
getMessageCode
());
assertEquals
(
0
,
spe
.
getPosition
());
assertTrue
(
ex
.
getMessage
().
contains
(
ex
.
getExpressionString
()));
}
}
@Test
public
void
arithmeticPrecedence2
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPrecedence2
()
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
"2+3*5"
);
assertEquals
(
17
,
expr
.
getValue
());
}
@Test
public
void
arithmeticPrecedence3
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPrecedence3
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"3+10/2"
);
assertEquals
(
8
,
expr
.
getValue
());
}
@Test
public
void
arithmeticPrecedence4
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPrecedence4
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"10/2+3"
);
assertEquals
(
8
,
expr
.
getValue
());
}
@Test
public
void
arithmeticPrecedence5
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPrecedence5
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"(4+10)/2"
);
assertEquals
(
7
,
expr
.
getValue
());
}
@Test
public
void
arithmeticPrecedence6
()
throws
EvaluationException
,
ParseException
{
public
void
arithmeticPrecedence6
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"(3+2)*2"
);
assertEquals
(
10
,
expr
.
getValue
());
}
@Test
public
void
booleanOperators
()
throws
EvaluationException
,
ParseException
{
public
void
booleanOperators
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"true"
);
assertEquals
(
Boolean
.
TRUE
,
expr
.
getValue
(
Boolean
.
class
));
expr
=
new
SpelExpressionParser
().
parseRaw
(
"false"
);
...
...
@@ -236,7 +241,7 @@ public class SpelParserTests {
}
@Test
public
void
booleanOperators_symbolic_spr9614
()
throws
EvaluationException
,
ParseException
{
public
void
booleanOperators_symbolic_spr9614
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"true"
);
assertEquals
(
Boolean
.
TRUE
,
expr
.
getValue
(
Boolean
.
class
));
expr
=
new
SpelExpressionParser
().
parseRaw
(
"false"
);
...
...
@@ -254,7 +259,7 @@ public class SpelParserTests {
}
@Test
public
void
stringLiterals
()
throws
EvaluationException
,
ParseException
{
public
void
stringLiterals
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"'howdy'"
);
assertEquals
(
"howdy"
,
expr
.
getValue
());
expr
=
new
SpelExpressionParser
().
parseRaw
(
"'hello '' world'"
);
...
...
@@ -262,13 +267,13 @@ public class SpelParserTests {
}
@Test
public
void
stringLiterals2
()
throws
EvaluationException
,
ParseException
{
public
void
stringLiterals2
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"'howdy'.substring(0,2)"
);
assertEquals
(
"ho"
,
expr
.
getValue
());
}
@Test
public
void
testStringLiterals_DoubleQuotes_spr9620
()
throws
Exception
{
public
void
testStringLiterals_DoubleQuotes_spr9620
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"\"double quote: \"\".\""
);
assertEquals
(
"double quote: \"."
,
expr
.
getValue
());
expr
=
new
SpelExpressionParser
().
parseRaw
(
"\"hello \"\" world\""
);
...
...
@@ -276,7 +281,7 @@ public class SpelParserTests {
}
@Test
public
void
testStringLiterals_DoubleQuotes_spr9620_2
()
throws
Exception
{
public
void
testStringLiterals_DoubleQuotes_spr9620_2
()
{
try
{
new
SpelExpressionParser
().
parseRaw
(
"\"double quote: \\\"\\\".\""
);
fail
(
"Should have failed"
);
...
...
@@ -288,7 +293,7 @@ public class SpelParserTests {
}
@Test
public
void
positionalInformation
()
throws
EvaluationException
,
ParseException
{
public
void
positionalInformation
()
{
SpelExpression
expr
=
new
SpelExpressionParser
().
parseRaw
(
"true and true or false"
);
SpelNode
rootAst
=
expr
.
getAST
();
OpOr
operatorOr
=
(
OpOr
)
rootAst
;
...
...
@@ -355,13 +360,13 @@ public class SpelParserTests {
exprEx
=
new
ExpressionException
(
"wibble"
,
"test"
);
assertEquals
(
"test"
,
exprEx
.
getSimpleMessage
());
assertEquals
(
"Expression
'wibble'
: test"
,
exprEx
.
toDetailedString
());
assertEquals
(
"Expression
'wibble'
: test"
,
exprEx
.
getMessage
());
assertEquals
(
"Expression
[wibble]
: test"
,
exprEx
.
toDetailedString
());
assertEquals
(
"Expression
[wibble]
: test"
,
exprEx
.
getMessage
());
exprEx
=
new
ExpressionException
(
"wibble"
,
3
,
"test"
);
assertEquals
(
"test"
,
exprEx
.
getSimpleMessage
());
assertEquals
(
"Expression
'wibble' @
3: test"
,
exprEx
.
toDetailedString
());
assertEquals
(
"Expression
'wibble' @
3: test"
,
exprEx
.
getMessage
());
assertEquals
(
"Expression
[wibble] @
3: test"
,
exprEx
.
toDetailedString
());
assertEquals
(
"Expression
[wibble] @
3: test"
,
exprEx
.
getMessage
());
}
@Test
...
...
@@ -401,16 +406,16 @@ public class SpelParserTests {
checkNumber
(
"1e+3"
,
1
e3d
,
Double
.
class
);
}
private
void
checkNumber
(
String
expression
,
Object
value
,
Class
<?>
type
)
{
try
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
SpelExpression
expr
=
parser
.
parseRaw
(
expression
);
Object
o
=
expr
.
getValue
();
assertEquals
(
value
,
o
);
assertEquals
(
type
,
o
.
getClass
());
Object
exprVal
=
expr
.
getValue
();
assertEquals
(
value
,
exprVal
);
assertEquals
(
type
,
exprVal
.
getClass
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
fail
(
ex
.
getMessage
());
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录