Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
9202224b
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,发现更多精彩内容 >>
提交
9202224b
编写于
4月 01, 2011
作者:
A
Andy Clement
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-8174: varargs and primitive handling in SpEL
上级
b9d07b9c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
168 addition
and
7 deletion
+168
-7
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
...ngframework/expression/spel/support/ReflectionHelper.java
+62
-7
org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java
...org/springframework/expression/spel/SpringEL300Tests.java
+106
-0
未找到文件。
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
浏览文件 @
9202224b
...
...
@@ -316,18 +316,73 @@ public class ReflectionHelper {
if
(
argumentCount
>=
parameterCount
)
{
arraySize
=
argumentCount
-
(
parameterCount
-
1
);
}
Object
[]
repackagedArguments
=
(
Object
[])
Array
.
newInstance
(
requiredParameterTypes
[
parameterCount
-
1
].
getComponentType
(),
arraySize
);
// Copy all but the varargs arguments
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
args
[
parameterCount
+
i
-
1
];
}
// Create an array for the varargs arguments
Object
[]
newArgs
=
new
Object
[
parameterCount
];
for
(
int
i
=
0
;
i
<
newArgs
.
length
-
1
;
i
++)
{
newArgs
[
i
]
=
args
[
i
];
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
// Now sort out the final argument, which is the varargs one. Before entering this
// method the arguments should have been converted to the box form of the required type.
Class
<?>
componentType
=
requiredParameterTypes
[
parameterCount
-
1
].
getComponentType
();
if
(
componentType
.
isPrimitive
())
{
if
(
componentType
==
Integer
.
TYPE
)
{
int
[]
repackagedArguments
=
(
int
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Integer
)
args
[
parameterCount
+
i
-
1
]).
intValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Float
.
TYPE
)
{
float
[]
repackagedArguments
=
(
float
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Float
)
args
[
parameterCount
+
i
-
1
]).
floatValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Double
.
TYPE
)
{
double
[]
repackagedArguments
=
(
double
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Double
)
args
[
parameterCount
+
i
-
1
]).
doubleValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Short
.
TYPE
)
{
short
[]
repackagedArguments
=
(
short
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Short
)
args
[
parameterCount
+
i
-
1
]).
shortValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Character
.
TYPE
)
{
char
[]
repackagedArguments
=
(
char
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Character
)
args
[
parameterCount
+
i
-
1
]).
charValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Byte
.
TYPE
)
{
byte
[]
repackagedArguments
=
(
byte
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Byte
)
args
[
parameterCount
+
i
-
1
]).
byteValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Boolean
.
TYPE
)
{
boolean
[]
repackagedArguments
=
(
boolean
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Boolean
)
args
[
parameterCount
+
i
-
1
]).
booleanValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
else
if
(
componentType
==
Long
.
TYPE
)
{
long
[]
repackagedArguments
=
(
long
[])
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
((
Long
)
args
[
parameterCount
+
i
-
1
]).
longValue
();
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
}
else
{
Object
[]
repackagedArguments
=
(
Object
[])
Array
.
newInstance
(
componentType
,
arraySize
);
// Copy all but the varargs arguments
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
repackagedArguments
[
i
]
=
args
[
parameterCount
+
i
-
1
];
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArguments
;
}
return
newArgs
;
}
return
args
;
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java
浏览文件 @
9202224b
...
...
@@ -36,11 +36,13 @@ import org.springframework.expression.EvaluationContext;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ExpressionParser
;
import
org.springframework.expression.MethodExecutor
;
import
org.springframework.expression.ParserContext
;
import
org.springframework.expression.PropertyAccessor
;
import
org.springframework.expression.TypedValue
;
import
org.springframework.expression.spel.standard.SpelExpression
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.expression.spel.support.ReflectiveMethodResolver
;
import
org.springframework.expression.spel.support.ReflectivePropertyAccessor
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.expression.spel.support.StandardTypeLocator
;
...
...
@@ -811,5 +813,109 @@ public class SpringEL300Tests extends ExpressionTestCase {
assertEquals
(
"[D(aaa), D(bbb), D(ccc)]"
,
value3
.
toString
());
}
@Test
public
void
varargsAndPrimitives_SPR8174
()
throws
Exception
{
EvaluationContext
emptyEvalContext
=
new
StandardEvaluationContext
();
List
<
TypeDescriptor
>
args
=
new
ArrayList
<
TypeDescriptor
>();
args
.
add
(
TypeDescriptor
.
forObject
(
34L
));
ReflectionUtil
<
Integer
>
ru
=
new
ReflectionUtil
<
Integer
>();
MethodExecutor
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"methodToCall"
,
args
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
(
23
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
45
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
(
23
f
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
45
f
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
(
23
d
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
23
d
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
((
short
)
23
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
(
short
)
23
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
(
23L
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
23L
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
((
char
)
65
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
(
char
)
65
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
((
byte
)
23
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
(
byte
)
23
);
args
.
set
(
0
,
TypeDescriptor
.
forObject
(
true
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"foo"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
true
);
// trickier:
args
.
set
(
0
,
TypeDescriptor
.
forObject
(
12
));
args
.
add
(
TypeDescriptor
.
forObject
(
23
f
));
me
=
new
ReflectiveMethodResolver
().
resolve
(
emptyEvalContext
,
ru
,
"bar"
,
args
);
me
.
execute
(
emptyEvalContext
,
ru
,
12
,
23
f
);
}
public
class
ReflectionUtil
<
T
extends
Number
>
{
public
Object
methodToCall
(
T
param
)
{
System
.
out
.
println
(
param
+
" "
+
param
.
getClass
());
return
"Object methodToCall(T param)"
;
}
public
void
foo
(
int
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
float
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
double
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
short
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
long
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
boolean
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
char
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
foo
(
byte
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
public
void
bar
(
int
...
array
)
{
if
(
array
.
length
==
0
)
{
throw
new
RuntimeException
();
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录