Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
8da9e546
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,发现更多精彩内容 >>
提交
8da9e546
编写于
1月 15, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Turned ArgumentsMatchKind and ArgumentsMatchInfo to package-visible
上级
abff789b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
143 deletion
+72
-143
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
...ngframework/expression/spel/support/ReflectionHelper.java
+30
-96
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java
...xpression/spel/support/ReflectiveConstructorResolver.java
+7
-11
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java
...ork/expression/spel/support/ReflectiveMethodResolver.java
+5
-6
spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java
...mework/expression/spel/support/ReflectionHelperTests.java
+30
-30
未找到文件。
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
浏览文件 @
8da9e546
...
...
@@ -55,7 +55,7 @@ public class ReflectionHelper {
Assert
.
isTrue
(
expectedArgTypes
.
size
()
==
suppliedArgTypes
.
size
(),
"Expected argument types and supplied argument types should be arrays of same length"
);
Arg
sMatchKind
match
=
Arg
sMatchKind
.
EXACT
;
Arg
umentsMatchKind
match
=
Argument
sMatchKind
.
EXACT
;
for
(
int
i
=
0
;
i
<
expectedArgTypes
.
size
()
&&
match
!=
null
;
i
++)
{
TypeDescriptor
suppliedArg
=
suppliedArgTypes
.
get
(
i
);
TypeDescriptor
expectedArg
=
expectedArgTypes
.
get
(
i
);
...
...
@@ -68,12 +68,12 @@ public class ReflectionHelper {
}
else
{
if
(
suppliedArg
.
isAssignableTo
(
expectedArg
))
{
if
(
match
!=
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
match
=
ArgsMatchKind
.
CLOSE
;
if
(
match
!=
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
)
{
match
=
Arg
ument
sMatchKind
.
CLOSE
;
}
}
else
if
(
typeConverter
.
canConvert
(
suppliedArg
,
expectedArg
))
{
match
=
ArgsMatchKind
.
REQUIRES_CONVERSION
;
match
=
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
;
}
else
{
match
=
null
;
...
...
@@ -144,7 +144,7 @@ public class ReflectionHelper {
Assert
.
isTrue
(
expectedArgTypes
.
get
(
expectedArgTypes
.
size
()
-
1
).
isArray
(),
"Final expected argument should be array type (the varargs parameter)"
);
Arg
sMatchKind
match
=
Arg
sMatchKind
.
EXACT
;
Arg
umentsMatchKind
match
=
Argument
sMatchKind
.
EXACT
;
// Check up until the varargs argument:
...
...
@@ -161,12 +161,12 @@ public class ReflectionHelper {
else
{
if
(!
expectedArg
.
equals
(
suppliedArg
))
{
if
(
suppliedArg
.
isAssignableTo
(
expectedArg
))
{
if
(
match
!=
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
match
=
ArgsMatchKind
.
CLOSE
;
if
(
match
!=
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
)
{
match
=
Arg
ument
sMatchKind
.
CLOSE
;
}
}
else
if
(
typeConverter
.
canConvert
(
suppliedArg
,
expectedArg
))
{
match
=
ArgsMatchKind
.
REQUIRES_CONVERSION
;
match
=
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
;
}
else
{
match
=
null
;
...
...
@@ -202,12 +202,12 @@ public class ReflectionHelper {
else
{
if
(
varargsParamType
!=
suppliedArg
.
getType
())
{
if
(
ClassUtils
.
isAssignable
(
varargsParamType
,
suppliedArg
.
getType
()))
{
if
(
match
!=
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
match
=
ArgsMatchKind
.
CLOSE
;
if
(
match
!=
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
)
{
match
=
Arg
ument
sMatchKind
.
CLOSE
;
}
}
else
if
(
typeConverter
.
canConvert
(
suppliedArg
,
TypeDescriptor
.
valueOf
(
varargsParamType
)))
{
match
=
ArgsMatchKind
.
REQUIRES_CONVERSION
;
match
=
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
;
}
else
{
match
=
null
;
...
...
@@ -331,8 +331,9 @@ public class ReflectionHelper {
// Check if repackaging is needed:
if
(
parameterCount
!=
args
.
length
||
requiredParameterTypes
[
parameterCount
-
1
]
!=
(
args
[
argumentCount
-
1
]
==
null
?
null
:
args
[
argumentCount
-
1
].
getClass
()))
{
int
arraySize
=
0
;
// zero size array if nothing to pass as the varargs parameter
(
args
[
argumentCount
-
1
]
!=
null
?
args
[
argumentCount
-
1
].
getClass
()
:
null
))
{
int
arraySize
=
0
;
// zero size array if nothing to pass as the varargs parameter
if
(
argumentCount
>=
parameterCount
)
{
arraySize
=
argumentCount
-
(
parameterCount
-
1
);
}
...
...
@@ -341,93 +342,26 @@ public class ReflectionHelper {
Object
[]
newArgs
=
new
Object
[
parameterCount
];
System
.
arraycopy
(
args
,
0
,
newArgs
,
0
,
newArgs
.
length
-
1
);
// 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
System
.
arraycopy
(
args
,
parameterCount
-
1
,
repackagedArguments
,
0
,
arraySize
);
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
();
Object
repackagedArgs
=
Array
.
newInstance
(
componentType
,
arraySize
);
for
(
int
i
=
0
;
i
<
arraySize
;
i
++)
{
Array
.
set
(
repackagedArgs
,
i
,
args
[
parameterCount
-
1
+
i
]);
}
newArgs
[
newArgs
.
length
-
1
]
=
repackagedArgs
;
return
newArgs
;
}
return
args
;
}
public
static
enum
Arg
sMatchKind
{
static
enum
Argument
sMatchKind
{
/** An exact match is where the parameter types exactly match what the method/constructor
being invoked
is expecting */
/** An exact match is where the parameter types exactly match what the method/constructor is expecting */
EXACT
,
/** A close match is where the parameter types either exactly match or are assignment
compatible with the method/constructor being invoked
*/
/** A close match is where the parameter types either exactly match or are assignment
-compatible
*/
CLOSE
,
/** A conversion match is where the type converter must be used to transform some of the parameter types */
...
...
@@ -441,24 +375,24 @@ public class ReflectionHelper {
* If the kind indicates that conversion is required for some of the arguments then the arguments that require
* conversion are listed in the argsRequiringConversion array.
*/
public
static
class
ArgumentsMatchInfo
{
static
class
ArgumentsMatchInfo
{
p
ublic
final
Arg
sMatchKind
kind
;
p
rivate
final
Argument
sMatchKind
kind
;
ArgumentsMatchInfo
(
ArgsMatchKind
kind
)
{
ArgumentsMatchInfo
(
Arg
ument
sMatchKind
kind
)
{
this
.
kind
=
kind
;
}
public
boolean
isExactMatch
()
{
return
(
this
.
kind
==
ArgsMatchKind
.
EXACT
);
return
(
this
.
kind
==
Arg
ument
sMatchKind
.
EXACT
);
}
public
boolean
isCloseMatch
()
{
return
(
this
.
kind
==
ArgsMatchKind
.
CLOSE
);
return
(
this
.
kind
==
Arg
ument
sMatchKind
.
CLOSE
);
}
public
boolean
isMatchRequiringConversion
()
{
return
(
this
.
kind
==
ArgsMatchKind
.
REQUIRES_CONVERSION
);
return
(
this
.
kind
==
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
);
}
@Override
...
...
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java
浏览文件 @
8da9e546
...
...
@@ -32,8 +32,7 @@ import org.springframework.expression.EvaluationException;
import
org.springframework.expression.TypeConverter
;
/**
* A constructor resolver that uses reflection to locate the constructor that should be
* invoked
* A constructor resolver that uses reflection to locate the constructor that should be invoked.
*
* @author Andy Clement
* @author Juergen Hoeller
...
...
@@ -44,12 +43,10 @@ public class ReflectiveConstructorResolver implements ConstructorResolver {
/**
* Locate a constructor on the type. There are three kinds of match that might occur:
* <ol>
* <li>An exact match where the types of the arguments match the types of the
* constructor
* <li>An in-exact match where the types we are looking for are subtypes of those
* defined on the constructor
* <li>A match where we are able to convert the arguments into those expected by the
* constructor, according to the registered type converter.
* <li>An exact match where the types of the arguments match the types of the constructor
* <li>An in-exact match where the types we are looking for are subtypes of those defined on the constructor
* <li>A match where we are able to convert the arguments into those expected by the constructor, according to the
* registered type converter.
* </ol>
*/
@Override
...
...
@@ -93,11 +90,10 @@ public class ReflectiveConstructorResolver implements ConstructorResolver {
matchInfo
=
ReflectionHelper
.
compareArguments
(
paramDescriptors
,
argumentTypes
,
typeConverter
);
}
if
(
matchInfo
!=
null
)
{
if
(
matchInfo
.
kind
==
ReflectionHelper
.
ArgsMatchKind
.
EXACT
)
{
if
(
matchInfo
.
isExactMatch
()
)
{
return
new
ReflectiveConstructorExecutor
(
ctor
);
}
else
if
(
matchInfo
.
kind
==
ReflectionHelper
.
ArgsMatchKind
.
CLOSE
||
matchInfo
.
kind
==
ReflectionHelper
.
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
else
if
(
matchInfo
.
isCloseMatch
()
||
matchInfo
.
isMatchRequiringConversion
())
{
closeMatch
=
ctor
;
}
}
...
...
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java
浏览文件 @
8da9e546
...
...
@@ -42,8 +42,8 @@ import org.springframework.expression.spel.SpelEvaluationException;
import
org.springframework.expression.spel.SpelMessage
;
/**
* Reflection-based {@link MethodResolver} used by default in
*
{@link StandardEvaluationContext}
unless explicit method resolvers have been specified.
* Reflection-based {@link MethodResolver} used by default in
{@link StandardEvaluationContext}
* unless explicit method resolvers have been specified.
*
* @author Andy Clement
* @author Juergen Hoeller
...
...
@@ -124,7 +124,6 @@ public class ReflectiveMethodResolver implements MethodResolver {
Method
closeMatch
=
null
;
int
closeMatchDistance
=
Integer
.
MAX_VALUE
;
int
[]
argsToConvert
=
null
;
Method
matchRequiringConversion
=
null
;
boolean
multipleOptions
=
false
;
...
...
@@ -145,10 +144,10 @@ public class ReflectiveMethodResolver implements MethodResolver {
matchInfo
=
ReflectionHelper
.
compareArguments
(
paramDescriptors
,
argumentTypes
,
typeConverter
);
}
if
(
matchInfo
!=
null
)
{
if
(
matchInfo
.
kind
==
ReflectionHelper
.
ArgsMatchKind
.
EXACT
)
{
if
(
matchInfo
.
isExactMatch
()
)
{
return
new
ReflectiveMethodExecutor
(
method
);
}
else
if
(
matchInfo
.
kind
==
ReflectionHelper
.
ArgsMatchKind
.
CLOSE
)
{
else
if
(
matchInfo
.
isCloseMatch
()
)
{
if
(!
this
.
useDistance
)
{
closeMatch
=
method
;
}
...
...
@@ -161,7 +160,7 @@ public class ReflectiveMethodResolver implements MethodResolver {
}
}
}
else
if
(
matchInfo
.
kind
==
ReflectionHelper
.
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
else
if
(
matchInfo
.
isMatchRequiringConversion
()
)
{
if
(
matchRequiringConversion
!=
null
)
{
multipleOptions
=
true
;
}
...
...
spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java
浏览文件 @
8da9e546
...
...
@@ -35,7 +35,7 @@ import org.springframework.expression.spel.SpelMessage;
import
org.springframework.expression.spel.SpelUtilities
;
import
org.springframework.expression.spel.ast.FormatHelper
;
import
org.springframework.expression.spel.standard.SpelExpression
;
import
org.springframework.expression.spel.support.ReflectionHelper.ArgsMatchKind
;
import
org.springframework.expression.spel.support.ReflectionHelper.Arg
ument
sMatchKind
;
import
static
org
.
junit
.
Assert
.*;
...
...
@@ -107,10 +107,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
StandardTypeConverter
tc
=
new
StandardTypeConverter
();
// Calling foo(String) with (String) is exact match
checkMatch
(
new
Class
[]
{
String
.
class
},
new
Class
[]
{
String
.
class
},
tc
,
Arg
sMatchKind
.
EXACT
);
checkMatch
(
new
Class
[]
{
String
.
class
},
new
Class
[]
{
String
.
class
},
tc
,
ReflectionHelper
.
Argument
sMatchKind
.
EXACT
);
// Calling foo(String,Integer) with (String,Integer) is exact match
checkMatch
(
new
Class
[]
{
String
.
class
,
Integer
.
class
},
new
Class
[]
{
String
.
class
,
Integer
.
class
},
tc
,
ArgsMatchKind
.
EXACT
);
checkMatch
(
new
Class
[]
{
String
.
class
,
Integer
.
class
},
new
Class
[]
{
String
.
class
,
Integer
.
class
},
tc
,
Arg
ument
sMatchKind
.
EXACT
);
}
@Test
...
...
@@ -118,13 +118,13 @@ public class ReflectionHelperTests extends ExpressionTestCase {
StandardTypeConverter
tc
=
new
StandardTypeConverter
();
// Calling foo(List) with (ArrayList) is close match (no conversion required)
checkMatch
(
new
Class
[]
{
ArrayList
.
class
},
new
Class
[]
{
List
.
class
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch
(
new
Class
[]
{
ArrayList
.
class
},
new
Class
[]
{
List
.
class
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (Sub,String) on call to foo(Super,String) is close match
checkMatch
(
new
Class
[]
{
Sub
.
class
,
String
.
class
},
new
Class
[]
{
Super
.
class
,
String
.
class
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch
(
new
Class
[]
{
Sub
.
class
,
String
.
class
},
new
Class
[]
{
Super
.
class
,
String
.
class
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (String,Sub) on call to foo(String,Super) is close match
checkMatch
(
new
Class
[]
{
String
.
class
,
Sub
.
class
},
new
Class
[]
{
String
.
class
,
Super
.
class
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch
(
new
Class
[]
{
String
.
class
,
Sub
.
class
},
new
Class
[]
{
String
.
class
,
Super
.
class
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
}
@Test
...
...
@@ -132,13 +132,13 @@ public class ReflectionHelperTests extends ExpressionTestCase {
StandardTypeConverter
tc
=
new
StandardTypeConverter
();
// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
checkMatch
(
new
Class
[]
{
String
.
class
,
Integer
.
TYPE
},
new
Class
[]
{
String
.
class
,
Integer
.
class
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch
(
new
Class
[]
{
String
.
class
,
Integer
.
TYPE
},
new
Class
[]
{
String
.
class
,
Integer
.
class
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
checkMatch
(
new
Class
[]
{
Integer
.
TYPE
,
String
.
class
},
new
Class
[]
{
Integer
.
class
,
String
.
class
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch
(
new
Class
[]
{
Integer
.
TYPE
,
String
.
class
},
new
Class
[]
{
Integer
.
class
,
String
.
class
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
checkMatch
(
new
Class
[]
{
Integer
.
TYPE
,
Sub
.
class
},
new
Class
[]
{
Integer
.
class
,
Super
.
class
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch
(
new
Class
[]
{
Integer
.
TYPE
,
Sub
.
class
},
new
Class
[]
{
Integer
.
class
,
Super
.
class
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
// TODO checkMatch(new Class[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION);
...
...
@@ -159,34 +159,34 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Class
<?>
integerArrayClass
=
new
Integer
[
0
].
getClass
();
// Passing (String[]) on call to (String[]) is exact match
checkMatch2
(
new
Class
[]
{
stringArrayClass
},
new
Class
[]
{
stringArrayClass
},
tc
,
ArgsMatchKind
.
EXACT
);
checkMatch2
(
new
Class
[]
{
stringArrayClass
},
new
Class
[]
{
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
EXACT
);
// Passing (Integer, String[]) on call to (Integer, String[]) is exact match
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
tc
,
ArgsMatchKind
.
EXACT
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
EXACT
);
// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
checkMatch2
(
new
Class
[]
{
String
.
class
,
Integer
.
class
,
stringArrayClass
},
new
Class
[]
{
String
.
class
,
Integer
.
class
,
stringArrayClass
},
tc
,
ArgsMatchKind
.
EXACT
);
checkMatch2
(
new
Class
[]
{
String
.
class
,
Integer
.
class
,
stringArrayClass
},
new
Class
[]
{
String
.
class
,
Integer
.
class
,
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
EXACT
);
// Passing (Sub, String[]) on call to (Super, String[]) is exact match
checkMatch2
(
new
Class
[]
{
Sub
.
class
,
stringArrayClass
},
new
Class
[]
{
Super
.
class
,
stringArrayClass
},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch2
(
new
Class
[]
{
Sub
.
class
,
stringArrayClass
},
new
Class
[]
{
Super
.
class
,
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (Integer, String[]) on call to (String, String[]) is exact match
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
new
Class
[]
{
String
.
class
,
stringArrayClass
},
tc
,
ArgsMatchKind
.
REQUIRES_CONVERSION
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
new
Class
[]
{
String
.
class
,
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
);
// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Sub
.
class
,
String
[].
class
},
new
Class
[]
{
String
.
class
,
Super
.
class
,
String
[].
class
},
tc
,
ArgsMatchKind
.
REQUIRES_CONVERSION
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Sub
.
class
,
String
[].
class
},
new
Class
[]
{
String
.
class
,
Super
.
class
,
String
[].
class
},
tc
,
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
);
// Passing (String) on call to (String[]) is exact match
checkMatch2
(
new
Class
[]
{
String
.
class
},
new
Class
[]
{
stringArrayClass
},
tc
,
ArgsMatchKind
.
EXACT
);
checkMatch2
(
new
Class
[]
{
String
.
class
},
new
Class
[]
{
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
EXACT
);
// Passing (Integer,String) on call to (Integer,String[]) is exact match
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
String
.
class
},
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
tc
,
ArgsMatchKind
.
EXACT
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
String
.
class
},
new
Class
[]
{
Integer
.
class
,
stringArrayClass
},
tc
,
Arg
ument
sMatchKind
.
EXACT
);
// Passing (String) on call to (Integer[]) is conversion match (String to Integer)
checkMatch2
(
new
Class
[]
{
String
.
class
},
new
Class
[]
{
integerArrayClass
},
tc
,
ArgsMatchKind
.
REQUIRES_CONVERSION
);
checkMatch2
(
new
Class
[]
{
String
.
class
},
new
Class
[]
{
integerArrayClass
},
tc
,
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
);
// Passing (Sub) on call to (Super[]) is close match
checkMatch2
(
new
Class
[]
{
Sub
.
class
},
new
Class
[]
{
new
Super
[
0
].
getClass
()},
tc
,
ArgsMatchKind
.
CLOSE
);
checkMatch2
(
new
Class
[]
{
Sub
.
class
},
new
Class
[]
{
new
Super
[
0
].
getClass
()},
tc
,
Arg
ument
sMatchKind
.
CLOSE
);
// Passing (Super) on call to (Sub[]) is not a match
checkMatch2
(
new
Class
[]
{
Super
.
class
},
new
Class
[]
{
new
Sub
[
0
].
getClass
()},
tc
,
null
);
...
...
@@ -199,9 +199,9 @@ public class ReflectionHelperTests extends ExpressionTestCase {
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Integer
.
class
,
String
.
class
},
new
Class
[]
{
String
.
class
,
String
.
class
,
Super
[].
class
},
tc
,
null
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Integer
.
class
,
Sub
.
class
},
new
Class
[]
{
String
.
class
,
String
.
class
,
Super
[].
class
},
tc
,
ArgsMatchKind
.
REQUIRES_CONVERSION
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Integer
.
class
,
Sub
.
class
},
new
Class
[]
{
String
.
class
,
String
.
class
,
Super
[].
class
},
tc
,
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Integer
.
class
,
Integer
.
class
},
new
Class
[]
{
Integer
.
class
,
String
[].
class
},
tc
,
ArgsMatchKind
.
REQUIRES_CONVERSION
);
checkMatch2
(
new
Class
[]
{
Integer
.
class
,
Integer
.
class
,
Integer
.
class
},
new
Class
[]
{
Integer
.
class
,
String
[].
class
},
tc
,
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
);
// what happens on (Integer,String) passed to (Integer[]) ?
}
...
...
@@ -481,7 +481,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
/**
* Used to validate the match returned from a compareArguments call.
*/
private
void
checkMatch
(
Class
[]
inputTypes
,
Class
[]
expectedTypes
,
StandardTypeConverter
typeConverter
,
ArgsMatchKind
expectedMatchKind
)
{
private
void
checkMatch
(
Class
[]
inputTypes
,
Class
[]
expectedTypes
,
StandardTypeConverter
typeConverter
,
Arg
ument
sMatchKind
expectedMatchKind
)
{
ReflectionHelper
.
ArgumentsMatchInfo
matchInfo
=
ReflectionHelper
.
compareArguments
(
getTypeDescriptors
(
expectedTypes
),
getTypeDescriptors
(
inputTypes
),
typeConverter
);
if
(
expectedMatchKind
==
null
)
{
assertNull
(
"Did not expect them to match in any way"
,
matchInfo
);
...
...
@@ -490,13 +490,13 @@ public class ReflectionHelperTests extends ExpressionTestCase {
assertNotNull
(
"Should not be a null match"
,
matchInfo
);
}
if
(
expectedMatchKind
==
ArgsMatchKind
.
EXACT
)
{
if
(
expectedMatchKind
==
Arg
ument
sMatchKind
.
EXACT
)
{
assertTrue
(
matchInfo
.
isExactMatch
());
}
else
if
(
expectedMatchKind
==
ArgsMatchKind
.
CLOSE
)
{
else
if
(
expectedMatchKind
==
Arg
ument
sMatchKind
.
CLOSE
)
{
assertTrue
(
matchInfo
.
isCloseMatch
());
}
else
if
(
expectedMatchKind
==
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
else
if
(
expectedMatchKind
==
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
)
{
assertTrue
(
"expected to be a match requiring conversion, but was "
+
matchInfo
,
matchInfo
.
isMatchRequiringConversion
());
}
}
...
...
@@ -504,22 +504,22 @@ public class ReflectionHelperTests extends ExpressionTestCase {
/**
* Used to validate the match returned from a compareArguments call.
*/
private
void
checkMatch2
(
Class
[]
inputTypes
,
Class
[]
expectedTypes
,
StandardTypeConverter
typeConverter
,
ArgsMatchKind
expectedMatchKind
)
{
private
void
checkMatch2
(
Class
[]
inputTypes
,
Class
[]
expectedTypes
,
StandardTypeConverter
typeConverter
,
Arg
ument
sMatchKind
expectedMatchKind
)
{
ReflectionHelper
.
ArgumentsMatchInfo
matchInfo
=
ReflectionHelper
.
compareArgumentsVarargs
(
getTypeDescriptors
(
expectedTypes
),
getTypeDescriptors
(
inputTypes
),
typeConverter
);
if
(
expectedMatchKind
==
null
)
{
assertNull
(
"Did not expect them to match in any way: "
+
matchInfo
,
matchInfo
);
assertNull
(
"Did not expect them to match in any way: "
+
matchInfo
,
matchInfo
);
}
else
{
assertNotNull
(
"Should not be a null match"
,
matchInfo
);
}
if
(
expectedMatchKind
==
ArgsMatchKind
.
EXACT
)
{
if
(
expectedMatchKind
==
Arg
ument
sMatchKind
.
EXACT
)
{
assertTrue
(
matchInfo
.
isExactMatch
());
}
else
if
(
expectedMatchKind
==
ArgsMatchKind
.
CLOSE
)
{
else
if
(
expectedMatchKind
==
Arg
ument
sMatchKind
.
CLOSE
)
{
assertTrue
(
matchInfo
.
isCloseMatch
());
}
else
if
(
expectedMatchKind
==
ArgsMatchKind
.
REQUIRES_CONVERSION
)
{
else
if
(
expectedMatchKind
==
Arg
ument
sMatchKind
.
REQUIRES_CONVERSION
)
{
assertTrue
(
"expected to be a match requiring conversion, but was "
+
matchInfo
,
matchInfo
.
isMatchRequiringConversion
());
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录