Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
4d9bf3a4
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,发现更多精彩内容 >>
提交
4d9bf3a4
编写于
10月 14, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removed valueOf convention b/c of unwanted side effects
上级
dc076ee6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
5 addition
and
46 deletion
+5
-46
org.springframework.context/src/main/java/org/springframework/ui/format/support/GenericFormatterRegistry.java
...framework/ui/format/support/GenericFormatterRegistry.java
+2
-34
org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java
...ingframework/ui/format/GenericFormatterRegistryTests.java
+3
-4
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java
...amework/core/convert/support/ObjectToStringConverter.java
+0
-8
未找到文件。
org.springframework.context/src/main/java/org/springframework/ui/format/support/GenericFormatterRegistry.java
浏览文件 @
4d9bf3a4
...
...
@@ -277,7 +277,7 @@ public class GenericFormatterRegistry implements FormatterRegistry, ApplicationC
}
else
{
Formatted
formattedAnnotation
=
annotationType
.
getAnnotation
(
Formatted
.
class
);
if
(
formattedAnnotation
!=
null
)
{
// annotation has @Formatted meta-annotation
//
property
annotation has @Formatted meta-annotation
Formatter
formatter
=
createFormatter
(
formattedAnnotation
.
value
());
addFormatterByAnnotation
(
annotationType
,
formatter
);
return
findFormatterHolderForAnnotation
(
annotation
);
...
...
@@ -315,14 +315,7 @@ public class GenericFormatterRegistry implements FormatterRegistry, ApplicationC
addFormatterByType
(
type
,
formatter
);
return
findFormatterHolderForType
(
type
);
}
else
{
Method
valueOfMethod
=
getValueOfMethod
(
type
);
if
(
valueOfMethod
!=
null
)
{
Formatter
formatter
=
createFormatter
(
valueOfMethod
);
addFormatterByType
(
type
,
formatter
);
return
findFormatterHolderForType
(
type
);
}
else
{
return
null
;
}
return
null
;
}
}
...
...
@@ -331,31 +324,6 @@ public class GenericFormatterRegistry implements FormatterRegistry, ApplicationC
formatterClass
)
:
BeanUtils
.
instantiate
(
formatterClass
));
}
private
Method
getValueOfMethod
(
Class
type
)
{
Method
[]
methods
=
type
.
getDeclaredMethods
();
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
Method
method
=
methods
[
i
];
if
(
"valueOf"
.
equals
(
method
.
getName
())
&&
acceptsSingleStringParameterType
(
method
)
&&
Modifier
.
isPublic
(
method
.
getModifiers
())
&&
Modifier
.
isStatic
(
method
.
getModifiers
()))
{
return
method
;
}
}
return
null
;
}
private
boolean
acceptsSingleStringParameterType
(
Method
method
)
{
Class
[]
paramTypes
=
method
.
getParameterTypes
();
if
(
paramTypes
==
null
)
{
return
false
;
}
else
{
return
paramTypes
.
length
==
1
&&
paramTypes
[
0
]
==
String
.
class
;
}
}
private
Formatter
createFormatter
(
Method
valueOfMethod
)
{
return
new
ValueOfMethodFormatter
(
valueOfMethod
);
}
private
abstract
static
class
AbstractFormatterHolder
{
private
Class
formattedObjectType
;
...
...
org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java
浏览文件 @
4d9bf3a4
...
...
@@ -17,6 +17,7 @@
package
org.springframework.ui.format
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
...
...
@@ -104,10 +105,8 @@ public class GenericFormatterRegistryTests {
}
@Test
public
void
testGetDefaultFormatterForTypeValueOfMethod
()
throws
ParseException
{
Formatter
formatter
=
registry
.
getFormatter
(
TypeDescriptor
.
valueOf
(
Integer
.
class
));
assertEquals
(
"3"
,
formatter
.
format
(
new
Integer
(
3
),
null
));
assertEquals
(
new
Integer
(
3
),
formatter
.
parse
(
"3"
,
null
));
public
void
testGetDefaultFormatterNull
()
throws
ParseException
{
assertNull
(
registry
.
getFormatter
(
TypeDescriptor
.
valueOf
(
Integer
.
class
)));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java
浏览文件 @
4d9bf3a4
...
...
@@ -28,14 +28,6 @@ import org.springframework.core.convert.converter.Converter;
*/
final
class
ObjectToStringConverter
implements
Converter
<
Object
,
String
>
{
public
Class
<?>
getSourceType
()
{
return
Object
.
class
;
}
public
Class
<?>
getTargetType
()
{
return
String
.
class
;
}
public
String
convert
(
Object
source
)
{
return
source
.
toString
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录