Reintroduce explicit local variable types.

We now reinstate local variable types instead of var as general var usage removes contextual detail that cannot be omitted generally.

See #2465
This commit is contained in:
Mark Paluch
2022-03-28 08:55:29 +02:00
parent c85c4ef2ed
commit 0e5e869cbf
249 changed files with 1662 additions and 1507 deletions

View File

@@ -53,8 +53,8 @@ public class ConfigurableTypeInformationMapper implements TypeInformationMapper
for (Entry<? extends Class<?>, String> entry : sourceTypeMap.entrySet()) {
var type = ClassTypeInformation.from(entry.getKey());
var alias = Alias.of(entry.getValue());
ClassTypeInformation<?> type = ClassTypeInformation.from(entry.getKey());
Alias alias = Alias.of(entry.getValue());
if (typeToAlias.containsValue(alias)) {
throw new IllegalArgumentException(

View File

@@ -116,7 +116,7 @@ public class CustomConversions {
this.converterConfiguration = converterConfiguration;
var registeredConverters = collectPotentialConverterRegistrations(
List<Object> registeredConverters = collectPotentialConverterRegistrations(
converterConfiguration.getStoreConversions(), converterConfiguration.getUserConverters()).stream() //
.filter(this::isSupportedConverter) //
.filter(this::shouldRegister) //
@@ -289,7 +289,7 @@ public class CustomConversions {
Assert.notNull(converterRegistration, "Converter registration must not be null!");
var pair = converterRegistration.getConvertiblePair();
ConvertiblePair pair = converterRegistration.getConvertiblePair();
if (converterRegistration.isReading()) {
@@ -324,7 +324,7 @@ public class CustomConversions {
*/
private boolean isSupportedConverter(ConverterRegistrationIntent registrationIntent) {
var register = registrationIntent.isUserConverter() || registrationIntent.isStoreConverter()
boolean register = registrationIntent.isUserConverter() || registrationIntent.isStoreConverter()
|| (registrationIntent.isReading() && registrationIntent.isSimpleSourceType())
|| (registrationIntent.isWriting() && registrationIntent.isSimpleTargetType());
@@ -365,7 +365,7 @@ public class CustomConversions {
Assert.notNull(sourceType, "Source type must not be null!");
var target = customWriteTargetTypes.computeIfAbsent(sourceType, getRawWriteTarget);
Class<?> target = customWriteTargetTypes.computeIfAbsent(sourceType, getRawWriteTarget);
return Void.class.equals(target) || target == null ? Optional.empty() : Optional.of(target);
}
@@ -384,7 +384,7 @@ public class CustomConversions {
Assert.notNull(sourceType, "Source type must not be null!");
Assert.notNull(requestedTargetType, "Target type must not be null!");
var target = customWriteTargetTypes.computeIfAbsent(sourceType, requestedTargetType, getWriteTarget);
Class<?> target = customWriteTargetTypes.computeIfAbsent(sourceType, requestedTargetType, getWriteTarget);
return Void.class.equals(target) || target == null ? Optional.empty() : Optional.of(target);
}
@@ -464,13 +464,13 @@ public class CustomConversions {
return targetType;
}
for (var pair : pairs) {
for (ConvertiblePair pair : pairs) {
if (!hasAssignableSourceType(pair, sourceType)) {
continue;
}
var candidate = pair.getTargetType();
Class<?> candidate = pair.getTargetType();
if (!requestedTargetTypeIsAssignable(targetType, candidate)) {
continue;
@@ -527,7 +527,7 @@ public class CustomConversions {
public Class<?> computeIfAbsent(Class<?> sourceType, Class<?> targetType,
Function<ConvertiblePair, Class<?>> mappingFunction) {
var targetTypes = customReadTargetTypes.get(sourceType);
TargetTypes targetTypes = customReadTargetTypes.get(sourceType);
if (targetTypes == null) {
targetTypes = customReadTargetTypes.computeIfAbsent(sourceType, TargetTypes::new);
@@ -568,7 +568,7 @@ public class CustomConversions {
@Nullable
public Class<?> computeIfAbsent(Class<?> targetType, Function<ConvertiblePair, Class<?>> mappingFunction) {
var optionalTarget = conversionTargets.get(targetType);
Class<?> optionalTarget = conversionTargets.get(targetType);
if (optionalTarget == null) {
optionalTarget = mappingFunction.apply(new ConvertiblePair(sourceType, targetType));
@@ -794,9 +794,9 @@ public class CustomConversions {
Assert.notNull(converter, "Converter must not be null!");
var type = converter.getClass();
var isWriting = isAnnotatedWith(type, WritingConverter.class);
var isReading = isAnnotatedWith(type, ReadingConverter.class);
Class<?> type = converter.getClass();
boolean isWriting = isAnnotatedWith(type, WritingConverter.class);
boolean isReading = isAnnotatedWith(type, ReadingConverter.class);
if (converter instanceof ConverterAware) {
@@ -805,7 +805,7 @@ public class CustomConversions {
} else if (converter instanceof GenericConverter) {
var convertibleTypes = GenericConverter.class.cast(converter).getConvertibleTypes();
Set<ConvertiblePair> convertibleTypes = GenericConverter.class.cast(converter).getConvertibleTypes();
return convertibleTypes == null //
? Streamable.empty() //
@@ -831,8 +831,8 @@ public class CustomConversions {
private Streamable<ConverterRegistration> getRegistrationFor(Object converter, Class<?> type, boolean isReading,
boolean isWriting) {
var converterType = converter.getClass();
var arguments = GenericTypeResolver.resolveTypeArguments(converterType, type);
Class<?> converterType = converter.getClass();
Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converterType, type);
if (arguments == null) {
throw new IllegalStateException(String.format("Couldn't resolve type arguments for %s!", converterType));
@@ -883,7 +883,7 @@ public class CustomConversions {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(storeTypeHolder);
int result = ObjectUtils.nullSafeHashCode(storeTypeHolder);
result = 31 * result + ObjectUtils.nullSafeHashCode(storeConverters);
return result;
}

View File

@@ -142,7 +142,7 @@ record DefaultConverterBuilder<S, T> (ConvertiblePair convertiblePair,
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(convertiblePair);
int result = ObjectUtils.nullSafeHashCode(convertiblePair);
result = 31 * result + ObjectUtils.nullSafeHashCode(function);
return result;
}

View File

@@ -96,8 +96,8 @@ public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware
this.typeCache = new ConcurrentHashMap<>();
this.getAlias = key -> {
for (var mapper : mappers) {
var typeInformation = mapper.resolveTypeFrom(key);
for (TypeInformationMapper mapper : mappers) {
TypeInformation<?> typeInformation = mapper.resolveTypeFrom(key);
if (typeInformation != null) {
return Optional.of(typeInformation);
@@ -126,7 +126,7 @@ public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware
@Nullable
private TypeInformation<?> getFromCacheOrCreate(Alias alias) {
var typeInformation = typeCache.get(alias);
Optional<TypeInformation<?>> typeInformation = typeCache.get(alias);
if (typeInformation == null) {
typeInformation = typeCache.computeIfAbsent(alias, getAlias);
@@ -141,22 +141,22 @@ public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware
Assert.notNull(source, "Source must not be null!");
Assert.notNull(basicType, "Basic type must not be null!");
var documentsTargetType = getDefaultedTypeToBeUsed(source);
Class<?> documentsTargetType = getDefaultedTypeToBeUsed(source);
if (documentsTargetType == null) {
return basicType;
}
var rawType = basicType.getType();
Class<T> rawType = basicType.getType();
var isMoreConcreteCustomType = rawType == null
boolean isMoreConcreteCustomType = rawType == null
|| rawType.isAssignableFrom(documentsTargetType) && !rawType.equals(documentsTargetType);
if (!isMoreConcreteCustomType) {
return basicType;
}
var targetType = ClassTypeInformation.from(documentsTargetType);
ClassTypeInformation<?> targetType = ClassTypeInformation.from(documentsTargetType);
return (TypeInformation<? extends T>) basicType.specialize(targetType);
}
@@ -171,7 +171,7 @@ public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware
@Nullable
private Class<?> getDefaultedTypeToBeUsed(S source) {
var documentsTargetTypeInformation = readType(source);
TypeInformation<?> documentsTargetTypeInformation = readType(source);
documentsTargetTypeInformation = documentsTargetTypeInformation == null ? getFallbackTypeFor(source)
: documentsTargetTypeInformation;
return documentsTargetTypeInformation == null ? null : documentsTargetTypeInformation.getType();
@@ -198,7 +198,7 @@ public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware
Assert.notNull(info, "TypeInformation must not be null!");
var alias = getAliasFor(info);
Alias alias = getAliasFor(info);
if (alias.isPresent()) {
accessor.writeTypeTo(sink, alias.getValue());
}
@@ -226,7 +226,7 @@ public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware
for (TypeInformationMapper mapper : mappers) {
var alias = mapper.createAliasFor(info);
Alias alias = mapper.createAliasFor(info);
if (alias.isPresent()) {
return alias;
}

View File

@@ -16,9 +16,11 @@
package org.springframework.data.convert;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.EntityInstantiator;
@@ -73,18 +75,19 @@ public class DtoInstantiatingConverter implements Converter<Object, Object> {
return source;
}
var sourceEntity = context.getRequiredPersistentEntity(source.getClass());
var sourceAccessor = sourceEntity.getPropertyAccessor(source);
var targetEntity = context.getRequiredPersistentEntity(targetType);
PersistentEntity<?, ? extends PersistentProperty<?>> sourceEntity = context
.getRequiredPersistentEntity(source.getClass());
PersistentPropertyAccessor<Object> sourceAccessor = sourceEntity.getPropertyAccessor(source);
PersistentEntity<?, ? extends PersistentProperty<?>> targetEntity = context.getRequiredPersistentEntity(targetType);
@SuppressWarnings({ "rawtypes", "unchecked" })
var dto = instantiator.createInstance(targetEntity, new ParameterValueProvider() {
Object dto = instantiator.createInstance(targetEntity, new ParameterValueProvider() {
@Override
@Nullable
public Object getParameterValue(Parameter parameter) {
var name = parameter.getName();
String name = parameter.getName();
if (name == null) {
throw new IllegalArgumentException(String.format("Parameter %s does not have a name", parameter));
@@ -94,8 +97,8 @@ public class DtoInstantiatingConverter implements Converter<Object, Object> {
}
});
var targetAccessor = targetEntity.getPropertyAccessor(dto);
var creator = targetEntity.getInstanceCreatorMetadata();
PersistentPropertyAccessor<Object> targetAccessor = targetEntity.getPropertyAccessor(dto);
InstanceCreatorMetadata<? extends PersistentProperty<?>> creator = targetEntity.getInstanceCreatorMetadata();
targetEntity.doWithProperties((SimplePropertyHandler) property -> {

View File

@@ -54,10 +54,11 @@ public class JMoleculesConverters {
List<Object> converters = new ArrayList<>();
var conversionService = (Supplier<ConversionService>) () -> DefaultConversionService.getSharedInstance();
Supplier<ConversionService> conversionService = (Supplier<ConversionService>) () -> DefaultConversionService
.getSharedInstance();
var toPrimitives = new IdentifierToPrimitivesConverter(conversionService);
var toIdentifier = new PrimitivesToIdentifierConverter(conversionService);
IdentifierToPrimitivesConverter toPrimitives = new IdentifierToPrimitivesConverter(conversionService);
PrimitivesToIdentifierConverter toIdentifier = new PrimitivesToIdentifierConverter(conversionService);
converters.add(toPrimitives);
converters.add(toIdentifier);

View File

@@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.data.mapping.Alias;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
@@ -61,7 +62,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
return typeMap.computeIfAbsent(type.getRawTypeInformation(), key -> {
var entity = mappingContext.getPersistentEntity(key);
PersistentEntity<?, ? extends PersistentProperty<?>> entity = mappingContext.getPersistentEntity(key);
if (entity == null || entity.getTypeAlias() == null) {
return Alias.NONE;
@@ -81,7 +82,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
// Reject second alias for same type
var existingAlias = typeMap.getOrDefault(key, Alias.NONE);
Alias existingAlias = typeMap.getOrDefault(key, Alias.NONE);
if (existingAlias.isPresentButDifferent(alias)) {
@@ -111,7 +112,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
@Override
public TypeInformation<?> resolveTypeFrom(Alias alias) {
for (var entry : typeMap.entrySet()) {
for (Map.Entry<ClassTypeInformation<?>, Alias> entry : typeMap.entrySet()) {
if (entry.getValue().hasSamePresentValueAs(alias)) {
return entry.getKey();
}

View File

@@ -53,7 +53,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper, BeanC
@Override
public TypeInformation<?> resolveTypeFrom(Alias alias) {
var stringAlias = alias.mapTyped(String.class);
String stringAlias = alias.mapTyped(String.class);
if (stringAlias != null) {
return cache.computeIfAbsent(stringAlias, this::loadClass).orElse(null);