3434import org .springframework .core .convert .ConversionService ;
3535import org .springframework .core .convert .ConverterNotFoundException ;
3636import org .springframework .core .convert .TypeDescriptor ;
37- import org .springframework .core .convert .converter .ConditionalConversion ;
37+ import org .springframework .core .convert .converter .ConditionalConverter ;
3838import org .springframework .core .convert .converter .ConditionalGenericConverter ;
3939import org .springframework .core .convert .converter .Converter ;
4040import org .springframework .core .convert .converter .ConverterFactory ;
@@ -81,8 +81,8 @@ public class GenericConversionService implements ConfigurableConversionService {
8181
8282 public void addConverter (Converter <?, ?> converter ) {
8383 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." );
8686 addConverter (new ConverterAdapter (typeInfo , converter ));
8787 }
8888
@@ -99,8 +99,9 @@ public void addConverter(GenericConverter converter) {
9999 public void addConverterFactory (ConverterFactory <?, ?> converterFactory ) {
100100 GenericConverter .ConvertiblePair typeInfo = getRequiredTypeInfo (converterFactory , ConverterFactory .class );
101101 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." );
104105 }
105106 addConverter (new ConverterFactoryAdapter (typeInfo , converterFactory ));
106107 }
@@ -114,7 +115,9 @@ public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
114115
115116 public boolean canConvert (Class <?> sourceType , Class <?> targetType ) {
116117 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 ));
118121 }
119122
120123 public boolean canConvert (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -128,8 +131,9 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
128131
129132 public boolean canBypassConvert (Class <?> sourceType , Class <?> targetType ) {
130133 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 ));
133137 }
134138
135139 public boolean canBypassConvert (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -166,8 +170,11 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
166170 }
167171
168172 /**
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)}.
171178 * @param source the source object
172179 * @param targetType the target type
173180 * @return the converted value
@@ -206,7 +213,8 @@ protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor tar
206213 * Subclasses may override.
207214 * @param sourceType the source type to convert from
208215 * @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
210218 * @see #getDefaultConverter(TypeDescriptor, TypeDescriptor)
211219 */
212220 protected GenericConverter getConverter (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -305,9 +313,8 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
305313 if (!this .typeInfo .getTargetType ().equals (targetType .getObjectType ())) {
306314 return false ;
307315 }
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 );
311318 }
312319 return true ;
313320 }
@@ -320,8 +327,9 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
320327 }
321328
322329 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 ();
325333 }
326334 }
327335
@@ -349,14 +357,13 @@ public Set<ConvertiblePair> getConvertibleTypes() {
349357
350358 public boolean matches (TypeDescriptor sourceType , TypeDescriptor targetType ) {
351359 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 );
355362 }
356363 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 );
360367 }
361368 }
362369 return matches ;
@@ -370,8 +377,9 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
370377 }
371378
372379 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 ();
375383 }
376384 }
377385
@@ -437,7 +445,7 @@ private static class Converters {
437445 public void add (GenericConverter converter ) {
438446 Set <ConvertiblePair > convertibleTypes = converter .getConvertibleTypes ();
439447 if (convertibleTypes == null ) {
440- Assert .state (converter instanceof ConditionalConversion ,
448+ Assert .state (converter instanceof ConditionalConverter ,
441449 "Only conditional converters may return null convertible types" );
442450 globalConverters .add (converter );
443451 } else {
@@ -476,7 +484,8 @@ public GenericConverter find(TypeDescriptor sourceType, TypeDescriptor targetTyp
476484 List <TypeDescriptor > targetCandidates = getTypeHierarchy (targetType );
477485 for (TypeDescriptor sourceCandidate : sourceCandidates ) {
478486 for (TypeDescriptor targetCandidate : targetCandidates ) {
479- GenericConverter converter = getRegisteredConverter (sourceType , targetType , sourceCandidate , targetCandidate );
487+ GenericConverter converter = getRegisteredConverter (
488+ sourceType , targetType , sourceCandidate , targetCandidate );
480489 if (converter != null ) {
481490 return converter ;
482491 }
@@ -499,9 +508,8 @@ private GenericConverter getRegisteredConverter(TypeDescriptor sourceType, TypeD
499508
500509 // Check ConditionalGenericConverter that match all types
501510 for (GenericConverter globalConverter : this .globalConverters ) {
502- if (((ConditionalConversion )globalConverter ).matches (
503- sourceCandidate ,
504- targetCandidate )) {
511+ if (((ConditionalConverter )globalConverter ).matches (
512+ sourceCandidate , targetCandidate )) {
505513 return globalConverter ;
506514 }
507515 }
0 commit comments