Skip to content

Commit 234272e

Browse files
committed
Polishing
Issue: SPR-11215
1 parent 67abeb4 commit 234272e

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

spring-core/src/main/java/org/springframework/core/convert/ConversionService.java

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,36 +27,43 @@
2727
public interface ConversionService {
2828

2929
/**
30-
* Returns true if objects of sourceType can be converted to targetType.
31-
* If this method returns true, it means {@link #convert(Object, Class)} is capable of converting an instance of sourceType to targetType.
32-
* Special note on collections, arrays, and maps types:
33-
* For conversion between collection, array, and map types, this method will return 'true'
34-
* even though a convert invocation may still generate a {@link ConversionException} if the underlying elements are not convertible.
35-
* Callers are expected to handle this exceptional case when working with collections and maps.
36-
* @param sourceType the source type to convert from (may be null if source is null)
30+
* Return {@code true} if objects of {@code sourceType} can be converted to the {@code targetType}.
31+
* <p>If this method returns {@code true}, it means {@link #convert(Object, Class)} is capable
32+
* of converting an instance of {@code sourceType} to {@code targetType}.
33+
* <p>Special note on collections, arrays, and maps types:
34+
* For conversion between collection, array, and map types, this method will return {@code true}
35+
* even though a convert invocation may still generate a {@link ConversionException} if the
36+
* underlying elements are not convertible. Callers are expected to handle this exceptional case
37+
* when working with collections and maps.
38+
* @param sourceType the source type to convert from (may be {@code null} if source is {@code null})
3739
* @param targetType the target type to convert to (required)
38-
* @return true if a conversion can be performed, false if not
39-
* @throws IllegalArgumentException if targetType is null
40+
* @return {@code true} if a conversion can be performed, {@code false} if not
41+
* @throws IllegalArgumentException if {@code targetType} is {@code null}
4042
*/
4143
boolean canConvert(Class<?> sourceType, Class<?> targetType);
4244

4345
/**
44-
* Returns true if objects of sourceType can be converted to the targetType.
45-
* The TypeDescriptors provide additional context about the source and target locations where conversion would occur, often object fields or property locations.
46-
* If this method returns true, it means {@link #convert(Object, TypeDescriptor, TypeDescriptor)} is capable of converting an instance of sourceType to targetType.
47-
* Special note on collections, arrays, and maps types:
48-
* For conversion between collection, array, and map types, this method will return 'true'
49-
* even though a convert invocation may still generate a {@link ConversionException} if the underlying elements are not convertible.
50-
* Callers are expected to handle this exceptional case when working with collections and maps.
51-
* @param sourceType context about the source type to convert from (may be null if source is null)
46+
* Return {@code true} if objects of {@code sourceType} can be converted to the {@code targetType}.
47+
* The TypeDescriptors provide additional context about the source and target locations
48+
* where conversion would occur, often object fields or property locations.
49+
* <p>If this method returns {@code true}, it means {@link #convert(Object, TypeDescriptor, TypeDescriptor)}
50+
* is capable of converting an instance of {@code sourceType} to {@code targetType}.
51+
* <p>Special note on collections, arrays, and maps types:
52+
* For conversion between collection, array, and map types, this method will return {@code true}
53+
* even though a convert invocation may still generate a {@link ConversionException} if the
54+
* underlying elements are not convertible. Callers are expected to handle this exceptional case
55+
* when working with collections and maps.
56+
* @param sourceType context about the source type to convert from
57+
* (may be {@code null} if source is {@code null})
5258
* @param targetType context about the target type to convert to (required)
53-
* @return true if a conversion can be performed between the source and target types, false if not
54-
* @throws IllegalArgumentException if targetType is null
59+
* @return {@code true} if a conversion can be performed between the source and target types,
60+
* {@code false} if not
61+
* @throws IllegalArgumentException if {@code targetType} is {@code null}
5562
*/
5663
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
5764

5865
/**
59-
* Convert the source to targetType.
66+
* Convert the given {@code source} to the specified {@code targetType}.
6067
* @param source the source object to convert (may be null)
6168
* @param targetType the target type to convert to (required)
6269
* @return the converted object, an instance of targetType
@@ -66,15 +73,17 @@ public interface ConversionService {
6673
<T> T convert(Object source, Class<T> targetType);
6774

6875
/**
69-
* Convert the source to targetType.
70-
* The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object fields or property locations.
76+
* Convert the given {@code source} to the specified {@code targetType}.
77+
* The TypeDescriptors provide additional context about the source and target locations
78+
* where conversion will occur, often object fields or property locations.
7179
* @param source the source object to convert (may be null)
72-
* @param sourceType context about the source type converting from (may be null if source is null)
80+
* @param sourceType context about the source type to convert from
81+
* (may be {@code null} if source is {@code null})
7382
* @param targetType context about the target type to convert to (required)
74-
* @return the converted object, an instance of {@link TypeDescriptor#getObjectType() targetType}</code>
83+
* @return the converted object, an instance of {@link TypeDescriptor#getObjectType() targetType}
7584
* @throws ConversionException if a conversion exception occurred
76-
* @throws IllegalArgumentException if targetType is null
77-
* @throws IllegalArgumentException if sourceType is null but source is not null
85+
* @throws IllegalArgumentException if targetType is {@code null},
86+
* or {@code sourceType} is {@code null} but source is not {@code null}
7887
*/
7988
Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType);
8089

spring-expression/src/main/java/org/springframework/expression/TypeConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
/**
2222
* A type converter can convert values between different types encountered during
2323
* expression evaluation. This is an SPI for the expression parser; see
24-
* {@link org.springframework.core.convert.ConversionService} for the primary user API to
25-
* Spring's conversion facilities.
24+
* {@link org.springframework.core.convert.ConversionService} for the primary
25+
* user API to Spring's conversion facilities.
2626
*
2727
* @author Andy Clement
2828
* @author Juergen Hoeller
@@ -31,8 +31,8 @@
3131
public interface TypeConverter {
3232

3333
/**
34-
* Return true if the type converter can convert the specified type to the desired
35-
* target type.
34+
* Return {@code true} if the type converter can convert the specified type
35+
* to the desired target type.
3636
* @param sourceType a type descriptor that describes the source type
3737
* @param targetType a type descriptor that describes the requested result type
3838
* @return true if that conversion can be performed
@@ -46,9 +46,9 @@ public interface TypeConverter {
4646
* than simply a List.
4747
* @param value the value to be converted
4848
* @param sourceType a type descriptor that supplies extra information about the
49-
* source object
49+
* source object
5050
* @param targetType a type descriptor that supplies extra information about the
51-
* requested result type
51+
* requested result type
5252
* @return the converted value
5353
* @throws EvaluationException if conversion is not possible
5454
*/

spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescript
6767
try {
6868
return this.conversionService.convert(value, sourceType, targetType);
6969
}
70-
catch (ConverterNotFoundException cenfe) {
71-
throw new SpelEvaluationException(cenfe, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
70+
catch (ConverterNotFoundException ex) {
71+
throw new SpelEvaluationException(
72+
ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
7273
}
73-
catch (ConversionException ce) {
74-
throw new SpelEvaluationException(ce, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
74+
catch (ConversionException ex) {
75+
throw new SpelEvaluationException(
76+
ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
7577
}
7678
}
7779

0 commit comments

Comments
 (0)