Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
387c8a81
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,发现更多精彩内容 >>
提交
387c8a81
编写于
12月 18, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Differentiate between TypeDescriptors with same annotations but different attributes
Issue: SPR-13714
上级
06056e6a
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
399 addition
and
298 deletion
+399
-298
spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
...java/org/springframework/core/convert/TypeDescriptor.java
+1
-1
spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java
...org/springframework/core/convert/TypeDescriptorTests.java
+303
-271
spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
...k/core/convert/support/GenericConversionServiceTests.java
+95
-26
未找到文件。
spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
浏览文件 @
387c8a81
...
@@ -468,7 +468,7 @@ public class TypeDescriptor implements Serializable {
...
@@ -468,7 +468,7 @@ public class TypeDescriptor implements Serializable {
return
false
;
return
false
;
}
}
for
(
Annotation
ann
:
getAnnotations
())
{
for
(
Annotation
ann
:
getAnnotations
())
{
if
(!
other
.
hasAnnotation
(
ann
.
annotationType
(
)))
{
if
(!
ann
.
equals
(
other
.
getAnnotation
(
ann
.
annotationType
()
)))
{
return
false
;
return
false
;
}
}
}
}
...
...
spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java
浏览文件 @
387c8a81
此差异已折叠。
点击以展开。
spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
浏览文件 @
387c8a81
...
@@ -478,6 +478,21 @@ public class GenericConversionServiceTests {
...
@@ -478,6 +478,21 @@ public class GenericConversionServiceTests {
assertTrue
(
converter
.
getNestedMatchAttempts
()
>
0
);
assertTrue
(
converter
.
getNestedMatchAttempts
()
>
0
);
}
}
@Test
public
void
conditionalConverterCachingForDifferentAnnotationAttributes
()
throws
Exception
{
conversionService
.
addConverter
(
new
ColorConverter
());
conversionService
.
addConverter
(
new
MyConditionalColorConverter
());
assertEquals
(
Color
.
BLACK
,
conversionService
.
convert
(
"000000xxxx"
,
new
TypeDescriptor
(
getClass
().
getField
(
"activeColor"
))));
assertEquals
(
Color
.
BLACK
,
conversionService
.
convert
(
" #000000 "
,
new
TypeDescriptor
(
getClass
().
getField
(
"inactiveColor"
))));
assertEquals
(
Color
.
BLACK
,
conversionService
.
convert
(
"000000yyyy"
,
new
TypeDescriptor
(
getClass
().
getField
(
"activeColor"
))));
assertEquals
(
Color
.
BLACK
,
conversionService
.
convert
(
" #000000 "
,
new
TypeDescriptor
(
getClass
().
getField
(
"inactiveColor"
))));
}
@Test
@Test
public
void
shouldNotSupportNullConvertibleTypesFromNonConditionalGenericConverter
()
{
public
void
shouldNotSupportNullConvertibleTypesFromNonConditionalGenericConverter
()
{
GenericConverter
converter
=
new
NonConditionalGenericConverter
();
GenericConverter
converter
=
new
NonConditionalGenericConverter
();
...
@@ -629,14 +644,49 @@ public class GenericConversionServiceTests {
...
@@ -629,14 +644,49 @@ public class GenericConversionServiceTests {
}
}
@ExampleAnnotation
(
active
=
true
)
public
String
annotatedString
;
@ExampleAnnotation
(
active
=
true
)
public
Color
activeColor
;
@ExampleAnnotation
(
active
=
false
)
public
Color
inactiveColor
;
public
List
<
Integer
>
list
;
public
Map
<
String
,
Integer
>
map
;
public
Map
<
String
,
?>
wildcardMap
;
@SuppressWarnings
(
"rawtypes"
)
public
Collection
rawCollection
;
public
Collection
<?>
genericCollection
;
public
Collection
<
String
>
stringCollection
;
public
Collection
<
Integer
>
integerCollection
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
private
static
@interface
ExampleAnnotation
{}
private
@interface
ExampleAnnotation
{
boolean
active
();
}
private
interface
MyBaseInterface
{
}
private
static
interface
MyBaseInterface
{}
private
static
interface
MyInterface
extends
MyBaseInterface
{}
private
interface
MyInterface
extends
MyBaseInterface
{
}
private
static
class
MyInterfaceImplementer
implements
MyInterface
{
}
private
static
class
MyInterfaceImplementer
implements
MyInterface
{}
private
static
class
MyBaseInterfaceToStringConverter
implements
Converter
<
MyBaseInterface
,
String
>
{
private
static
class
MyBaseInterfaceToStringConverter
implements
Converter
<
MyBaseInterface
,
String
>
{
...
@@ -646,6 +696,7 @@ public class GenericConversionServiceTests {
...
@@ -646,6 +696,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyStringArrayToResourceArrayConverter
implements
Converter
<
String
[],
Resource
[]>
{
private
static
class
MyStringArrayToResourceArrayConverter
implements
Converter
<
String
[],
Resource
[]>
{
@Override
@Override
...
@@ -654,6 +705,7 @@ public class GenericConversionServiceTests {
...
@@ -654,6 +705,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyStringArrayToIntegerArrayConverter
implements
Converter
<
String
[],
Integer
[]>
{
private
static
class
MyStringArrayToIntegerArrayConverter
implements
Converter
<
String
[],
Integer
[]>
{
@Override
@Override
...
@@ -662,6 +714,7 @@ public class GenericConversionServiceTests {
...
@@ -662,6 +714,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyStringToIntegerArrayConverter
implements
Converter
<
String
,
Integer
[]>
{
private
static
class
MyStringToIntegerArrayConverter
implements
Converter
<
String
,
Integer
[]>
{
@Override
@Override
...
@@ -671,6 +724,7 @@ public class GenericConversionServiceTests {
...
@@ -671,6 +724,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
WithCopyConstructor
{
private
static
class
WithCopyConstructor
{
WithCopyConstructor
()
{}
WithCopyConstructor
()
{}
...
@@ -679,6 +733,7 @@ public class GenericConversionServiceTests {
...
@@ -679,6 +733,7 @@ public class GenericConversionServiceTests {
WithCopyConstructor
(
WithCopyConstructor
value
)
{}
WithCopyConstructor
(
WithCopyConstructor
value
)
{}
}
}
private
static
class
MyConditionalConverter
implements
Converter
<
String
,
Color
>,
ConditionalConverter
{
private
static
class
MyConditionalConverter
implements
Converter
<
String
,
Color
>,
ConditionalConverter
{
private
int
matchAttempts
=
0
;
private
int
matchAttempts
=
0
;
...
@@ -699,6 +754,7 @@ public class GenericConversionServiceTests {
...
@@ -699,6 +754,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
NonConditionalGenericConverter
implements
GenericConverter
{
private
static
class
NonConditionalGenericConverter
implements
GenericConverter
{
@Override
@Override
...
@@ -712,6 +768,7 @@ public class GenericConversionServiceTests {
...
@@ -712,6 +768,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyConditionalGenericConverter
implements
GenericConverter
,
ConditionalConverter
{
private
static
class
MyConditionalGenericConverter
implements
GenericConverter
,
ConditionalConverter
{
private
final
List
<
TypeDescriptor
>
sourceTypes
=
new
ArrayList
<
TypeDescriptor
>();
private
final
List
<
TypeDescriptor
>
sourceTypes
=
new
ArrayList
<
TypeDescriptor
>();
...
@@ -737,6 +794,7 @@ public class GenericConversionServiceTests {
...
@@ -737,6 +794,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyConditionalConverterFactory
implements
ConverterFactory
<
String
,
Color
>,
ConditionalConverter
{
private
static
class
MyConditionalConverterFactory
implements
ConverterFactory
<
String
,
Color
>,
ConditionalConverter
{
private
MyConditionalConverter
converter
=
new
MyConditionalConverter
();
private
MyConditionalConverter
converter
=
new
MyConditionalConverter
();
...
@@ -768,11 +826,13 @@ public class GenericConversionServiceTests {
...
@@ -768,11 +826,13 @@ public class GenericConversionServiceTests {
String
getBaseCode
();
String
getBaseCode
();
}
}
private
static
interface
MyEnumInterface
extends
MyEnumBaseInterface
{
private
interface
MyEnumInterface
extends
MyEnumBaseInterface
{
String
getCode
();
String
getCode
();
}
}
private
static
enum
MyEnum
implements
MyEnumInterface
{
private
enum
MyEnum
implements
MyEnumInterface
{
A
(
"1"
),
A
(
"1"
),
B
(
"2"
),
B
(
"2"
),
...
@@ -795,7 +855,8 @@ public class GenericConversionServiceTests {
...
@@ -795,7 +855,8 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
enum
EnumWithSubclass
{
private
enum
EnumWithSubclass
{
FIRST
{
FIRST
{
@Override
@Override
...
@@ -805,6 +866,7 @@ public class GenericConversionServiceTests {
...
@@ -805,6 +866,7 @@ public class GenericConversionServiceTests {
}
}
}
}
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
private
static
class
MyStringToRawCollectionConverter
implements
Converter
<
String
,
Collection
>
{
private
static
class
MyStringToRawCollectionConverter
implements
Converter
<
String
,
Collection
>
{
...
@@ -814,6 +876,7 @@ public class GenericConversionServiceTests {
...
@@ -814,6 +876,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyStringToGenericCollectionConverter
implements
Converter
<
String
,
Collection
<?>>
{
private
static
class
MyStringToGenericCollectionConverter
implements
Converter
<
String
,
Collection
<?>>
{
@Override
@Override
...
@@ -822,6 +885,7 @@ public class GenericConversionServiceTests {
...
@@ -822,6 +885,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyEnumInterfaceToStringConverter
<
T
extends
MyEnumInterface
>
implements
Converter
<
T
,
String
>
{
private
static
class
MyEnumInterfaceToStringConverter
<
T
extends
MyEnumInterface
>
implements
Converter
<
T
,
String
>
{
@Override
@Override
...
@@ -830,14 +894,16 @@ public class GenericConversionServiceTests {
...
@@ -830,14 +894,16 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
StringToMyEnumInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumInterface
>
{
private
static
class
StringToMyEnumInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumInterface
>
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
<
T
extends
MyEnumInterface
>
Converter
<
String
,
T
>
getConverter
(
Class
<
T
>
targetType
)
{
public
<
T
extends
MyEnumInterface
>
Converter
<
String
,
T
>
getConverter
(
Class
<
T
>
targetType
)
{
return
new
StringToMyEnumInterfaceConverter
(
targetType
);
return
new
StringToMyEnumInterfaceConverter
(
targetType
);
}
}
private
static
class
StringToMyEnumInterfaceConverter
<
T
extends
Enum
<?>
&
MyEnumInterface
>
implements
Converter
<
String
,
T
>
{
private
static
class
StringToMyEnumInterfaceConverter
<
T
extends
Enum
<?>
&
MyEnumInterface
>
implements
Converter
<
String
,
T
>
{
private
final
Class
<
T
>
enumType
;
private
final
Class
<
T
>
enumType
;
public
StringToMyEnumInterfaceConverter
(
Class
<
T
>
enumType
)
{
public
StringToMyEnumInterfaceConverter
(
Class
<
T
>
enumType
)
{
...
@@ -855,9 +921,10 @@ public class GenericConversionServiceTests {
...
@@ -855,9 +921,10 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
StringToMyEnumBaseInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumBaseInterface
>
{
private
static
class
StringToMyEnumBaseInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumBaseInterface
>
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
<
T
extends
MyEnumBaseInterface
>
Converter
<
String
,
T
>
getConverter
(
Class
<
T
>
targetType
)
{
public
<
T
extends
MyEnumBaseInterface
>
Converter
<
String
,
T
>
getConverter
(
Class
<
T
>
targetType
)
{
return
new
StringToMyEnumBaseInterfaceConverter
(
targetType
);
return
new
StringToMyEnumBaseInterfaceConverter
(
targetType
);
}
}
...
@@ -881,6 +948,7 @@ public class GenericConversionServiceTests {
...
@@ -881,6 +948,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyStringToStringCollectionConverter
implements
Converter
<
String
,
Collection
<
String
>>
{
private
static
class
MyStringToStringCollectionConverter
implements
Converter
<
String
,
Collection
<
String
>>
{
@Override
@Override
...
@@ -889,6 +957,7 @@ public class GenericConversionServiceTests {
...
@@ -889,6 +957,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyStringToIntegerCollectionConverter
implements
Converter
<
String
,
Collection
<
Integer
>>
{
private
static
class
MyStringToIntegerCollectionConverter
implements
Converter
<
String
,
Collection
<
Integer
>>
{
@Override
@Override
...
@@ -897,6 +966,7 @@ public class GenericConversionServiceTests {
...
@@ -897,6 +966,7 @@ public class GenericConversionServiceTests {
}
}
}
}
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
private
static
class
UntypedConverter
implements
Converter
{
private
static
class
UntypedConverter
implements
Converter
{
...
@@ -906,28 +976,27 @@ public class GenericConversionServiceTests {
...
@@ -906,28 +976,27 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
ColorConverter
implements
Converter
<
String
,
Color
>
{
private
static
class
ColorConverter
implements
Converter
<
String
,
Color
>
{
@Override
@Override
public
Color
convert
(
String
source
)
{
if
(!
source
.
startsWith
(
"#"
))
source
=
"#"
+
source
;
return
Color
.
decode
(
source
);
}
public
Color
convert
(
String
source
)
{
return
Color
.
decode
(
source
.
trim
());
}
}
}
@ExampleAnnotation
private
static
class
MyConditionalColorConverter
implements
Converter
<
String
,
Color
>,
ConditionalConverter
{
public
String
annotatedString
;
public
List
<
Integer
>
list
;
public
Map
<
String
,
Integer
>
map
;
public
Map
<
String
,
?>
wildcardMap
;
@SuppressWarnings
(
"rawtypes"
)
public
Collection
rawCollection
;
public
Collection
<?>
genericCollection
;
public
Collection
<
String
>
stringCollection
;
public
Collection
<
Integer
>
integerCollection
;
@Override
public
boolean
matches
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
ExampleAnnotation
ann
=
targetType
.
getAnnotation
(
ExampleAnnotation
.
class
);
return
(
ann
!=
null
&&
ann
.
active
());
}
@Override
public
Color
convert
(
String
source
)
{
return
Color
.
decode
(
source
.
substring
(
0
,
6
));
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录