Polishing.

Extract duplicate calls to findAnnotation(…) into static helper methods.

See #2500
This commit is contained in:
Mark Paluch
2021-12-08 10:14:58 +01:00
parent ca723d11c7
commit ef522f8e9c
4 changed files with 28 additions and 13 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.convert;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -43,7 +44,6 @@ import org.springframework.core.convert.converter.GenericConverter.ConvertiblePa
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.ConverterBuilder.ConverterAware;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.repository.RepositoryDefinition;
import org.springframework.data.util.Streamable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -760,8 +760,8 @@ public class CustomConversions {
Assert.notNull(converter, "Converter must not be null!");
Class<?> type = converter.getClass();
boolean isWriting = AnnotationUtils.findAnnotation(type, WritingConverter.class) != null;
boolean isReading = AnnotationUtils.findAnnotation(type, ReadingConverter.class) != null;
boolean isWriting = isAnnotatedWith(type, WritingConverter.class);
boolean isReading = isAnnotatedWith(type, ReadingConverter.class);
if (converter instanceof ConverterAware) {
@@ -789,6 +789,10 @@ public class CustomConversions {
}
}
private static boolean isAnnotatedWith(Class<?> type, Class<? extends Annotation> annotationType) {
return AnnotationUtils.findAnnotation(type, annotationType) != null;
}
private Streamable<ConverterRegistration> getRegistrationFor(Object converter, Class<?> type, boolean isReading,
boolean isWriting) {