34
34
import org .springframework .core .convert .ConversionService ;
35
35
import org .springframework .core .convert .ConverterNotFoundException ;
36
36
import org .springframework .core .convert .TypeDescriptor ;
37
- import org .springframework .core .convert .converter .ConditionalConversion ;
37
+ import org .springframework .core .convert .converter .ConditionalConverter ;
38
38
import org .springframework .core .convert .converter .ConditionalGenericConverter ;
39
39
import org .springframework .core .convert .converter .Converter ;
40
40
import org .springframework .core .convert .converter .ConverterFactory ;
@@ -81,8 +81,8 @@ public class GenericConversionService implements ConfigurableConversionService {
81
81
82
82
public void addConverter (Converter <?, ?> converter ) {
83
83
GenericConverter .ConvertiblePair typeInfo = getRequiredTypeInfo (converter , Converter .class );
84
- Assert .notNull (typeInfo , "Unable to the determine sourceType <S> and targetType <T> which " +
85
- " your Converter<S, T> converts between; declare these generic types." );
84
+ Assert .notNull (typeInfo , "Unable to the determine sourceType <S> and targetType " +
85
+ "<T> which your Converter<S, T> converts between; declare these generic types." );
86
86
addConverter (new ConverterAdapter (typeInfo , converter ));
87
87
}
88
88
@@ -99,8 +99,9 @@ public void addConverter(GenericConverter converter) {
99
99
public void addConverterFactory (ConverterFactory <?, ?> converterFactory ) {
100
100
GenericConverter .ConvertiblePair typeInfo = getRequiredTypeInfo (converterFactory , ConverterFactory .class );
101
101
if (typeInfo == null ) {
102
- throw new IllegalArgumentException ("Unable to the determine sourceType <S> and targetRangeType R which " +
103
- "your ConverterFactory<S, R> converts between; declare these generic types." );
102
+ throw new IllegalArgumentException ("Unable to the determine sourceType <S> and " +
103
+ "targetRangeType R which your ConverterFactory<S, R> converts between; " +
104
+ "declare these generic types." );
104
105
}
105
106
addConverter (new ConverterFactoryAdapter (typeInfo , converterFactory ));
106
107
}
@@ -114,7 +115,9 @@ public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
114
115
115
116
public boolean canConvert (Class <?> sourceType , Class <?> targetType ) {
116
117
Assert .notNull (targetType , "The targetType to convert to cannot be null" );
117
- return canConvert (sourceType != null ? TypeDescriptor .valueOf (sourceType ) : null , TypeDescriptor .valueOf (targetType ));
118
+ return canConvert (sourceType != null ?
119
+ TypeDescriptor .valueOf (sourceType ) : null ,
120
+ TypeDescriptor .valueOf (targetType ));
118
121
}
119
122
120
123
public boolean canConvert (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -128,8 +131,9 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
128
131
129
132
public boolean canBypassConvert (Class <?> sourceType , Class <?> targetType ) {
130
133
Assert .notNull (targetType , "The targetType to convert to cannot be null" );
131
- return canBypassConvert (sourceType != null ? TypeDescriptor .valueOf (sourceType )
132
- : null , TypeDescriptor .valueOf (targetType ));
134
+ return canBypassConvert (sourceType != null ?
135
+ TypeDescriptor .valueOf (sourceType ) : null ,
136
+ TypeDescriptor .valueOf (targetType ));
133
137
}
134
138
135
139
public boolean canBypassConvert (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -166,8 +170,11 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
166
170
}
167
171
168
172
/**
169
- * Convenience operation for converting a source object to the specified targetType, where the targetType is a descriptor that provides additional conversion context.
170
- * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and encapsulates the construction of the sourceType descriptor using {@link TypeDescriptor#forObject(Object)}.
173
+ * Convenience operation for converting a source object to the specified targetType,
174
+ * where the targetType is a descriptor that provides additional conversion context.
175
+ * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and
176
+ * encapsulates the construction of the sourceType descriptor using
177
+ * {@link TypeDescriptor#forObject(Object)}.
171
178
* @param source the source object
172
179
* @param targetType the target type
173
180
* @return the converted value
@@ -206,7 +213,8 @@ protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor tar
206
213
* Subclasses may override.
207
214
* @param sourceType the source type to convert from
208
215
* @param targetType the target type to convert to
209
- * @return the generic converter that will perform the conversion, or {@code null} if no suitable converter was found
216
+ * @return the generic converter that will perform the conversion, or {@code null} if
217
+ * no suitable converter was found
210
218
* @see #getDefaultConverter(TypeDescriptor, TypeDescriptor)
211
219
*/
212
220
protected GenericConverter getConverter (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -305,9 +313,8 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
305
313
if (!this .typeInfo .getTargetType ().equals (targetType .getObjectType ())) {
306
314
return false ;
307
315
}
308
- if (this .converter instanceof ConditionalConversion ) {
309
- return ((ConditionalConversion ) this .converter ).matches (sourceType ,
310
- targetType );
316
+ if (this .converter instanceof ConditionalConverter ) {
317
+ return ((ConditionalConverter ) this .converter ).matches (sourceType , targetType );
311
318
}
312
319
return true ;
313
320
}
@@ -320,8 +327,9 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
320
327
}
321
328
322
329
public String toString () {
323
- return this .typeInfo .getSourceType ().getName () + " -> " + this .typeInfo .getTargetType ().getName () +
324
- " : " + this .converter .toString ();
330
+ return this .typeInfo .getSourceType ().getName () + " -> " +
331
+ this .typeInfo .getTargetType ().getName () + " : " +
332
+ this .converter .toString ();
325
333
}
326
334
}
327
335
@@ -349,14 +357,13 @@ public Set<ConvertiblePair> getConvertibleTypes() {
349
357
350
358
public boolean matches (TypeDescriptor sourceType , TypeDescriptor targetType ) {
351
359
boolean matches = true ;
352
- if (this .converterFactory instanceof ConditionalConversion ) {
353
- matches = ((ConditionalConversion ) this .converterFactory ).matches (
354
- sourceType , targetType );
360
+ if (this .converterFactory instanceof ConditionalConverter ) {
361
+ matches = ((ConditionalConverter ) this .converterFactory ).matches (sourceType , targetType );
355
362
}
356
363
if (matches ) {
357
- Converter <?, ?> converter = converterFactory .getConverter (targetType .getType ());
358
- if (converter instanceof ConditionalConversion ) {
359
- matches = ((ConditionalConversion ) converter ).matches (sourceType , targetType );
364
+ Converter <?, ?> converter = this . converterFactory .getConverter (targetType .getType ());
365
+ if (converter instanceof ConditionalConverter ) {
366
+ matches = ((ConditionalConverter ) converter ).matches (sourceType , targetType );
360
367
}
361
368
}
362
369
return matches ;
@@ -370,8 +377,9 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
370
377
}
371
378
372
379
public String toString () {
373
- return this .typeInfo .getSourceType ().getName () + " -> " + this .typeInfo .getTargetType ().getName () +
374
- " : " + this .converterFactory .toString ();
380
+ return this .typeInfo .getSourceType ().getName () + " -> " +
381
+ this .typeInfo .getTargetType ().getName () + " : " +
382
+ this .converterFactory .toString ();
375
383
}
376
384
}
377
385
@@ -437,7 +445,7 @@ private static class Converters {
437
445
public void add (GenericConverter converter ) {
438
446
Set <ConvertiblePair > convertibleTypes = converter .getConvertibleTypes ();
439
447
if (convertibleTypes == null ) {
440
- Assert .state (converter instanceof ConditionalConversion ,
448
+ Assert .state (converter instanceof ConditionalConverter ,
441
449
"Only conditional converters may return null convertible types" );
442
450
globalConverters .add (converter );
443
451
} else {
@@ -476,7 +484,8 @@ public GenericConverter find(TypeDescriptor sourceType, TypeDescriptor targetTyp
476
484
List <TypeDescriptor > targetCandidates = getTypeHierarchy (targetType );
477
485
for (TypeDescriptor sourceCandidate : sourceCandidates ) {
478
486
for (TypeDescriptor targetCandidate : targetCandidates ) {
479
- GenericConverter converter = getRegisteredConverter (sourceType , targetType , sourceCandidate , targetCandidate );
487
+ GenericConverter converter = getRegisteredConverter (
488
+ sourceType , targetType , sourceCandidate , targetCandidate );
480
489
if (converter != null ) {
481
490
return converter ;
482
491
}
@@ -499,9 +508,8 @@ private GenericConverter getRegisteredConverter(TypeDescriptor sourceType, TypeD
499
508
500
509
// Check ConditionalGenericConverter that match all types
501
510
for (GenericConverter globalConverter : this .globalConverters ) {
502
- if (((ConditionalConversion )globalConverter ).matches (
503
- sourceCandidate ,
504
- targetCandidate )) {
511
+ if (((ConditionalConverter )globalConverter ).matches (
512
+ sourceCandidate , targetCandidate )) {
505
513
return globalConverter ;
506
514
}
507
515
}
0 commit comments