Browse Source

Migrate code to Java 17 style.

Use var instead of explicit local types where applicable. Use pattern variable instead instanceof and cast. Prefer loops and nullable types over Stream and Optional. Convert classes to records where applicable.

See #2465
pull/2538/head
Mark Paluch 4 years ago committed by Jens Schauder
parent
commit
c735b58607
No known key found for this signature in database
GPG Key ID: 45CC872F17423DBF
  1. 2
      src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java
  2. 12
      src/main/java/org/springframework/data/auditing/AuditingHandlerSupport.java
  3. 2
      src/main/java/org/springframework/data/auditing/Auditor.java
  4. 8
      src/main/java/org/springframework/data/auditing/DefaultAuditableBeanWrapperFactory.java
  5. 3
      src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java
  6. 6
      src/main/java/org/springframework/data/auditing/MappingAuditableBeanWrapperFactory.java
  7. 3
      src/main/java/org/springframework/data/auditing/ReactiveIsNewAwareAuditingHandler.java
  8. 3
      src/main/java/org/springframework/data/auditing/config/AnnotationAuditingConfiguration.java
  9. 8
      src/main/java/org/springframework/data/auditing/config/AuditingBeanDefinitionRegistrarSupport.java
  10. 8
      src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java
  11. 10
      src/main/java/org/springframework/data/config/BeanComponentDefinitionBuilder.java
  12. 6
      src/main/java/org/springframework/data/config/ConfigurationUtils.java
  13. 8
      src/main/java/org/springframework/data/config/ParsingUtils.java
  14. 30
      src/main/java/org/springframework/data/config/TypeFilterParser.java
  15. 4
      src/main/java/org/springframework/data/convert/ConfigurableTypeInformationMapper.java
  16. 35
      src/main/java/org/springframework/data/convert/CustomConversions.java
  17. 20
      src/main/java/org/springframework/data/convert/DefaultConverterBuilder.java
  18. 20
      src/main/java/org/springframework/data/convert/DefaultTypeMapper.java
  19. 6
      src/main/java/org/springframework/data/convert/JMoleculesConverters.java
  20. 38
      src/main/java/org/springframework/data/convert/Jsr310Converters.java
  21. 7
      src/main/java/org/springframework/data/convert/MappingContextTypeInformationMapper.java
  22. 2
      src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java
  23. 4
      src/main/java/org/springframework/data/crossstore/HashMapChangeSet.java
  24. 6
      src/main/java/org/springframework/data/domain/AbstractPageRequest.java
  25. 10
      src/main/java/org/springframework/data/domain/Chunk.java
  26. 17
      src/main/java/org/springframework/data/domain/ExampleMatcher.java
  27. 10
      src/main/java/org/springframework/data/domain/PageImpl.java
  28. 4
      src/main/java/org/springframework/data/domain/PageRequest.java
  29. 12
      src/main/java/org/springframework/data/domain/Range.java
  30. 10
      src/main/java/org/springframework/data/domain/SliceImpl.java
  31. 20
      src/main/java/org/springframework/data/domain/Sort.java
  32. 5
      src/main/java/org/springframework/data/domain/TypedExample.java
  33. 20
      src/main/java/org/springframework/data/domain/TypedExampleMatcher.java
  34. 7
      src/main/java/org/springframework/data/domain/jaxb/OrderAdapter.java
  35. 2
      src/main/java/org/springframework/data/domain/jaxb/PageAdapter.java
  36. 6
      src/main/java/org/springframework/data/domain/jaxb/PageableAdapter.java
  37. 2
      src/main/java/org/springframework/data/domain/jaxb/SortAdapter.java
  38. 4
      src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java
  39. 6
      src/main/java/org/springframework/data/geo/Box.java
  40. 6
      src/main/java/org/springframework/data/geo/Circle.java
  41. 14
      src/main/java/org/springframework/data/geo/Distance.java
  42. 4
      src/main/java/org/springframework/data/geo/GeoPage.java
  43. 6
      src/main/java/org/springframework/data/geo/GeoResult.java
  44. 8
      src/main/java/org/springframework/data/geo/GeoResults.java
  45. 8
      src/main/java/org/springframework/data/geo/Point.java
  46. 3
      src/main/java/org/springframework/data/geo/Polygon.java
  47. 4
      src/main/java/org/springframework/data/geo/format/DistanceFormatter.java
  48. 6
      src/main/java/org/springframework/data/geo/format/PointFormatter.java
  49. 6
      src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java
  50. 6
      src/main/java/org/springframework/data/history/Revision.java
  51. 2
      src/main/java/org/springframework/data/history/RevisionSort.java
  52. 2
      src/main/java/org/springframework/data/history/Revisions.java
  53. 4
      src/main/java/org/springframework/data/mapping/AccessOptions.java
  54. 3
      src/main/java/org/springframework/data/mapping/Alias.java
  55. 2
      src/main/java/org/springframework/data/mapping/IdentifierAccessor.java
  56. 10
      src/main/java/org/springframework/data/mapping/PersistentEntity.java
  57. 12
      src/main/java/org/springframework/data/mapping/PersistentProperty.java
  58. 22
      src/main/java/org/springframework/data/mapping/PersistentPropertyAccessor.java
  59. 2
      src/main/java/org/springframework/data/mapping/PersistentPropertyPath.java
  60. 18
      src/main/java/org/springframework/data/mapping/PreferredConstructor.java
  61. 43
      src/main/java/org/springframework/data/mapping/PropertyPath.java
  62. 6
      src/main/java/org/springframework/data/mapping/PropertyReferenceException.java
  63. 2
      src/main/java/org/springframework/data/mapping/TargetAwareIdentifierAccessor.java
  64. 4
      src/main/java/org/springframework/data/mapping/TraversalContext.java
  65. 22
      src/main/java/org/springframework/data/mapping/callback/DefaultEntityCallbacks.java
  66. 20
      src/main/java/org/springframework/data/mapping/callback/DefaultReactiveEntityCallbacks.java
  67. 31
      src/main/java/org/springframework/data/mapping/callback/EntityCallbackDiscoverer.java
  68. 2
      src/main/java/org/springframework/data/mapping/callback/EntityCallbackInvoker.java
  69. 4
      src/main/java/org/springframework/data/mapping/callback/EntityCallbacks.java
  70. 4
      src/main/java/org/springframework/data/mapping/callback/ReactiveEntityCallbacks.java
  71. 54
      src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
  72. 19
      src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java
  73. 4
      src/main/java/org/springframework/data/mapping/context/InvalidPersistentPropertyPath.java
  74. 6
      src/main/java/org/springframework/data/mapping/context/MappingContext.java
  75. 28
      src/main/java/org/springframework/data/mapping/context/PersistentEntities.java
  76. 50
      src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java
  77. 16
      src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java
  78. 24
      src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
  79. 25
      src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java
  80. 21
      src/main/java/org/springframework/data/mapping/model/BeanWrapper.java
  81. 6
      src/main/java/org/springframework/data/mapping/model/CamelCaseSplittingFieldNamingStrategy.java
  82. 43
      src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java
  83. 153
      src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java
  84. 2
      src/main/java/org/springframework/data/mapping/model/ConvertingPropertyAccessor.java
  85. 3
      src/main/java/org/springframework/data/mapping/model/DefaultSpELExpressionEvaluator.java
  86. 4
      src/main/java/org/springframework/data/mapping/model/EntityInstantiators.java
  87. 10
      src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java
  88. 48
      src/main/java/org/springframework/data/mapping/model/KotlinClassGeneratingEntityInstantiator.java
  89. 48
      src/main/java/org/springframework/data/mapping/model/KotlinCopyMethod.java
  90. 10
      src/main/java/org/springframework/data/mapping/model/KotlinDefaultMask.java
  91. 7
      src/main/java/org/springframework/data/mapping/model/MappingInstantiationException.java
  92. 4
      src/main/java/org/springframework/data/mapping/model/PersistentEntityIsNewStrategy.java
  93. 7
      src/main/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProvider.java
  94. 22
      src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java
  95. 10
      src/main/java/org/springframework/data/mapping/model/Property.java
  96. 12
      src/main/java/org/springframework/data/mapping/model/ReflectionEntityInstantiator.java
  97. 28
      src/main/java/org/springframework/data/mapping/model/SimplePersistentPropertyPathAccessor.java
  98. 11
      src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java
  99. 2
      src/main/java/org/springframework/data/mapping/model/SpELContext.java
  100. 2
      src/main/java/org/springframework/data/mapping/model/SpELExpressionParameterValueProvider.java
  101. Some files were not shown because too many files have changed in this diff Show More

2
src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java

@ -101,7 +101,7 @@ final class AnnotationAuditingMetadata { @@ -101,7 +101,7 @@ final class AnnotationAuditingMetadata {
return;
}
Class<?> type = it.getType();
var type = it.getType();
if (Jsr310Converters.supports(type)) {
return;

12
src/main/java/org/springframework/data/auditing/AuditingHandlerSupport.java

@ -107,7 +107,7 @@ public abstract class AuditingHandlerSupport { @@ -107,7 +107,7 @@ public abstract class AuditingHandlerSupport {
* @param auditor can be {@literal null}.
* @param source must not be {@literal null}.
*/
<T> T markCreated(Auditor auditor, T source) {
<T> T markCreated(Auditor<?> auditor, T source) {
Assert.notNull(source, "Source entity must not be null!");
@ -120,16 +120,16 @@ public abstract class AuditingHandlerSupport { @@ -120,16 +120,16 @@ public abstract class AuditingHandlerSupport {
* @param auditor
* @param source
*/
<T> T markModified(Auditor auditor, T source) {
<T> T markModified(Auditor<?> auditor, T source) {
Assert.notNull(source, "Source entity must not be null!");
return touch(auditor, source, false);
}
private <T> T touch(Auditor auditor, T target, boolean isNew) {
private <T> T touch(Auditor<?> auditor, T target, boolean isNew) {
Optional<AuditableBeanWrapper<T>> wrapper = factory.getBeanWrapperFor(target);
var wrapper = factory.getBeanWrapperFor(target);
return wrapper.map(it -> {
@ -157,7 +157,7 @@ public abstract class AuditingHandlerSupport { @@ -157,7 +157,7 @@ public abstract class AuditingHandlerSupport {
* @param isNew
* @return
*/
private void touchAuditor(Auditor auditor, AuditableBeanWrapper<?> wrapper, boolean isNew) {
private void touchAuditor(Auditor<?> auditor, AuditableBeanWrapper<?> wrapper, boolean isNew) {
if(!auditor.isPresent()) {
return;
@ -185,7 +185,7 @@ public abstract class AuditingHandlerSupport { @@ -185,7 +185,7 @@ public abstract class AuditingHandlerSupport {
Assert.notNull(wrapper, "AuditableBeanWrapper must not be null!");
Optional<TemporalAccessor> now = dateTimeProvider.getNow();
var now = dateTimeProvider.getNow();
Assert.notNull(now, () -> String.format("Now must not be null! Returned by: %s!", dateTimeProvider.getClass()));

2
src/main/java/org/springframework/data/auditing/Auditor.java

@ -110,7 +110,7 @@ class Auditor<T> { @@ -110,7 +110,7 @@ class Auditor<T> {
if (o == null || getClass() != o.getClass())
return false;
Auditor<?> auditor = (Auditor<?>) o;
var auditor = (Auditor<?>) o;
return ObjectUtils.nullSafeEquals(value, auditor.value);
}

8
src/main/java/org/springframework/data/auditing/DefaultAuditableBeanWrapperFactory.java

@ -46,7 +46,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory @@ -46,7 +46,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
public DefaultAuditableBeanWrapperFactory() {
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
var conversionService = new DefaultFormattingConversionService();
Jsr310Converters.getConvertersToRegister().forEach(conversionService::addConverter);
@ -75,7 +75,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory @@ -75,7 +75,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
return (AuditableBeanWrapper<T>) new AuditableInterfaceBeanWrapper(conversionService, (Auditable<Object, ?, TemporalAccessor>) it);
}
AnnotationAuditingMetadata metadata = AnnotationAuditingMetadata.getMetadata(it.getClass());
var metadata = AnnotationAuditingMetadata.getMetadata(it.getClass());
if (metadata.isAuditable()) {
return new ReflectionAuditingBeanWrapper<T>(conversionService, it);
@ -215,7 +215,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory @@ -215,7 +215,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
value.getClass(), targetType));
}
Date date = conversionService.convert(value, Date.class);
var date = conversionService.convert(value, Date.class);
return conversionService.convert(date, targetType);
}
@ -317,7 +317,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory @@ -317,7 +317,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
return getAsTemporalAccessor(metadata.getLastModifiedDateField().map(field -> {
Object value = org.springframework.util.ReflectionUtils.getField(field, target);
var value = org.springframework.util.ReflectionUtils.getField(field, target);
return value instanceof Optional ? ((Optional<?>) value).orElse(null) : value;
}), TemporalAccessor.class);

3
src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.data.auditing;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.support.IsNewStrategy;
@ -62,7 +61,7 @@ public class IsNewAwareAuditingHandler extends AuditingHandler { @@ -62,7 +61,7 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
return object;
}
PersistentEntity<?, ? extends PersistentProperty<?>> entity = entities
var entity = entities
.getRequiredPersistentEntity(object.getClass());
return entity.isNew(object) ? markCreated(object) : markModified(object);

6
src/main/java/org/springframework/data/auditing/MappingAuditableBeanWrapperFactory.java

@ -85,7 +85,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap @@ -85,7 +85,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
return entities.mapOnContext(it.getClass(), (context, entity) -> {
MappingAuditingMetadata metadata = metadataCache.computeIfAbsent(it.getClass(),
var metadata = metadataCache.computeIfAbsent(it.getClass(),
key -> new MappingAuditingMetadata(context, it.getClass()));
return Optional.<AuditableBeanWrapper<T>> ofNullable(metadata.isAuditable() //
@ -229,7 +229,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap @@ -229,7 +229,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
@Override
public Optional<TemporalAccessor> getLastModifiedDate() {
Optional<Object> firstValue = metadata.lastModifiedDatePaths.getFirst() //
var firstValue = metadata.lastModifiedDatePaths.getFirst() //
.map(accessor::getProperty);
return getAsTemporalAccessor(firstValue, TemporalAccessor.class);
@ -266,7 +266,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap @@ -266,7 +266,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
property.forEach(it -> {
Class<?> type = it.getRequiredLeafProperty().getType();
var type = it.getRequiredLeafProperty().getType();
this.accessor.setProperty(it, getDateValueToSet(value, type, accessor.getBean()), OPTIONS);
});

3
src/main/java/org/springframework/data/auditing/ReactiveIsNewAwareAuditingHandler.java

@ -18,7 +18,6 @@ package org.springframework.data.auditing; @@ -18,7 +18,6 @@ package org.springframework.data.auditing;
import reactor.core.publisher.Mono;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.support.IsNewStrategy;
@ -62,7 +61,7 @@ public class ReactiveIsNewAwareAuditingHandler extends ReactiveAuditingHandler { @@ -62,7 +61,7 @@ public class ReactiveIsNewAwareAuditingHandler extends ReactiveAuditingHandler {
return Mono.just(object);
}
PersistentEntity<?, ? extends PersistentProperty<?>> entity = entities
var entity = entities
.getRequiredPersistentEntity(object.getClass());
return entity.isNew(object) ? markCreated(object) : markModified(object);

3
src/main/java/org/springframework/data/auditing/config/AnnotationAuditingConfiguration.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.data.auditing.config;
import java.lang.annotation.Annotation;
import java.util.Map;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
@ -47,7 +46,7 @@ public class AnnotationAuditingConfiguration implements AuditingConfiguration { @@ -47,7 +46,7 @@ public class AnnotationAuditingConfiguration implements AuditingConfiguration {
Assert.notNull(metadata, "AnnotationMetadata must not be null!");
Assert.notNull(annotation, "Annotation must not be null!");
Map<String, Object> attributesSource = metadata.getAnnotationAttributes(annotation.getName());
var attributesSource = metadata.getAnnotationAttributes(annotation.getName());
if (attributesSource == null) {
throw new IllegalArgumentException(String.format(MISSING_ANNOTATION_ATTRIBUTES, annotation, metadata));

8
src/main/java/org/springframework/data/auditing/config/AuditingBeanDefinitionRegistrarSupport.java

@ -60,7 +60,7 @@ public abstract class AuditingBeanDefinitionRegistrarSupport implements ImportBe @@ -60,7 +60,7 @@ public abstract class AuditingBeanDefinitionRegistrarSupport implements ImportBe
Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null!");
Assert.notNull(registry, "BeanDefinitionRegistry must not be null!");
AbstractBeanDefinition ahbd = registerAuditHandlerBeanDefinition(registry, getConfiguration(annotationMetadata));
var ahbd = registerAuditHandlerBeanDefinition(registry, getConfiguration(annotationMetadata));
registerAuditListenerBeanDefinition(ahbd, registry);
}
@ -77,7 +77,7 @@ public abstract class AuditingBeanDefinitionRegistrarSupport implements ImportBe @@ -77,7 +77,7 @@ public abstract class AuditingBeanDefinitionRegistrarSupport implements ImportBe
Assert.notNull(registry, "BeanDefinitionRegistry must not be null!");
Assert.notNull(configuration, "AuditingConfiguration must not be null!");
AbstractBeanDefinition ahbd = getAuditHandlerBeanDefinitionBuilder(configuration).getBeanDefinition();
var ahbd = getAuditHandlerBeanDefinitionBuilder(configuration).getBeanDefinition();
registry.registerBeanDefinition(getAuditingHandlerBeanName(), ahbd);
return ahbd;
}
@ -178,10 +178,10 @@ public abstract class AuditingBeanDefinitionRegistrarSupport implements ImportBe @@ -178,10 +178,10 @@ public abstract class AuditingBeanDefinitionRegistrarSupport implements ImportBe
private BeanDefinition createLazyInitTargetSourceBeanDefinition(String auditorAwareRef) {
BeanDefinitionBuilder targetSourceBuilder = rootBeanDefinition(LazyInitTargetSource.class);
var targetSourceBuilder = rootBeanDefinition(LazyInitTargetSource.class);
targetSourceBuilder.addPropertyValue("targetBeanName", auditorAwareRef);
BeanDefinitionBuilder builder = rootBeanDefinition(ProxyFactoryBean.class);
var builder = rootBeanDefinition(ProxyFactoryBean.class);
builder.addPropertyValue("targetSource", targetSourceBuilder.getBeanDefinition());
return builder.getBeanDefinition();

8
src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java

@ -95,11 +95,11 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin @@ -95,11 +95,11 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
final BeanDefinitionBuilder persistentEntities = rootBeanDefinition(PersistentEntitiesFactoryBean.class);
final var persistentEntities = rootBeanDefinition(PersistentEntitiesFactoryBean.class);
persistentEntities.addConstructorArgReference(mappingContextBeanName);
builder.addConstructorArgValue(persistentEntities.getBeanDefinition());
String auditorAwareRef = element.getAttribute(AUDITOR_AWARE_REF);
var auditorAwareRef = element.getAttribute(AUDITOR_AWARE_REF);
if (StringUtils.hasText(auditorAwareRef)) {
builder.addPropertyValue("auditorAware", createLazyInitTargetSourceBeanDefinition(auditorAwareRef));
@ -123,10 +123,10 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin @@ -123,10 +123,10 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
private BeanDefinition createLazyInitTargetSourceBeanDefinition(String auditorAwareRef) {
BeanDefinitionBuilder targetSourceBuilder = rootBeanDefinition(LazyInitTargetSource.class);
var targetSourceBuilder = rootBeanDefinition(LazyInitTargetSource.class);
targetSourceBuilder.addPropertyValue("targetBeanName", auditorAwareRef);
BeanDefinitionBuilder builder = rootBeanDefinition(ProxyFactoryBean.class);
var builder = rootBeanDefinition(ProxyFactoryBean.class);
builder.addPropertyValue("targetSource", targetSourceBuilder.getBeanDefinition());
return builder.getBeanDefinition();

10
src/main/java/org/springframework/data/config/BeanComponentDefinitionBuilder.java

@ -16,12 +16,12 @@ @@ -16,12 +16,12 @@
package org.springframework.data.config;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
@ -60,8 +60,8 @@ public class BeanComponentDefinitionBuilder { @@ -60,8 +60,8 @@ public class BeanComponentDefinitionBuilder {
Assert.notNull(builder, "Builder must not be null!");
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
String name = BeanDefinitionReaderUtils.generateBeanName(definition, context.getRegistry(), context.isNested());
var definition = builder.getRawBeanDefinition();
var name = BeanDefinitionReaderUtils.generateBeanName(definition, context.getRegistry(), context.isNested());
return getComponent(builder, name);
}
@ -78,7 +78,7 @@ public class BeanComponentDefinitionBuilder { @@ -78,7 +78,7 @@ public class BeanComponentDefinitionBuilder {
Assert.hasText(fallback, "Fallback component id must not be null or empty!");
String id = defaultSource.getAttribute("id");
var id = defaultSource.getAttribute("id");
return getComponent(builder, StringUtils.hasText(id) ? id : fallback);
}
@ -107,7 +107,7 @@ public class BeanComponentDefinitionBuilder { @@ -107,7 +107,7 @@ public class BeanComponentDefinitionBuilder {
Assert.notNull(builder, "Builder must not be null!");
Assert.hasText(name, "Name of bean must not be null or empty!");
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
var definition = builder.getRawBeanDefinition();
definition.setSource(context.extractSource(rawSource));
return new BeanComponentDefinition(definition, name);

6
src/main/java/org/springframework/data/config/ConfigurationUtils.java

@ -41,7 +41,7 @@ public interface ConfigurationUtils { @@ -41,7 +41,7 @@ public interface ConfigurationUtils {
Assert.notNull(context, "XmlReaderContext must not be null!");
ResourceLoader resourceLoader = context.getResourceLoader();
var resourceLoader = context.getResourceLoader();
if (resourceLoader == null) {
throw new IllegalArgumentException("Could not obtain ResourceLoader from XmlReaderContext!");
@ -72,7 +72,7 @@ public interface ConfigurationUtils { @@ -72,7 +72,7 @@ public interface ConfigurationUtils {
Assert.notNull(resourceLoader, "ResourceLoader must not be null!");
ClassLoader classLoader = resourceLoader.getClassLoader();
var classLoader = resourceLoader.getClassLoader();
if (classLoader == null) {
throw new IllegalArgumentException("Could not obtain ClassLoader from ResourceLoader!");
@ -92,7 +92,7 @@ public interface ConfigurationUtils { @@ -92,7 +92,7 @@ public interface ConfigurationUtils {
Assert.notNull(beanDefinition, "BeanDefinition must not be null!");
String result = beanDefinition.getBeanClassName();
var result = beanDefinition.getBeanClassName();
if (result == null) {
throw new IllegalArgumentException(

8
src/main/java/org/springframework/data/config/ParsingUtils.java

@ -55,7 +55,7 @@ public abstract class ParsingUtils { @@ -55,7 +55,7 @@ public abstract class ParsingUtils {
Assert.hasText(attrName, "Attribute name must not be null!");
Assert.hasText(propertyName, "Property name must not be null!");
String attr = element.getAttribute(attrName);
var attr = element.getAttribute(attrName);
if (StringUtils.hasText(attr)) {
builder.addPropertyValue(propertyName, attr);
@ -90,7 +90,7 @@ public abstract class ParsingUtils { @@ -90,7 +90,7 @@ public abstract class ParsingUtils {
Assert.hasText(attribute, "Attribute name must not be null!");
Assert.hasText(property, "Property name must not be null!");
String value = element.getAttribute(attribute);
var value = element.getAttribute(attribute);
if (StringUtils.hasText(value)) {
builder.addPropertyReference(property, value);
@ -126,7 +126,7 @@ public abstract class ParsingUtils { @@ -126,7 +126,7 @@ public abstract class ParsingUtils {
Assert.notNull(builder, "Builder must not be null!");
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
var definition = builder.getRawBeanDefinition();
definition.setSource(source);
return definition;
}
@ -143,7 +143,7 @@ public abstract class ParsingUtils { @@ -143,7 +143,7 @@ public abstract class ParsingUtils {
Assert.hasText(targetBeanName, "Target bean name must not be null or empty!");
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ObjectFactoryCreatingFactoryBean.class);
var builder = BeanDefinitionBuilder.rootBeanDefinition(ObjectFactoryCreatingFactoryBean.class);
builder.addPropertyValue("targetBeanName", targetBeanName);
builder.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE);

30
src/main/java/org/springframework/data/config/TypeFilterParser.java

@ -32,9 +32,9 @@ import org.springframework.core.type.filter.RegexPatternTypeFilter; @@ -32,9 +32,9 @@ import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Parser to populate the given {@link ClassPathScanningCandidateComponentProvider} with {@link TypeFilter}s parsed from
@ -85,13 +85,13 @@ public class TypeFilterParser { @@ -85,13 +85,13 @@ public class TypeFilterParser {
*/
public Collection<TypeFilter> parseTypeFilters(Element element, Type type) {
NodeList nodeList = element.getChildNodes();
var nodeList = element.getChildNodes();
Collection<TypeFilter> filters = new HashSet<>();
for (int i = 0; i < nodeList.getLength(); i++) {
for (var i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element childElement = type.getElement(node);
var node = nodeList.item(i);
var childElement = type.getElement(node);
if (childElement == null) {
continue;
@ -116,12 +116,12 @@ public class TypeFilterParser { @@ -116,12 +116,12 @@ public class TypeFilterParser {
*/
protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) {
String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
var filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
var expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
try {
FilterType filter = FilterType.fromString(filterType);
var filter = FilterType.fromString(filterType);
return filter.getFilter(expression, classLoader);
} catch (ClassNotFoundException ex) {
@ -136,7 +136,7 @@ public class TypeFilterParser { @@ -136,7 +136,7 @@ public class TypeFilterParser {
* @author Oliver Gierke
* @see #getFilter(String, ClassLoader)
*/
private static enum FilterType {
private enum FilterType {
ANNOTATION {
@Override
@ -171,7 +171,7 @@ public class TypeFilterParser { @@ -171,7 +171,7 @@ public class TypeFilterParser {
@Override
public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException {
Class<?> filterClass = classLoader.loadClass(expression);
var filterClass = classLoader.loadClass(expression);
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
throw new IllegalArgumentException(
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
@ -199,7 +199,7 @@ public class TypeFilterParser { @@ -199,7 +199,7 @@ public class TypeFilterParser {
*/
static FilterType fromString(String typeString) {
for (FilterType filter : FilterType.values()) {
for (var filter : FilterType.values()) {
if (filter.name().equalsIgnoreCase(typeString)) {
return filter;
}
@ -209,13 +209,13 @@ public class TypeFilterParser { @@ -209,13 +209,13 @@ public class TypeFilterParser {
}
}
public static enum Type {
public enum Type {
INCLUDE("include-filter"), EXCLUDE("exclude-filter");
private String elementName;
private final String elementName;
private Type(String elementName) {
Type(String elementName) {
this.elementName = elementName;
}
@ -230,7 +230,7 @@ public class TypeFilterParser { @@ -230,7 +230,7 @@ public class TypeFilterParser {
Element getElement(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String localName = node.getLocalName();
var localName = node.getLocalName();
if (elementName.equals(localName)) {
return (Element) node;
}

4
src/main/java/org/springframework/data/convert/ConfigurableTypeInformationMapper.java

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

35
src/main/java/org/springframework/data/convert/CustomConversions.java

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

20
src/main/java/org/springframework/data/convert/DefaultConverterBuilder.java

@ -44,20 +44,10 @@ import org.springframework.util.ObjectUtils; @@ -44,20 +44,10 @@ import org.springframework.util.ObjectUtils;
* @soundtrack John Mayer - Still Feel Like Your Man (The Search for Everything)
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
class DefaultConverterBuilder<S, T>
record DefaultConverterBuilder<S, T> (ConvertiblePair convertiblePair,
Optional<Function<? super S, ? extends T>> writing, Optional<Function<? super T, ? extends S>> reading)
implements ConverterAware, ReadingConverterBuilder<T, S>, WritingConverterBuilder<S, T> {
private final ConvertiblePair convertiblePair;
private final Optional<Function<? super S, ? extends T>> writing;
private final Optional<Function<? super T, ? extends S>> reading;
DefaultConverterBuilder(ConvertiblePair convertiblePair, Optional<Function<? super S, ? extends T>> writing,
Optional<Function<? super T, ? extends S>> reading) {
this.convertiblePair = convertiblePair;
this.writing = writing;
this.reading = reading;
}
/*
* (non-Javadoc)
* @see org.springframework.data.convert.WritingConverterBuilder#andReading(java.util.function.Function)
@ -172,12 +162,10 @@ class DefaultConverterBuilder<S, T> @@ -172,12 +162,10 @@ class DefaultConverterBuilder<S, T>
return true;
}
if (!(o instanceof ConfigurableGenericConverter)) {
if (!(o instanceof ConfigurableGenericConverter<?, ?> that)) {
return false;
}
ConfigurableGenericConverter<?, ?> that = (ConfigurableGenericConverter<?, ?>) o;
if (!ObjectUtils.nullSafeEquals(convertiblePair, that.convertiblePair)) {
return false;
}
@ -191,7 +179,7 @@ class DefaultConverterBuilder<S, T> @@ -191,7 +179,7 @@ class DefaultConverterBuilder<S, T>
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(convertiblePair);
var result = ObjectUtils.nullSafeHashCode(convertiblePair);
result = 31 * result + ObjectUtils.nullSafeHashCode(function);
return result;
}

20
src/main/java/org/springframework/data/convert/DefaultTypeMapper.java

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

6
src/main/java/org/springframework/data/convert/JMoleculesConverters.java

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

38
src/main/java/org/springframework/data/convert/Jsr310Converters.java

@ -87,7 +87,7 @@ public abstract class Jsr310Converters { @@ -87,7 +87,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
public enum DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
INSTANCE;
@ -99,7 +99,7 @@ public abstract class Jsr310Converters { @@ -99,7 +99,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum LocalDateTimeToDateConverter implements Converter<LocalDateTime, Date> {
public enum LocalDateTimeToDateConverter implements Converter<LocalDateTime, Date> {
INSTANCE;
@ -111,7 +111,7 @@ public abstract class Jsr310Converters { @@ -111,7 +111,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum DateToLocalDateConverter implements Converter<Date, LocalDate> {
public enum DateToLocalDateConverter implements Converter<Date, LocalDate> {
INSTANCE;
@ -123,7 +123,7 @@ public abstract class Jsr310Converters { @@ -123,7 +123,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum LocalDateToDateConverter implements Converter<LocalDate, Date> {
public enum LocalDateToDateConverter implements Converter<LocalDate, Date> {
INSTANCE;
@ -135,7 +135,7 @@ public abstract class Jsr310Converters { @@ -135,7 +135,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum DateToLocalTimeConverter implements Converter<Date, LocalTime> {
public enum DateToLocalTimeConverter implements Converter<Date, LocalTime> {
INSTANCE;
@ -147,7 +147,7 @@ public abstract class Jsr310Converters { @@ -147,7 +147,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum LocalTimeToDateConverter implements Converter<LocalTime, Date> {
public enum LocalTimeToDateConverter implements Converter<LocalTime, Date> {
INSTANCE;
@ -159,7 +159,7 @@ public abstract class Jsr310Converters { @@ -159,7 +159,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum DateToInstantConverter implements Converter<Date, Instant> {
public enum DateToInstantConverter implements Converter<Date, Instant> {
INSTANCE;
@ -171,7 +171,7 @@ public abstract class Jsr310Converters { @@ -171,7 +171,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum InstantToDateConverter implements Converter<Instant, Date> {
public enum InstantToDateConverter implements Converter<Instant, Date> {
INSTANCE;
@ -183,7 +183,7 @@ public abstract class Jsr310Converters { @@ -183,7 +183,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum LocalDateTimeToInstantConverter implements Converter<LocalDateTime, Instant> {
public enum LocalDateTimeToInstantConverter implements Converter<LocalDateTime, Instant> {
INSTANCE;
@ -195,7 +195,7 @@ public abstract class Jsr310Converters { @@ -195,7 +195,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum InstantToLocalDateTimeConverter implements Converter<Instant, LocalDateTime> {
public enum InstantToLocalDateTimeConverter implements Converter<Instant, LocalDateTime> {
INSTANCE;
@ -207,7 +207,7 @@ public abstract class Jsr310Converters { @@ -207,7 +207,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum ZoneIdToStringConverter implements Converter<ZoneId, String> {
public enum ZoneIdToStringConverter implements Converter<ZoneId, String> {
INSTANCE;
@ -219,7 +219,7 @@ public abstract class Jsr310Converters { @@ -219,7 +219,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum StringToZoneIdConverter implements Converter<String, ZoneId> {
public enum StringToZoneIdConverter implements Converter<String, ZoneId> {
INSTANCE;
@ -231,7 +231,7 @@ public abstract class Jsr310Converters { @@ -231,7 +231,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum DurationToStringConverter implements Converter<Duration, String> {
public enum DurationToStringConverter implements Converter<Duration, String> {
INSTANCE;
@ -243,7 +243,7 @@ public abstract class Jsr310Converters { @@ -243,7 +243,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum StringToDurationConverter implements Converter<String, Duration> {
public enum StringToDurationConverter implements Converter<String, Duration> {
INSTANCE;
@ -255,7 +255,7 @@ public abstract class Jsr310Converters { @@ -255,7 +255,7 @@ public abstract class Jsr310Converters {
}
@WritingConverter
public static enum PeriodToStringConverter implements Converter<Period, String> {
public enum PeriodToStringConverter implements Converter<Period, String> {
INSTANCE;
@ -267,7 +267,7 @@ public abstract class Jsr310Converters { @@ -267,7 +267,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum StringToPeriodConverter implements Converter<String, Period> {
public enum StringToPeriodConverter implements Converter<String, Period> {
INSTANCE;
@ -279,7 +279,7 @@ public abstract class Jsr310Converters { @@ -279,7 +279,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum StringToLocalDateConverter implements Converter<String, LocalDate> {
public enum StringToLocalDateConverter implements Converter<String, LocalDate> {
INSTANCE;
@ -295,7 +295,7 @@ public abstract class Jsr310Converters { @@ -295,7 +295,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {
public enum StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {
INSTANCE;
@ -311,7 +311,7 @@ public abstract class Jsr310Converters { @@ -311,7 +311,7 @@ public abstract class Jsr310Converters {
}
@ReadingConverter
public static enum StringToInstantConverter implements Converter<String, Instant> {
public enum StringToInstantConverter implements Converter<String, Instant> {
INSTANCE;

7
src/main/java/org/springframework/data/convert/MappingContextTypeInformationMapper.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.data.convert;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.data.mapping.Alias;
@ -66,7 +65,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe @@ -66,7 +65,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
return typeMap.computeIfAbsent(type.getRawTypeInformation(), key -> {
PersistentEntity<?, ?> entity = mappingContext.getPersistentEntity(key);
var entity = mappingContext.getPersistentEntity(key);
if (entity == null || entity.getTypeAlias() == null) {
return Alias.NONE;
@ -86,7 +85,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe @@ -86,7 +85,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
// Reject second alias for same type
Alias existingAlias = typeMap.getOrDefault(key, Alias.NONE);
var existingAlias = typeMap.getOrDefault(key, Alias.NONE);
if (existingAlias.isPresentButDifferent(alias)) {
@ -120,7 +119,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe @@ -120,7 +119,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
@Override
public TypeInformation<?> resolveTypeFrom(Alias alias) {
for (Entry<ClassTypeInformation<?>, Alias> entry : typeMap.entrySet()) {
for (var entry : typeMap.entrySet()) {
if (entry.getValue().hasSamePresentValueAs(alias)) {
return entry.getKey();
}

2
src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java

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

4
src/main/java/org/springframework/data/crossstore/HashMapChangeSet.java

@ -24,7 +24,7 @@ import org.springframework.lang.Nullable; @@ -24,7 +24,7 @@ import org.springframework.lang.Nullable;
/**
* Simple ChangeSet implementation backed by a HashMap.
*
*
* @author Thomas Risberg
* @author Rod Johnson
* @author Christoph Strobl
@ -61,7 +61,7 @@ public class HashMapChangeSet implements ChangeSet { @@ -61,7 +61,7 @@ public class HashMapChangeSet implements ChangeSet {
@Nullable
public <T> T get(String key, Class<T> requiredClass, ConversionService conversionService) {
Object value = values.get(key);
var value = values.get(key);
if (value == null) {
return null;

6
src/main/java/org/springframework/data/domain/AbstractPageRequest.java

@ -118,8 +118,8 @@ public abstract class AbstractPageRequest implements Pageable, Serializable { @@ -118,8 +118,8 @@ public abstract class AbstractPageRequest implements Pageable, Serializable {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
final var prime = 31;
var result = 1;
result = prime * result + page;
result = prime * result + size;
@ -142,7 +142,7 @@ public abstract class AbstractPageRequest implements Pageable, Serializable { @@ -142,7 +142,7 @@ public abstract class AbstractPageRequest implements Pageable, Serializable {
return false;
}
AbstractPageRequest other = (AbstractPageRequest) obj;
var other = (AbstractPageRequest) obj;
return this.page == other.page && this.size == other.size;
}
}

10
src/main/java/org/springframework/data/domain/Chunk.java

@ -184,14 +184,12 @@ abstract class Chunk<T> implements Slice<T>, Serializable { @@ -184,14 +184,12 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
return true;
}
if (!(obj instanceof Chunk<?>)) {
if (!(obj instanceof Chunk<?> that)) {
return false;
}
Chunk<?> that = (Chunk<?>) obj;
boolean contentEqual = this.content.equals(that.content);
boolean pageableEqual = this.pageable.equals(that.pageable);
var contentEqual = this.content.equals(that.content);
var pageableEqual = this.pageable.equals(that.pageable);
return contentEqual && pageableEqual;
}
@ -203,7 +201,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable { @@ -203,7 +201,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
@Override
public int hashCode() {
int result = 17;
var result = 17;
result += 31 * pageable.hashCode();
result += 31 * content.hashCode();

17
src/main/java/org/springframework/data/domain/ExampleMatcher.java

@ -124,7 +124,7 @@ public interface ExampleMatcher { @@ -124,7 +124,7 @@ public interface ExampleMatcher {
Assert.hasText(propertyPath, "PropertyPath must not be empty!");
Assert.notNull(matcherConfigurer, "MatcherConfigurer must not be empty!");
GenericPropertyMatcher genericPropertyMatcher = new GenericPropertyMatcher();
var genericPropertyMatcher = new GenericPropertyMatcher();
matcherConfigurer.configureMatcher(genericPropertyMatcher);
return withMatcher(propertyPath, genericPropertyMatcher);
@ -451,12 +451,10 @@ public interface ExampleMatcher { @@ -451,12 +451,10 @@ public interface ExampleMatcher {
return true;
}
if (!(o instanceof GenericPropertyMatcher)) {
if (!(o instanceof GenericPropertyMatcher that)) {
return false;
}
GenericPropertyMatcher that = (GenericPropertyMatcher) o;
if (stringMatcher != that.stringMatcher)
return false;
@ -473,7 +471,7 @@ public interface ExampleMatcher { @@ -473,7 +471,7 @@ public interface ExampleMatcher {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(stringMatcher);
var result = ObjectUtils.nullSafeHashCode(stringMatcher);
result = 31 * result + ObjectUtils.nullSafeHashCode(ignoreCase);
result = 31 * result + ObjectUtils.nullSafeHashCode(valueTransformer);
return result;
@ -751,12 +749,10 @@ public interface ExampleMatcher { @@ -751,12 +749,10 @@ public interface ExampleMatcher {
return true;
}
if (!(o instanceof PropertySpecifier)) {
if (!(o instanceof PropertySpecifier that)) {
return false;
}
PropertySpecifier that = (PropertySpecifier) o;
if (!ObjectUtils.nullSafeEquals(path, that.path)) {
return false;
}
@ -777,7 +773,7 @@ public interface ExampleMatcher { @@ -777,7 +773,7 @@ public interface ExampleMatcher {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(path);
var result = ObjectUtils.nullSafeHashCode(path);
result = 31 * result + ObjectUtils.nullSafeHashCode(stringMatcher);
result = 31 * result + ObjectUtils.nullSafeHashCode(ignoreCase);
result = 31 * result + ObjectUtils.nullSafeHashCode(valueTransformer);
@ -840,11 +836,10 @@ public interface ExampleMatcher { @@ -840,11 +836,10 @@ public interface ExampleMatcher {
return true;
}
if (!(o instanceof PropertySpecifiers)) {
if (!(o instanceof PropertySpecifiers that)) {
return false;
}
PropertySpecifiers that = (PropertySpecifiers) o;
return ObjectUtils.nullSafeEquals(propertySpecifiers, that.propertySpecifiers);
}

10
src/main/java/org/springframework/data/domain/PageImpl.java

@ -113,8 +113,8 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> { @@ -113,8 +113,8 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
@Override
public String toString() {
String contentType = "UNKNOWN";
List<T> content = getContent();
var contentType = "UNKNOWN";
var content = getContent();
if (!content.isEmpty() && content.get(0) != null) {
contentType = content.get(0).getClass().getName();
@ -134,12 +134,10 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> { @@ -134,12 +134,10 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
return true;
}
if (!(obj instanceof PageImpl<?>)) {
if (!(obj instanceof PageImpl<?> that)) {
return false;
}
PageImpl<?> that = (PageImpl<?>) obj;
return this.total == that.total && super.equals(obj);
}
@ -150,7 +148,7 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> { @@ -150,7 +148,7 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
@Override
public int hashCode() {
int result = 17;
var result = 17;
result += 31 * (int) (total ^ total >>> 32);
result += 31 * super.hashCode();

4
src/main/java/org/springframework/data/domain/PageRequest.java

@ -142,12 +142,10 @@ public class PageRequest extends AbstractPageRequest { @@ -142,12 +142,10 @@ public class PageRequest extends AbstractPageRequest {
return true;
}
if (!(obj instanceof PageRequest)) {
if (!(obj instanceof PageRequest that)) {
return false;
}
PageRequest that = (PageRequest) obj;
return super.equals(that) && this.sort.equals(that.sort);
}

12
src/main/java/org/springframework/data/domain/Range.java

@ -226,12 +226,10 @@ public final class Range<T extends Comparable<T>> { @@ -226,12 +226,10 @@ public final class Range<T extends Comparable<T>> {
return true;
}
if (!(o instanceof Range)) {
if (!(o instanceof Range<?> range)) {
return false;
}
Range<?> range = (Range<?>) o;
if (!ObjectUtils.nullSafeEquals(lowerBound, range.lowerBound)) {
return false;
}
@ -245,7 +243,7 @@ public final class Range<T extends Comparable<T>> { @@ -245,7 +243,7 @@ public final class Range<T extends Comparable<T>> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(lowerBound);
var result = ObjectUtils.nullSafeHashCode(lowerBound);
result = 31 * result + ObjectUtils.nullSafeHashCode(upperBound);
return result;
}
@ -436,12 +434,10 @@ public final class Range<T extends Comparable<T>> { @@ -436,12 +434,10 @@ public final class Range<T extends Comparable<T>> {
return true;
}
if (!(o instanceof Bound)) {
if (!(o instanceof Bound<?> bound)) {
return false;
}
Bound<?> bound = (Bound<?>) o;
if (inclusive != bound.inclusive)
return false;
@ -454,7 +450,7 @@ public final class Range<T extends Comparable<T>> { @@ -454,7 +450,7 @@ public final class Range<T extends Comparable<T>> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(value);
var result = ObjectUtils.nullSafeHashCode(value);
result = 31 * result + (inclusive ? 1 : 0);
return result;
}

10
src/main/java/org/springframework/data/domain/SliceImpl.java

@ -83,8 +83,8 @@ public class SliceImpl<T> extends Chunk<T> { @@ -83,8 +83,8 @@ public class SliceImpl<T> extends Chunk<T> {
@Override
public String toString() {
String contentType = "UNKNOWN";
List<T> content = getContent();
var contentType = "UNKNOWN";
var content = getContent();
if (content.size() > 0) {
contentType = content.get(0).getClass().getName();
@ -104,12 +104,10 @@ public class SliceImpl<T> extends Chunk<T> { @@ -104,12 +104,10 @@ public class SliceImpl<T> extends Chunk<T> {
return true;
}
if (!(obj instanceof SliceImpl<?>)) {
if (!(obj instanceof SliceImpl<?> that)) {
return false;
}
SliceImpl<?> that = (SliceImpl<?>) obj;
return this.hasNext == that.hasNext && super.equals(obj);
}
@ -120,7 +118,7 @@ public class SliceImpl<T> extends Chunk<T> { @@ -120,7 +118,7 @@ public class SliceImpl<T> extends Chunk<T> {
@Override
public int hashCode() {
int result = 17;
var result = 17;
result += 31 * (hasNext ? 1 : 0);
result += 31 * super.hashCode();

20
src/main/java/org/springframework/data/domain/Sort.java

@ -193,9 +193,9 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -193,9 +193,9 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
Assert.notNull(sort, "Sort must not be null!");
ArrayList<Order> these = new ArrayList<>(this.toList());
var these = new ArrayList<Order>(this.toList());
for (Order order : sort) {
for (var order : sort) {
these.add(order);
}
@ -211,7 +211,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -211,7 +211,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Nullable
public Order getOrderFor(String property) {
for (Order order : this) {
for (var order : this) {
if (order.getProperty().equals(property)) {
return order;
}
@ -239,12 +239,10 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -239,12 +239,10 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
return true;
}
if (!(obj instanceof Sort)) {
if (!(obj instanceof Sort that)) {
return false;
}
Sort that = (Sort) obj;
return toList().equals(that.toList());
}
@ -255,7 +253,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -255,7 +253,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Override
public int hashCode() {
int result = 17;
var result = 17;
result = 31 * result + orders.hashCode();
return result;
}
@ -607,7 +605,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -607,7 +605,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Override
public int hashCode() {
int result = 17;
var result = 17;
result = 31 * result + direction.hashCode();
result = 31 * result + property.hashCode();
@ -628,12 +626,10 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -628,12 +626,10 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
return true;
}
if (!(obj instanceof Order)) {
if (!(obj instanceof Order that)) {
return false;
}
Order that = (Order) obj;
return this.direction.equals(that.direction) && this.property.equals(that.property)
&& this.ignoreCase == that.ignoreCase && this.nullHandling.equals(that.nullHandling);
}
@ -645,7 +641,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord @@ -645,7 +641,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Override
public String toString() {
String result = String.format("%s: %s", property, direction);
var result = String.format("%s: %s", property, direction);
if (!NullHandling.NATIVE.equals(nullHandling)) {
result += ", " + nullHandling;

5
src/main/java/org/springframework/data/domain/TypedExample.java

@ -57,11 +57,10 @@ class TypedExample<T> implements Example<T> { @@ -57,11 +57,10 @@ class TypedExample<T> implements Example<T> {
return true;
}
if (!(o instanceof TypedExample)) {
if (!(o instanceof TypedExample<?> that)) {
return false;
}
TypedExample<?> that = (TypedExample<?>) o;
if (!ObjectUtils.nullSafeEquals(probe, that.probe)) {
return false;
}
@ -75,7 +74,7 @@ class TypedExample<T> implements Example<T> { @@ -75,7 +74,7 @@ class TypedExample<T> implements Example<T> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(probe);
var result = ObjectUtils.nullSafeHashCode(probe);
result = 31 * result + ObjectUtils.nullSafeHashCode(matcher);
return result;
}

20
src/main/java/org/springframework/data/domain/TypedExampleMatcher.java

@ -105,8 +105,8 @@ class TypedExampleMatcher implements ExampleMatcher { @@ -105,8 +105,8 @@ class TypedExampleMatcher implements ExampleMatcher {
Assert.hasText(propertyPath, "PropertyPath must not be empty!");
Assert.notNull(genericPropertyMatcher, "GenericPropertyMatcher must not be empty!");
PropertySpecifiers propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
PropertySpecifier propertySpecifier = new PropertySpecifier(propertyPath);
var propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
var propertySpecifier = new PropertySpecifier(propertyPath);
if (genericPropertyMatcher.ignoreCase != null) {
propertySpecifier = propertySpecifier.withIgnoreCase(genericPropertyMatcher.ignoreCase);
@ -134,8 +134,8 @@ class TypedExampleMatcher implements ExampleMatcher { @@ -134,8 +134,8 @@ class TypedExampleMatcher implements ExampleMatcher {
Assert.hasText(propertyPath, "PropertyPath must not be empty!");
Assert.notNull(propertyValueTransformer, "PropertyValueTransformer must not be empty!");
PropertySpecifiers propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
PropertySpecifier propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
var propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
var propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
propertySpecifiers.add(propertySpecifier.withValueTransformer(propertyValueTransformer));
@ -153,10 +153,10 @@ class TypedExampleMatcher implements ExampleMatcher { @@ -153,10 +153,10 @@ class TypedExampleMatcher implements ExampleMatcher {
Assert.notEmpty(propertyPaths, "PropertyPaths must not be empty!");
Assert.noNullElements(propertyPaths, "PropertyPaths must not contain null elements!");
PropertySpecifiers propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
var propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
for (String propertyPath : propertyPaths) {
PropertySpecifier propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
for (var propertyPath : propertyPaths) {
var propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
propertySpecifiers.add(propertySpecifier.withIgnoreCase(true));
}
@ -256,12 +256,10 @@ class TypedExampleMatcher implements ExampleMatcher { @@ -256,12 +256,10 @@ class TypedExampleMatcher implements ExampleMatcher {
return true;
}
if (!(o instanceof TypedExampleMatcher)) {
if (!(o instanceof TypedExampleMatcher that)) {
return false;
}
TypedExampleMatcher that = (TypedExampleMatcher) o;
if (defaultIgnoreCase != that.defaultIgnoreCase) {
return false;
}
@ -292,7 +290,7 @@ class TypedExampleMatcher implements ExampleMatcher { @@ -292,7 +290,7 @@ class TypedExampleMatcher implements ExampleMatcher {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(nullHandler);
var result = ObjectUtils.nullSafeHashCode(nullHandler);
result = 31 * result + ObjectUtils.nullSafeHashCode(defaultStringMatcher);
result = 31 * result + ObjectUtils.nullSafeHashCode(propertySpecifiers);
result = 31 * result + ObjectUtils.nullSafeHashCode(ignoredPaths);

7
src/main/java/org/springframework/data/domain/jaxb/OrderAdapter.java

@ -17,7 +17,6 @@ package org.springframework.data.domain.jaxb; @@ -17,7 +17,6 @@ package org.springframework.data.domain.jaxb;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.domain.jaxb.SpringDataJaxb.OrderDto;
import org.springframework.lang.Nullable;
@ -43,7 +42,7 @@ public class OrderAdapter extends XmlAdapter<OrderDto, Order> { @@ -43,7 +42,7 @@ public class OrderAdapter extends XmlAdapter<OrderDto, Order> {
return null;
}
OrderDto dto = new OrderDto();
var dto = new OrderDto();
dto.direction = order.getDirection();
dto.property = order.getProperty();
return dto;
@ -61,8 +60,8 @@ public class OrderAdapter extends XmlAdapter<OrderDto, Order> { @@ -61,8 +60,8 @@ public class OrderAdapter extends XmlAdapter<OrderDto, Order> {
return null;
}
Direction direction = source.direction;
String property = source.property;
var direction = source.direction;
var property = source.property;
if (direction == null || property == null) {
return null;

2
src/main/java/org/springframework/data/domain/jaxb/PageAdapter.java

@ -44,7 +44,7 @@ public class PageAdapter extends XmlAdapter<PageDto, Page<Object>> { @@ -44,7 +44,7 @@ public class PageAdapter extends XmlAdapter<PageDto, Page<Object>> {
return null;
}
PageDto dto = new PageDto();
var dto = new PageDto();
dto.content = source.getContent();
dto.add(getLinks(source));

6
src/main/java/org/springframework/data/domain/jaxb/PageableAdapter.java

@ -46,9 +46,9 @@ class PageableAdapter extends XmlAdapter<PageRequestDto, Pageable> { @@ -46,9 +46,9 @@ class PageableAdapter extends XmlAdapter<PageRequestDto, Pageable> {
return null;
}
PageRequestDto dto = new PageRequestDto();
var dto = new PageRequestDto();
SortDto sortDto = SortAdapter.INSTANCE.marshal(request.getSort());
var sortDto = SortAdapter.INSTANCE.marshal(request.getSort());
dto.orders = sortDto == null ? Collections.emptyList() : sortDto.orders;
dto.page = request.getPageNumber();
dto.size = request.getPageSize();
@ -72,7 +72,7 @@ class PageableAdapter extends XmlAdapter<PageRequestDto, Pageable> { @@ -72,7 +72,7 @@ class PageableAdapter extends XmlAdapter<PageRequestDto, Pageable> {
return PageRequest.of(v.page, v.size);
}
SortDto sortDto = new SortDto();
var sortDto = new SortDto();
sortDto.orders = v.orders;
return PageRequest.of(v.page, v.size, SortAdapter.INSTANCE.unmarshal(sortDto));

2
src/main/java/org/springframework/data/domain/jaxb/SortAdapter.java

@ -43,7 +43,7 @@ public class SortAdapter extends XmlAdapter<SortDto, Sort> { @@ -43,7 +43,7 @@ public class SortAdapter extends XmlAdapter<SortDto, Sort> {
return null;
}
SortDto dto = new SortDto();
var dto = new SortDto();
dto.orders = SpringDataJaxb.marshal(source, OrderAdapter.INSTANCE);
return dto;

4
src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java

@ -119,7 +119,7 @@ public abstract class SpringDataJaxb { @@ -119,7 +119,7 @@ public abstract class SpringDataJaxb {
List<T> result = new ArrayList<>(source.size());
for (S element : source) {
for (var element : source) {
try {
result.add(adapter.unmarshal(element));
} catch (Exception o_O) {
@ -146,7 +146,7 @@ public abstract class SpringDataJaxb { @@ -146,7 +146,7 @@ public abstract class SpringDataJaxb {
List<S> result = new ArrayList<>();
for (T element : source) {
for (var element : source) {
try {
result.add(adapter.marshal(element));
} catch (Exception o_O) {

6
src/main/java/org/springframework/data/geo/Box.java

@ -97,7 +97,7 @@ public class Box implements Shape { @@ -97,7 +97,7 @@ public class Box implements Shape {
@Override
public int hashCode() {
int result = 31;
var result = 31;
result += 17 * first.hashCode();
result += 17 * second.hashCode();
@ -116,12 +116,10 @@ public class Box implements Shape { @@ -116,12 +116,10 @@ public class Box implements Shape {
return true;
}
if (!(obj instanceof Box)) {
if (!(obj instanceof Box that)) {
return false;
}
Box that = (Box) obj;
return this.first.equals(that.first) && this.second.equals(that.second);
}
}

6
src/main/java/org/springframework/data/geo/Circle.java

@ -102,12 +102,10 @@ public class Circle implements Shape { @@ -102,12 +102,10 @@ public class Circle implements Shape {
return true;
}
if (!(o instanceof Circle)) {
if (!(o instanceof Circle circle)) {
return false;
}
Circle circle = (Circle) o;
if (!ObjectUtils.nullSafeEquals(center, circle.center)) {
return false;
}
@ -121,7 +119,7 @@ public class Circle implements Shape { @@ -121,7 +119,7 @@ public class Circle implements Shape {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(center);
var result = ObjectUtils.nullSafeHashCode(center);
result = 31 * result + ObjectUtils.nullSafeHashCode(radius);
return result;
}

14
src/main/java/org/springframework/data/geo/Distance.java

@ -121,7 +121,7 @@ public final class Distance implements Serializable, Comparable<Distance> { @@ -121,7 +121,7 @@ public final class Distance implements Serializable, Comparable<Distance> {
Assert.notNull(other, "Distance to add must not be null!");
double newNormalizedValue = getNormalizedValue() + other.getNormalizedValue();
var newNormalizedValue = getNormalizedValue() + other.getNormalizedValue();
return new Distance(newNormalizedValue * metric.getMultiplier(), metric);
}
@ -138,8 +138,8 @@ public final class Distance implements Serializable, Comparable<Distance> { @@ -138,8 +138,8 @@ public final class Distance implements Serializable, Comparable<Distance> {
Assert.notNull(other, "Distance to must not be null!");
Assert.notNull(metric, "Result metric must not be null!");
double newLeft = getNormalizedValue() * metric.getMultiplier();
double newRight = other.getNormalizedValue() * metric.getMultiplier();
var newLeft = getNormalizedValue() * metric.getMultiplier();
var newRight = other.getNormalizedValue() * metric.getMultiplier();
return new Distance(newLeft + newRight, metric);
}
@ -169,7 +169,7 @@ public final class Distance implements Serializable, Comparable<Distance> { @@ -169,7 +169,7 @@ public final class Distance implements Serializable, Comparable<Distance> {
return 1;
}
double difference = this.getNormalizedValue() - that.getNormalizedValue();
var difference = this.getNormalizedValue() - that.getNormalizedValue();
return difference == 0 ? 0 : difference > 0 ? 1 : -1;
}
@ -181,7 +181,7 @@ public final class Distance implements Serializable, Comparable<Distance> { @@ -181,7 +181,7 @@ public final class Distance implements Serializable, Comparable<Distance> {
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();
builder.append(value);
if (metric != Metrics.NEUTRAL) {
@ -210,12 +210,10 @@ public final class Distance implements Serializable, Comparable<Distance> { @@ -210,12 +210,10 @@ public final class Distance implements Serializable, Comparable<Distance> {
return true;
}
if (!(o instanceof Distance)) {
if (!(o instanceof Distance distance)) {
return false;
}
Distance distance = (Distance) o;
if (value != distance.value) {
return false;
}

4
src/main/java/org/springframework/data/geo/GeoPage.java

@ -75,12 +75,10 @@ public class GeoPage<T> extends PageImpl<GeoResult<T>> { @@ -75,12 +75,10 @@ public class GeoPage<T> extends PageImpl<GeoResult<T>> {
return true;
}
if (!(obj instanceof GeoPage)) {
if (!(obj instanceof GeoPage<?> that)) {
return false;
}
GeoPage<?> that = (GeoPage<?>) obj;
return super.equals(obj) && ObjectUtils.nullSafeEquals(this.averageDistance, that.averageDistance);
}

6
src/main/java/org/springframework/data/geo/GeoResult.java

@ -62,12 +62,10 @@ public final class GeoResult<T> implements Serializable { @@ -62,12 +62,10 @@ public final class GeoResult<T> implements Serializable {
return true;
}
if (!(o instanceof GeoResult)) {
if (!(o instanceof GeoResult<?> geoResult)) {
return false;
}
GeoResult<?> geoResult = (GeoResult<?>) o;
if (!ObjectUtils.nullSafeEquals(content, geoResult.content)) {
return false;
}
@ -81,7 +79,7 @@ public final class GeoResult<T> implements Serializable { @@ -81,7 +79,7 @@ public final class GeoResult<T> implements Serializable {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(content);
var result = ObjectUtils.nullSafeHashCode(content);
result = 31 * result + ObjectUtils.nullSafeHashCode(distance);
return result;
}

8
src/main/java/org/springframework/data/geo/GeoResults.java

@ -115,12 +115,10 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable { @@ -115,12 +115,10 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable {
return true;
}
if (!(o instanceof GeoResults)) {
if (!(o instanceof GeoResults<?> that)) {
return false;
}
GeoResults<?> that = (GeoResults<?>) o;
if (!ObjectUtils.nullSafeEquals(results, that.results)) {
return false;
}
@ -134,7 +132,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable { @@ -134,7 +132,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(results);
var result = ObjectUtils.nullSafeHashCode(results);
result = 31 * result + ObjectUtils.nullSafeHashCode(averageDistance);
return result;
}
@ -158,7 +156,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable { @@ -158,7 +156,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable {
return new Distance(0, metric);
}
double averageDistance = results.stream()//
var averageDistance = results.stream()//
.mapToDouble(it -> it.getDistance().getValue())//
.average().orElse(0);

8
src/main/java/org/springframework/data/geo/Point.java

@ -87,9 +87,9 @@ public class Point implements Serializable { @@ -87,9 +87,9 @@ public class Point implements Serializable {
@Override
public int hashCode() {
int result = 1;
var result = 1;
long temp = Double.doubleToLongBits(x);
var temp = Double.doubleToLongBits(x);
result = 31 * result + (int) (temp ^ temp >>> 32);
temp = Double.doubleToLongBits(y);
@ -109,12 +109,10 @@ public class Point implements Serializable { @@ -109,12 +109,10 @@ public class Point implements Serializable {
return true;
}
if (!(obj instanceof Point)) {
if (!(obj instanceof Point other)) {
return false;
}
Point other = (Point) obj;
if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) {
return false;
}

3
src/main/java/org/springframework/data/geo/Polygon.java

@ -111,11 +111,10 @@ public class Polygon implements Iterable<Point>, Shape { @@ -111,11 +111,10 @@ public class Polygon implements Iterable<Point>, Shape {
return true;
}
if (!(o instanceof Polygon)) {
if (!(o instanceof Polygon that)) {
return false;
}
Polygon that = (Polygon) o;
return ObjectUtils.nullSafeEquals(points, that.points);
}

4
src/main/java/org/springframework/data/geo/format/DistanceFormatter.java

@ -94,7 +94,7 @@ public enum DistanceFormatter implements Converter<String, Distance>, Formatter< @@ -94,7 +94,7 @@ public enum DistanceFormatter implements Converter<String, Distance>, Formatter<
*/
private static Distance doConvert(String source) {
for (Entry<String, Metric> metric : SUPPORTED_METRICS.entrySet()) {
for (var metric : SUPPORTED_METRICS.entrySet()) {
if (source.endsWith(metric.getKey())) {
return fromString(source, metric);
}
@ -117,7 +117,7 @@ public enum DistanceFormatter implements Converter<String, Distance>, Formatter< @@ -117,7 +117,7 @@ public enum DistanceFormatter implements Converter<String, Distance>, Formatter<
*/
private static Distance fromString(String source, Entry<String, Metric> metric) {
String amountString = source.substring(0, source.indexOf(metric.getKey()));
var amountString = source.substring(0, source.indexOf(metric.getKey()));
try {
return new Distance(Double.parseDouble(amountString), metric.getValue());

6
src/main/java/org/springframework/data/geo/format/PointFormatter.java

@ -45,7 +45,7 @@ public enum PointFormatter implements Converter<String, Point>, Formatter<Point> @@ -45,7 +45,7 @@ public enum PointFormatter implements Converter<String, Point>, Formatter<Point>
@Override
public Point convert(String source) {
String[] parts = source.split(",");
var parts = source.split(",");
if (parts.length != 2) {
throw new IllegalArgumentException(String.format(INVALID_FORMAT, source));
@ -53,8 +53,8 @@ public enum PointFormatter implements Converter<String, Point>, Formatter<Point> @@ -53,8 +53,8 @@ public enum PointFormatter implements Converter<String, Point>, Formatter<Point>
try {
double latitude = Double.parseDouble(parts[0]);
double longitude = Double.parseDouble(parts[1]);
var latitude = Double.parseDouble(parts[0]);
var longitude = Double.parseDouble(parts[1]);
return new Point(longitude, latitude);

6
src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java

@ -118,7 +118,7 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem @@ -118,7 +118,7 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
return Lazy.of(() -> {
AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotationType);
var callback = new AnnotationDetectionFieldCallback(annotationType);
ReflectionUtils.doWithFields(entity.getClass(), callback);
return Optional.ofNullable(callback.getValue(entity));
});
@ -138,8 +138,8 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem @@ -138,8 +138,8 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
return Instant.ofEpochMilli((Long) timestamp);
}
if (Date.class.isInstance(timestamp)) {
return Date.class.cast(timestamp).toInstant();
if (timestamp instanceof Date) {
return ((Date) timestamp).toInstant();
}
throw new IllegalArgumentException(String.format("Can't convert %s to Instant!", timestamp));

6
src/main/java/org/springframework/data/history/Revision.java

@ -139,12 +139,10 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp @@ -139,12 +139,10 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
return true;
}
if (!(o instanceof Revision)) {
if (!(o instanceof Revision<?, ?> revision)) {
return false;
}
Revision<?, ?> revision = (Revision<?, ?>) o;
if (!ObjectUtils.nullSafeEquals(metadata, revision.metadata)) {
return false;
}
@ -158,7 +156,7 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp @@ -158,7 +156,7 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(metadata);
var result = ObjectUtils.nullSafeHashCode(metadata);
result = 31 * result + ObjectUtils.nullSafeHashCode(entity);
return result;
}

2
src/main/java/org/springframework/data/history/RevisionSort.java

@ -76,7 +76,7 @@ public class RevisionSort extends Sort { @@ -76,7 +76,7 @@ public class RevisionSort extends Sort {
Assert.notNull(sort, "Sort must not be null!");
Order order = sort.getOrderFor(PROPERTY);
var order = sort.getOrderFor(PROPERTY);
return order == null ? Direction.ASC : order.getDirection();
}
}

2
src/main/java/org/springframework/data/history/Revisions.java

@ -89,7 +89,7 @@ public class Revisions<N extends Number & Comparable<N>, T> implements Streamabl @@ -89,7 +89,7 @@ public class Revisions<N extends Number & Comparable<N>, T> implements Streamabl
* @return
*/
public Revision<N, T> getLatestRevision() {
int index = latestLast ? revisions.size() - 1 : 0;
var index = latestLast ? revisions.size() - 1 : 0;
return revisions.get(index);
}

4
src/main/java/org/springframework/data/mapping/AccessOptions.java

@ -186,7 +186,7 @@ public class AccessOptions { @@ -186,7 +186,7 @@ public class AccessOptions {
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
.format("Cannot register a property handler for %s on a property of type %s!", type, property.getType()));
Function<Object, T> caster = it -> type.cast(it);
var caster = (Function<Object, T>) it -> type.cast(it);
return registerHandler(property, caster.andThen(handler));
}
@ -201,7 +201,7 @@ public class AccessOptions { @@ -201,7 +201,7 @@ public class AccessOptions {
@Nullable
Object postProcess(PersistentProperty<?> property, @Nullable Object value) {
Function<Object, Object> handler = handlers.get(property);
var handler = handlers.get(property);
return handler == null ? value : handler.apply(value);
}

3
src/main/java/org/springframework/data/mapping/Alias.java

@ -158,11 +158,10 @@ public final class Alias { @@ -158,11 +158,10 @@ public final class Alias {
return true;
}
if (!(o instanceof Alias)) {
if (!(o instanceof Alias alias)) {
return false;
}
Alias alias = (Alias) o;
return ObjectUtils.nullSafeEquals(value, alias.value);
}

2
src/main/java/org/springframework/data/mapping/IdentifierAccessor.java

@ -45,7 +45,7 @@ public interface IdentifierAccessor { @@ -45,7 +45,7 @@ public interface IdentifierAccessor {
*/
default Object getRequiredIdentifier() {
Object identifier = getIdentifier();
var identifier = getIdentifier();
if (identifier != null) {
return identifier;

10
src/main/java/org/springframework/data/mapping/PersistentEntity.java

@ -97,7 +97,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It @@ -97,7 +97,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
*/
default P getRequiredIdProperty() {
P property = getIdProperty();
var property = getIdProperty();
if (property != null) {
return property;
@ -125,7 +125,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It @@ -125,7 +125,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
*/
default P getRequiredVersionProperty() {
P property = getVersionProperty();
var property = getVersionProperty();
if (property != null) {
return property;
@ -152,7 +152,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It @@ -152,7 +152,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
*/
default P getRequiredPersistentProperty(String name) {
P property = getPersistentProperty(name);
var property = getPersistentProperty(name);
if (property != null) {
return property;
@ -171,7 +171,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It @@ -171,7 +171,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
@Nullable
default P getPersistentProperty(Class<? extends Annotation> annotationType) {
Iterator<P> it = getPersistentProperties(annotationType).iterator();
var it = getPersistentProperties(annotationType).iterator();
return it.hasNext() ? it.next() : null;
}
@ -277,7 +277,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It @@ -277,7 +277,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
*/
default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType) throws IllegalStateException {
A annotation = findAnnotation(annotationType);
var annotation = findAnnotation(annotationType);
if (annotation != null) {
return annotation;

12
src/main/java/org/springframework/data/mapping/PersistentProperty.java

@ -85,7 +85,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> { @@ -85,7 +85,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
default Method getRequiredGetter() {
Method getter = getGetter();
var getter = getGetter();
if (getter == null) {
throw new IllegalArgumentException(String.format("No getter available for persistent property %s!", this));
@ -105,7 +105,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> { @@ -105,7 +105,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
default Method getRequiredSetter() {
Method setter = getSetter();
var setter = getSetter();
if (setter == null) {
throw new IllegalArgumentException(String.format("No setter available for persistent property %s!", this));
@ -143,7 +143,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> { @@ -143,7 +143,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
default Method getRequiredWither() {
Method wither = getWither();
var wither = getWither();
if (wither == null) {
throw new IllegalArgumentException(String.format("No wither available for persistent property %s!", this));
@ -157,7 +157,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> { @@ -157,7 +157,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
default Field getRequiredField() {
Field field = getField();
var field = getField();
if (field == null) {
throw new IllegalArgumentException(String.format("No field backing persistent property %s!", this));
@ -186,7 +186,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> { @@ -186,7 +186,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
*/
default Association<P> getRequiredAssociation() {
Association<P> association = getAssociation();
var association = getAssociation();
if (association != null) {
return association;
@ -332,7 +332,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> { @@ -332,7 +332,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
*/
default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType) throws IllegalStateException {
A annotation = findAnnotation(annotationType);
var annotation = findAnnotation(annotationType);
if (annotation != null) {
return annotation;

22
src/main/java/org/springframework/data/mapping/PersistentPropertyAccessor.java

@ -61,26 +61,26 @@ public interface PersistentPropertyAccessor<T> { @@ -61,26 +61,26 @@ public interface PersistentPropertyAccessor<T> {
Assert.notNull(path, "PersistentPropertyPath must not be null!");
Assert.isTrue(!path.isEmpty(), "PersistentPropertyPath must not be empty!");
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
PersistentProperty<?> leafProperty = path.getRequiredLeafProperty();
PersistentProperty<?> parentProperty = parentPath.isEmpty() ? null : parentPath.getLeafProperty();
var parentPath = path.getParentPath();
var leafProperty = path.getRequiredLeafProperty();
var parentProperty = parentPath.isEmpty() ? null : parentPath.getLeafProperty();
if (parentProperty != null && (parentProperty.isCollectionLike() || parentProperty.isMap())) {
throw new MappingException(
String.format("Cannot traverse collection or map intermediate %s", parentPath.toDotPath()));
}
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
var parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
if (parent == null) {
String nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
throw new MappingException(
String.format(nullIntermediateMessage, parentProperty, path.toDotPath(), getBean().getClass().getName()));
}
PersistentPropertyAccessor<?> accessor = parent == getBean() //
var accessor = parent == getBean() //
? this //
: leafProperty.getOwner().getPropertyAccessor(parent);
@ -90,7 +90,7 @@ public interface PersistentPropertyAccessor<T> { @@ -90,7 +90,7 @@ public interface PersistentPropertyAccessor<T> {
return;
}
Object bean = accessor.getBean();
var bean = accessor.getBean();
if (bean != parent) {
setProperty(parentPath, bean);
@ -140,7 +140,7 @@ public interface PersistentPropertyAccessor<T> { @@ -140,7 +140,7 @@ public interface PersistentPropertyAccessor<T> {
default Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, TraversalContext context) {
Object bean = getBean();
Object current = bean;
var current = bean;
if (path.isEmpty()) {
return bean;
@ -150,14 +150,14 @@ public interface PersistentPropertyAccessor<T> { @@ -150,14 +150,14 @@ public interface PersistentPropertyAccessor<T> {
if (current == null) {
String nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
throw new MappingException(
String.format(nullIntermediateMessage, property, path.toDotPath(), bean.getClass().getName()));
}
PersistentEntity<?, ? extends PersistentProperty<?>> entity = property.getOwner();
PersistentPropertyAccessor<Object> accessor = entity.getPropertyAccessor(current);
var entity = property.getOwner();
var accessor = entity.getPropertyAccessor(current);
current = context.postProcess(property, accessor.getProperty(property));
}

2
src/main/java/org/springframework/data/mapping/PersistentPropertyPath.java

@ -76,7 +76,7 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends @@ -76,7 +76,7 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends
default P getRequiredLeafProperty() {
P property = getLeafProperty();
var property = getLeafProperty();
if (property == null) {
throw new IllegalStateException("No leaf property found!");

18
src/main/java/org/springframework/data/mapping/PreferredConstructor.java

@ -131,13 +131,13 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> { @@ -131,13 +131,13 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
Assert.notNull(property, "Property must not be null!");
Boolean cached = isPropertyParameterCache.get(property);
var cached = isPropertyParameterCache.get(property);
if (cached != null) {
return cached;
}
boolean result = false;
var result = false;
for (Parameter<?, P> parameter : parameters) {
if (parameter.maps(property)) {
result = true;
@ -214,7 +214,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> { @@ -214,7 +214,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
throw new IllegalStateException();
}
Class<T> owningType = entity.getType();
var owningType = entity.getType();
return owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass());
});
@ -297,12 +297,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> { @@ -297,12 +297,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
return true;
}
if (!(o instanceof Parameter)) {
if (!(o instanceof Parameter<?, ?> parameter)) {
return false;
}
Parameter<?, ?> parameter = (Parameter<?, ?>) o;
if (!ObjectUtils.nullSafeEquals(name, parameter.name)) {
return false;
}
@ -324,7 +322,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> { @@ -324,7 +322,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(name);
var result = ObjectUtils.nullSafeHashCode(name);
result = 31 * result + ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(key);
result = 31 * result + ObjectUtils.nullSafeHashCode(entity);
@ -339,10 +337,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> { @@ -339,10 +337,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
*/
boolean maps(PersistentProperty<?> property) {
PersistentEntity<T, P> entity = this.entity;
String name = this.name;
var entity = this.entity;
var name = this.name;
P referencedProperty = entity == null ? null : name == null ? null : entity.getPersistentProperty(name);
var referencedProperty = entity == null ? null : name == null ? null : entity.getPersistentProperty(name);
return property.equals(referencedProperty);
}

43
src/main/java/org/springframework/data/mapping/PropertyPath.java

@ -22,7 +22,6 @@ import java.util.Iterator; @@ -22,7 +22,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.data.util.ClassTypeInformation;
@ -83,8 +82,8 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -83,8 +82,8 @@ public class PropertyPath implements Streamable<PropertyPath> {
Assert.notNull(owningType, "Owning type must not be null!");
Assert.notNull(base, "Previously found properties must not be null!");
String propertyName = Introspector.decapitalize(name);
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
var propertyName = Introspector.decapitalize(name);
var propertyType = owningType.getProperty(propertyName);
if (propertyType == null) {
throw new PropertyReferenceException(propertyName, owningType, base);
@ -123,7 +122,7 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -123,7 +122,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
public PropertyPath getLeafProperty() {
PropertyPath result = this;
var result = this;
while (result.hasNext()) {
result = result.requiredNext();
@ -209,7 +208,7 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -209,7 +208,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
Assert.hasText(path, "Path must not be null or empty!");
String lookup = toDotPath().concat(".").concat(path);
var lookup = toDotPath().concat(".").concat(path);
return PropertyPath.from(lookup, owningType);
}
@ -231,7 +230,7 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -231,7 +230,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
@Nullable
public PropertyPath next() {
PropertyPath result = current;
var result = current;
if (result == null) {
return null;
@ -258,12 +257,10 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -258,12 +257,10 @@ public class PropertyPath implements Streamable<PropertyPath> {
return true;
}
if (!(o instanceof PropertyPath)) {
if (!(o instanceof PropertyPath that)) {
return false;
}
PropertyPath that = (PropertyPath) o;
if (isCollection != that.isCollection) {
return false;
}
@ -293,7 +290,7 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -293,7 +290,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(owningType);
var result = ObjectUtils.nullSafeHashCode(owningType);
result = 31 * result + ObjectUtils.nullSafeHashCode(name);
result = 31 * result + ObjectUtils.nullSafeHashCode(typeInformation);
result = 31 * result + ObjectUtils.nullSafeHashCode(actualTypeInformation);
@ -310,7 +307,7 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -310,7 +307,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
private PropertyPath requiredNext() {
PropertyPath result = next;
var result = next;
if (result == null) {
throw new IllegalStateException(
@ -349,17 +346,17 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -349,17 +346,17 @@ public class PropertyPath implements Streamable<PropertyPath> {
List<String> iteratorSource = new ArrayList<>();
Matcher matcher = isQuoted(it.path) ? SPLITTER_FOR_QUOTED.matcher(it.path.replace("\\Q", "").replace("\\E", ""))
var matcher = isQuoted(it.path) ? SPLITTER_FOR_QUOTED.matcher(it.path.replace("\\Q", "").replace("\\E", ""))
: SPLITTER.matcher("_" + it.path);
while (matcher.find()) {
iteratorSource.add(matcher.group(1));
}
Iterator<String> parts = iteratorSource.iterator();
var parts = iteratorSource.iterator();
PropertyPath result = null;
Stack<PropertyPath> current = new Stack<>();
var current = new Stack<PropertyPath>();
while (parts.hasNext()) {
if (result == null) {
@ -392,9 +389,9 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -392,9 +389,9 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
private static PropertyPath create(String source, Stack<PropertyPath> base) {
PropertyPath previous = base.peek();
var previous = base.peek();
PropertyPath propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base);
var propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base);
previous.next = propertyPath;
return propertyPath;
}
@ -458,13 +455,13 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -458,13 +455,13 @@ public class PropertyPath implements Streamable<PropertyPath> {
exception = e;
}
Matcher matcher = NESTED_PROPERTY_PATTERN.matcher(source);
var matcher = NESTED_PROPERTY_PATTERN.matcher(source);
if (matcher.find() && matcher.start() != 0) {
int position = matcher.start();
String head = source.substring(0, position);
String tail = source.substring(position);
var position = matcher.start();
var head = source.substring(0, position);
var tail = source.substring(position);
try {
return create(head, type, tail + addTail, base);
@ -518,12 +515,10 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -518,12 +515,10 @@ public class PropertyPath implements Streamable<PropertyPath> {
return true;
}
if (!(o instanceof Key)) {
if (!(o instanceof Key key)) {
return false;
}
Key key = (Key) o;
if (!ObjectUtils.nullSafeEquals(type, key.type)) {
return false;
}
@ -537,7 +532,7 @@ public class PropertyPath implements Streamable<PropertyPath> { @@ -537,7 +532,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(type);
var result = ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(path);
return result;
}

6
src/main/java/org/springframework/data/mapping/PropertyReferenceException.java

@ -99,12 +99,12 @@ public class PropertyReferenceException extends RuntimeException { @@ -99,12 +99,12 @@ public class PropertyReferenceException extends RuntimeException {
@Override
public String getMessage() {
StringBuilder builder = new StringBuilder(
var builder = new StringBuilder(
String.format(ERROR_TEMPLATE, propertyName, type.getType().getSimpleName()));
Collection<String> potentialMatches = getPropertyMatches();
var potentialMatches = getPropertyMatches();
if (!potentialMatches.isEmpty()) {
String matches = StringUtils.collectionToDelimitedString(potentialMatches, ",", "'", "'");
var matches = StringUtils.collectionToDelimitedString(potentialMatches, ",", "'", "'");
builder.append(String.format(HINTS_TEMPLATE, matches));
}

2
src/main/java/org/springframework/data/mapping/TargetAwareIdentifierAccessor.java

@ -39,7 +39,7 @@ public abstract class TargetAwareIdentifierAccessor implements IdentifierAccesso @@ -39,7 +39,7 @@ public abstract class TargetAwareIdentifierAccessor implements IdentifierAccesso
@Override
public Object getRequiredIdentifier() {
Object identifier = getIdentifier();
var identifier = getIdentifier();
if (identifier != null) {
return identifier;

4
src/main/java/org/springframework/data/mapping/TraversalContext.java

@ -124,7 +124,7 @@ public class TraversalContext { @@ -124,7 +124,7 @@ public class TraversalContext {
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
.format("Cannot register a property handler for %s on a property of type %s!", type, property.getType()));
Function<Object, T> caster = it -> type.cast(it);
var caster = (Function<Object, T>) it -> type.cast(it);
return registerHandler(property, caster.andThen(handler));
}
@ -139,7 +139,7 @@ public class TraversalContext { @@ -139,7 +139,7 @@ public class TraversalContext {
@Nullable
Object postProcess(PersistentProperty<?> property, @Nullable Object value) {
Function<Object, Object> handler = handlers.get(property);
var handler = handlers.get(property);
return handler == null ? value : handler.apply(value);
}

22
src/main/java/org/springframework/data/mapping/callback/DefaultEntityCallbacks.java

@ -19,8 +19,8 @@ import java.lang.reflect.Method; @@ -19,8 +19,8 @@ import java.lang.reflect.Method;
import java.util.Map;
import java.util.function.BiFunction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.ResolvableType;
import org.springframework.util.Assert;
@ -68,22 +68,22 @@ class DefaultEntityCallbacks implements EntityCallbacks { @@ -68,22 +68,22 @@ class DefaultEntityCallbacks implements EntityCallbacks {
Assert.notNull(entity, "Entity must not be null!");
Class<T> entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
var entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
: callbackDiscoverer.resolveDeclaredEntityType(callbackType).getRawClass());
Method callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
var callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
Method method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
var method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
ReflectionUtils.makeAccessible(method);
return method;
});
T value = entity;
var value = entity;
for (EntityCallback<T> callback : callbackDiscoverer.getEntityCallbacks(entityType,
for (var callback : callbackDiscoverer.getEntityCallbacks(entityType,
ResolvableType.forClass(callbackType))) {
BiFunction<EntityCallback<T>, T, Object> callbackFunction = EntityCallbackDiscoverer
var callbackFunction = EntityCallbackDiscoverer
.computeCallbackInvokerFunction(callback, callbackMethod, args);
value = callbackInvoker.invokeCallback(callback, value, callbackFunction);
}
@ -100,7 +100,7 @@ class DefaultEntityCallbacks implements EntityCallbacks { @@ -100,7 +100,7 @@ class DefaultEntityCallbacks implements EntityCallbacks {
this.callbackDiscoverer.addEntityCallback(callback);
}
class SimpleEntityCallbackInvoker implements org.springframework.data.mapping.callback.EntityCallbackInvoker {
static class SimpleEntityCallbackInvoker implements org.springframework.data.mapping.callback.EntityCallbackInvoker {
@Override
public <T> T invokeCallback(EntityCallback<T> callback, T entity,
@ -108,7 +108,7 @@ class DefaultEntityCallbacks implements EntityCallbacks { @@ -108,7 +108,7 @@ class DefaultEntityCallbacks implements EntityCallbacks {
try {
Object value = callbackInvokerFunction.apply(callback, entity);
var value = callbackInvokerFunction.apply(callback, entity);
if (value != null) {
return (T) value;
@ -119,12 +119,12 @@ class DefaultEntityCallbacks implements EntityCallbacks { @@ -119,12 +119,12 @@ class DefaultEntityCallbacks implements EntityCallbacks {
} catch (ClassCastException ex) {
String msg = ex.getMessage();
var msg = ex.getMessage();
if (msg == null || EntityCallbackInvoker.matchesClassCastMessage(msg, entity.getClass())) {
// Possibly a lambda-defined listener which we could not resolve the generic event type for
// -> let's suppress the exception and just log a debug message.
Log logger = LogFactory.getLog(getClass());
var logger = LogFactory.getLog(getClass());
if (logger.isDebugEnabled()) {
logger.debug("Non-matching callback type for entity callback: " + callback, ex);
}

20
src/main/java/org/springframework/data/mapping/callback/DefaultReactiveEntityCallbacks.java

@ -21,9 +21,9 @@ import java.lang.reflect.Method; @@ -21,9 +21,9 @@ import java.lang.reflect.Method;
import java.util.Map;
import java.util.function.BiFunction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.ResolvableType;
import org.springframework.util.Assert;
@ -69,22 +69,22 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks { @@ -69,22 +69,22 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
Assert.notNull(entity, "Entity must not be null!");
Class<T> entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
var entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
: callbackDiscoverer.resolveDeclaredEntityType(callbackType).getRawClass());
Method callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
var callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
Method method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
var method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
ReflectionUtils.makeAccessible(method);
return method;
});
Mono<T> deferredCallbackChain = Mono.just(entity);
var deferredCallbackChain = Mono.just(entity);
for (EntityCallback<T> callback : callbackDiscoverer.getEntityCallbacks(entityType,
for (var callback : callbackDiscoverer.getEntityCallbacks(entityType,
ResolvableType.forClass(callbackType))) {
BiFunction<EntityCallback<T>, T, Object> callbackFunction = EntityCallbackDiscoverer
var callbackFunction = EntityCallbackDiscoverer
.computeCallbackInvokerFunction(callback, callbackMethod, args);
deferredCallbackChain = deferredCallbackChain
@ -111,7 +111,7 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks { @@ -111,7 +111,7 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
try {
Object value = callbackInvokerFunction.apply(callback, entity);
var value = callbackInvokerFunction.apply(callback, entity);
if (value != null) {
return value instanceof Publisher ? Mono.from((Publisher<T>) value) : Mono.just((T) value);
@ -121,12 +121,12 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks { @@ -121,12 +121,12 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
String.format("Callback invocation on %s returned null value for %s", callback.getClass(), entity));
} catch (ClassCastException ex) {
String msg = ex.getMessage();
var msg = ex.getMessage();
if (msg == null || EntityCallbackInvoker.matchesClassCastMessage(msg, entity.getClass())) {
// Possibly a lambda-defined listener which we could not resolve the generic event type for
// -> let's suppress the exception and just log a debug message.
Log logger = LogFactory.getLog(getClass());
var logger = LogFactory.getLog(getClass());
if (logger.isDebugEnabled()) {
logger.debug("Non-matching callback type for entity callback: " + callback, ex);
}

31
src/main/java/org/springframework/data/mapping/callback/EntityCallbackDiscoverer.java

@ -79,7 +79,7 @@ class EntityCallbackDiscoverer { @@ -79,7 +79,7 @@ class EntityCallbackDiscoverer {
// Explicitly remove target for a proxy, if registered already,
// in order to avoid double invocations of the same callback.
Object singletonTarget = AopProxyUtils.getSingletonTarget(callback);
var singletonTarget = AopProxyUtils.getSingletonTarget(callback);
if (singletonTarget instanceof EntityCallback) {
this.defaultRetriever.entityCallbacks.remove(singletonTarget);
}
@ -134,10 +134,10 @@ class EntityCallbackDiscoverer { @@ -134,10 +134,10 @@ class EntityCallbackDiscoverer {
<T extends S, S> Collection<EntityCallback<S>> getEntityCallbacks(Class<T> entity, ResolvableType callbackType) {
Class<?> sourceType = entity;
CallbackCacheKey cacheKey = new CallbackCacheKey(callbackType, sourceType);
var cacheKey = new CallbackCacheKey(callbackType, sourceType);
// Quick check for existing entry on ConcurrentHashMap...
CallbackRetriever retriever = this.retrieverCache.get(cacheKey);
var retriever = this.retrieverCache.get(cacheKey);
if (retriever != null) {
return (Collection<EntityCallback<S>>) (Collection) retriever.getEntityCallbacks();
}
@ -152,7 +152,7 @@ class EntityCallbackDiscoverer { @@ -152,7 +152,7 @@ class EntityCallbackDiscoverer {
return (Collection<EntityCallback<S>>) (Collection) retriever.getEntityCallbacks();
}
retriever = new CallbackRetriever(true);
Collection<EntityCallback<?>> callbacks = retrieveEntityCallbacks(ResolvableType.forClass(sourceType),
var callbacks = retrieveEntityCallbacks(ResolvableType.forClass(sourceType),
callbackType, retriever);
this.retrieverCache.put(cacheKey, retriever);
return (Collection<EntityCallback<S>>) (Collection) callbacks;
@ -166,7 +166,7 @@ class EntityCallbackDiscoverer { @@ -166,7 +166,7 @@ class EntityCallbackDiscoverer {
@Nullable
ResolvableType resolveDeclaredEntityType(Class<?> callbackType) {
ResolvableType eventType = entityTypeCache.get(callbackType);
var eventType = entityTypeCache.get(callbackType);
if (eventType == null) {
eventType = ResolvableType.forClass(callbackType).as(EntityCallback.class).getGeneric();
@ -196,7 +196,7 @@ class EntityCallbackDiscoverer { @@ -196,7 +196,7 @@ class EntityCallbackDiscoverer {
callbackBeans = new LinkedHashSet<>(this.defaultRetriever.entityCallbackBeans);
}
for (EntityCallback<?> callback : callbacks) {
for (var callback : callbacks) {
if (supportsEvent(callback, entityType, callbackType)) {
if (retriever != null) {
retriever.getEntityCallbacks().add(callback);
@ -206,10 +206,10 @@ class EntityCallbackDiscoverer { @@ -206,10 +206,10 @@ class EntityCallbackDiscoverer {
}
if (!callbackBeans.isEmpty()) {
BeanFactory beanFactory = getRequiredBeanFactory();
for (String callbackBeanName : callbackBeans) {
var beanFactory = getRequiredBeanFactory();
for (var callbackBeanName : callbackBeans) {
try {
Class<?> callbackImplType = beanFactory.getType(callbackBeanName);
var callbackImplType = beanFactory.getType(callbackBeanName);
if (callbackImplType == null || supportsEvent(callbackImplType, entityType)) {
EntityCallback<?> callback = beanFactory.getBean(callbackBeanName, EntityCallback.class);
if (!allCallbacks.contains(callback) && supportsEvent(callback, entityType, callbackType)) {
@ -253,7 +253,7 @@ class EntityCallbackDiscoverer { @@ -253,7 +253,7 @@ class EntityCallbackDiscoverer {
*/
protected boolean supportsEvent(Class<?> callback, ResolvableType entityType) {
ResolvableType declaredEventType = resolveDeclaredEntityType(callback);
var declaredEventType = resolveDeclaredEntityType(callback);
return (declaredEventType == null || declaredEventType.isAssignableFrom(entityType));
}
@ -291,8 +291,7 @@ class EntityCallbackDiscoverer { @@ -291,8 +291,7 @@ class EntityCallbackDiscoverer {
this.beanFactory = beanFactory;
if (beanFactory instanceof ConfigurableBeanFactory) {
ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
if (this.beanClassLoader == null) {
this.beanClassLoader = cbf.getBeanClassLoader();
}
@ -332,7 +331,7 @@ class EntityCallbackDiscoverer { @@ -332,7 +331,7 @@ class EntityCallbackDiscoverer {
return (entityCallback, entity) -> {
Object[] invocationArgs = new Object[args.length + 1];
var invocationArgs = new Object[args.length + 1];
invocationArgs[0] = entity;
if (args.length > 0) {
System.arraycopy(args, 0, invocationArgs, 1, args.length);
@ -372,8 +371,8 @@ class EntityCallbackDiscoverer { @@ -372,8 +371,8 @@ class EntityCallbackDiscoverer {
allCallbacks.addAll(this.entityCallbacks);
if (!this.entityCallbackBeans.isEmpty()) {
BeanFactory beanFactory = getRequiredBeanFactory();
for (String callbackBeanName : this.entityCallbackBeans) {
var beanFactory = getRequiredBeanFactory();
for (var callbackBeanName : this.entityCallbackBeans) {
try {
EntityCallback<?> callback = beanFactory.getBean(callbackBeanName, EntityCallback.class);
if (this.preFiltered || !allCallbacks.contains(callback)) {
@ -427,7 +426,7 @@ class EntityCallbackDiscoverer { @@ -427,7 +426,7 @@ class EntityCallbackDiscoverer {
return true;
}
CallbackCacheKey otherKey = (CallbackCacheKey) other;
var otherKey = (CallbackCacheKey) other;
return (this.callbackType.equals(otherKey.callbackType)
&& ObjectUtils.nullSafeEquals(this.entityType, otherKey.entityType));

2
src/main/java/org/springframework/data/mapping/callback/EntityCallbackInvoker.java

@ -48,7 +48,7 @@ interface EntityCallbackInvoker { @@ -48,7 +48,7 @@ interface EntityCallbackInvoker {
}
// On Java 9, the message used to contain the module name: "java.base/java.lang.String cannot be cast..."
int moduleSeparatorIndex = classCastMessage.indexOf('/');
var moduleSeparatorIndex = classCastMessage.indexOf('/');
if (moduleSeparatorIndex != -1 && classCastMessage.startsWith(eventClass.getName(), moduleSeparatorIndex + 1)) {
return true;
}

4
src/main/java/org/springframework/data/mapping/callback/EntityCallbacks.java

@ -55,8 +55,8 @@ public interface EntityCallbacks { @@ -55,8 +55,8 @@ public interface EntityCallbacks {
*/
static EntityCallbacks create(EntityCallback<?>... callbacks) {
EntityCallbacks entityCallbacks = create();
for (EntityCallback<?> callback : callbacks) {
var entityCallbacks = create();
for (var callback : callbacks) {
entityCallbacks.addEntityCallback(callback);
}
return entityCallbacks;

4
src/main/java/org/springframework/data/mapping/callback/ReactiveEntityCallbacks.java

@ -58,8 +58,8 @@ public interface ReactiveEntityCallbacks { @@ -58,8 +58,8 @@ public interface ReactiveEntityCallbacks {
*/
static ReactiveEntityCallbacks create(EntityCallback<?>... callbacks) {
ReactiveEntityCallbacks entityCallbacks = create();
for (EntityCallback<?> callback : callbacks) {
var entityCallbacks = create();
for (var callback : callbacks) {
entityCallbacks.addEntityCallback(callback);
}
return entityCallbacks;

54
src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

@ -17,7 +17,6 @@ package org.springframework.data.mapping.context; @@ -17,7 +17,6 @@ package org.springframework.data.mapping.context;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
@ -33,7 +32,6 @@ import java.util.stream.Collectors; @@ -33,7 +32,6 @@ import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
@ -114,8 +112,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -114,8 +112,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
EntityInstantiators instantiators = new EntityInstantiators();
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage()
var instantiators = new EntityInstantiators();
var accessorFactory = NativeDetector.inNativeImage()
? BeanWrapperPropertyAccessorFactory.INSTANCE
: new ClassGeneratingPropertyAccessorFactory();
@ -218,7 +216,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -218,7 +216,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
Assert.notNull(type, "Type must not be null!");
Optional<E> entity = persistentEntities.get(ClassTypeInformation.from(type));
var entity = persistentEntities.get(ClassTypeInformation.from(type));
return entity == null ? false : entity.isPresent();
}
@ -237,7 +235,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -237,7 +235,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
read.lock();
Optional<E> entity = persistentEntities.get(type);
var entity = persistentEntities.get(type);
if (entity != null) {
return entity.orElse(null);
@ -280,7 +278,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -280,7 +278,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
return null;
}
TypeInformation<?> typeInfo = persistentProperty.getTypeInformation();
var typeInfo = persistentProperty.getTypeInformation();
return getPersistentEntity(typeInfo.getRequiredActualType());
}
@ -355,7 +353,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -355,7 +353,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
read.lock();
Optional<E> persistentEntity = persistentEntities.get(typeInformation);
var persistentEntity = persistentEntities.get(typeInformation);
if (persistentEntity != null) {
return persistentEntity;
@ -400,9 +398,9 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -400,9 +398,9 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
try {
Class<?> type = userTypeInformation.getType();
var type = userTypeInformation.getType();
E entity = createPersistentEntity(userTypeInformation);
var entity = createPersistentEntity(userTypeInformation);
entity.setEvaluationContextProvider(evaluationContextProvider);
// Eagerly cache the entity as we might have to find it during recursive lookups.
@ -413,14 +411,14 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -413,14 +411,14 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
persistentEntities.put(typeInformation, Optional.of(entity));
}
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
var pds = BeanUtils.getPropertyDescriptors(type);
Map<String, PropertyDescriptor> descriptors = new HashMap<>();
for (PropertyDescriptor descriptor : pds) {
for (var descriptor : pds) {
descriptors.put(descriptor.getName(), descriptor);
}
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
var persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
@ -544,12 +542,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -544,12 +542,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
*/
public void doWith(Field field) {
String fieldName = field.getName();
TypeInformation<?> type = entity.getTypeInformation();
var fieldName = field.getName();
var type = entity.getTypeInformation();
ReflectionUtils.makeAccessible(field);
Property property = Optional.ofNullable(descriptors.get(fieldName))//
var property = Optional.ofNullable(descriptors.get(fieldName))//
.map(it -> Property.of(type, field, it))//
.orElseGet(() -> Property.of(type, field));
@ -575,7 +573,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -575,7 +573,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private void createAndRegisterProperty(Property input) {
P property = createPersistentProperty(input, entity, simpleTypeHolder);
var property = createPersistentProperty(input, entity, simpleTypeHolder);
if (property.isTransient()) {
return;
@ -609,17 +607,17 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -609,17 +607,17 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
protected boolean shouldSkipOverrideProperty(P property) {
P existingProperty = entity.getPersistentProperty(property.getName());
var existingProperty = entity.getPersistentProperty(property.getName());
if (existingProperty == null) {
return false;
}
Class<?> declaringClass = getDeclaringClass(property);
Class<?> existingDeclaringClass = getDeclaringClass(existingProperty);
var declaringClass = getDeclaringClass(property);
var existingDeclaringClass = getDeclaringClass(existingProperty);
Class<?> propertyType = getPropertyType(property);
Class<?> existingPropertyType = getPropertyType(existingProperty);
var propertyType = getPropertyType(property);
var existingPropertyType = getPropertyType(existingProperty);
if (!propertyType.isAssignableFrom(existingPropertyType)) {
@ -638,12 +636,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -638,12 +636,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private Class<?> getDeclaringClass(PersistentProperty<?> persistentProperty) {
Field field = persistentProperty.getField();
var field = persistentProperty.getField();
if (field != null) {
return field.getDeclaringClass();
}
Method accessor = persistentProperty.getGetter();
var accessor = persistentProperty.getGetter();
if (accessor == null) {
accessor = persistentProperty.getSetter();
@ -662,22 +660,22 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -662,22 +660,22 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private Class<?> getPropertyType(PersistentProperty<?> persistentProperty) {
Field field = persistentProperty.getField();
var field = persistentProperty.getField();
if (field != null) {
return field.getType();
}
Method getter = persistentProperty.getGetter();
var getter = persistentProperty.getGetter();
if (getter != null) {
return getter.getReturnType();
}
Method setter = persistentProperty.getSetter();
var setter = persistentProperty.getSetter();
if (setter != null) {
return setter.getParameterTypes()[0];
}
Method wither = persistentProperty.getWither();
var wither = persistentProperty.getWither();
if (wither != null) {
return wither.getParameterTypes()[0];
}

19
src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java

@ -80,7 +80,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -80,7 +80,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
}
@SuppressWarnings("null")
Class<?> leafPropertyType = getLeafProperty().getActualType();
var leafPropertyType = getLeafProperty().getActualType();
Assert.isTrue(property.getOwner().getType().equals(leafPropertyType),
() -> String.format("Cannot append property %s to type %s!", property.getName(), leafPropertyType.getName()));
@ -128,7 +128,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -128,7 +128,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
Assert.hasText(delimiter, "Delimiter must not be null or empty!");
Assert.notNull(converter, "Converter must not be null!");
String result = properties.stream() //
var result = properties.stream() //
.map(converter::convert) //
.filter(StringUtils::hasText) //
.collect(Collectors.joining(delimiter));
@ -162,15 +162,15 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -162,15 +162,15 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
Assert.notNull(path, "PersistentPropertyPath must not be null!");
Iterator<P> iterator = path.iterator();
var iterator = path.iterator();
for (P property : this) {
for (var property : this) {
if (!iterator.hasNext()) {
return false;
}
P reference = iterator.next();
var reference = iterator.next();
if (!property.equals(reference)) {
return false;
@ -191,9 +191,9 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -191,9 +191,9 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
}
List<P> result = new ArrayList<>();
Iterator<P> iterator = iterator();
var iterator = iterator();
for (int i = 0; i < base.getLength(); i++) {
for (var i = 0; i < base.getLength(); i++) {
iterator.next();
}
@ -210,7 +210,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -210,7 +210,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
*/
public PersistentPropertyPath<P> getParentPath() {
int size = properties.size();
var size = properties.size();
return size == 0 ? this : new DefaultPersistentPropertyPath<>(properties.subList(0, size - 1));
}
@ -256,11 +256,10 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -256,11 +256,10 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
return true;
}
if (!(o instanceof DefaultPersistentPropertyPath)) {
if (!(o instanceof DefaultPersistentPropertyPath<?> that)) {
return false;
}
DefaultPersistentPropertyPath<?> that = (DefaultPersistentPropertyPath<?>) o;
return ObjectUtils.nullSafeEquals(properties, that.properties);
}

4
src/main/java/org/springframework/data/mapping/context/InvalidPersistentPropertyPath.java

@ -109,14 +109,14 @@ public class InvalidPersistentPropertyPath extends MappingException { @@ -109,14 +109,14 @@ public class InvalidPersistentPropertyPath extends MappingException {
return "";
}
String dotPath = path.toDotPath();
var dotPath = path.toDotPath();
return dotPath == null ? "" : dotPath;
}
private static String createMessage(TypeInformation<?> type, String unresolvableSegment) {
Set<String> potentialMatches = detectPotentialMatches(unresolvableSegment, type.getType());
var potentialMatches = detectPotentialMatches(unresolvableSegment, type.getType());
Object match = StringUtils.collectionToCommaDelimitedString(potentialMatches);
return String.format(DEFAULT_MESSAGE, unresolvableSegment, type.getType(), match);

6
src/main/java/org/springframework/data/mapping/context/MappingContext.java

@ -70,7 +70,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers @@ -70,7 +70,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
*/
default E getRequiredPersistentEntity(Class<?> type) throws MappingException {
E entity = getPersistentEntity(type);
var entity = getPersistentEntity(type);
if (entity != null) {
return entity;
@ -110,7 +110,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers @@ -110,7 +110,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
*/
default E getRequiredPersistentEntity(TypeInformation<?> type) throws MappingException {
E entity = getPersistentEntity(type);
var entity = getPersistentEntity(type);
if (entity != null) {
return entity;
@ -143,7 +143,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers @@ -143,7 +143,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
*/
default E getRequiredPersistentEntity(P persistentProperty) throws MappingException {
E entity = getPersistentEntity(persistentProperty);
var entity = getPersistentEntity(persistentProperty);
if (entity != null) {
return entity;

28
src/main/java/org/springframework/data/mapping/context/PersistentEntities.java

@ -196,13 +196,13 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte @@ -196,13 +196,13 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
@Nullable
public PersistentEntity<?, ?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property) {
TypeInformation<?> propertyType = property.getTypeInformation().getActualType();
var propertyType = property.getTypeInformation().getActualType();
if (propertyType == null || !property.isAssociation()) {
return null;
}
Class<?> associationTargetType = property.getAssociationTargetType();
var associationTargetType = property.getAssociationTargetType();
return associationTargetType == null //
? getEntityIdentifiedBy(propertyType) //
@ -220,7 +220,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte @@ -220,7 +220,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
Assert.notNull(property, "PersistentProperty must not be null!");
PersistentEntity<?, ?> entity = getEntityUltimatelyReferredToBy(property);
var entity = getEntityUltimatelyReferredToBy(property);
return entity == null //
? property.getTypeInformation().getRequiredActualType() //
@ -238,16 +238,24 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte @@ -238,16 +238,24 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
@Nullable
private PersistentEntity<?, ?> getEntityIdentifiedBy(TypeInformation<?> type) {
Collection<PersistentEntity<?, ?>> entities = contexts.stream() //
.flatMap(it -> it.getPersistentEntities().stream()) //
.map(PersistentEntity::getIdProperty) //
.filter(it -> it != null && type.equals(it.getTypeInformation().getActualType())) //
.map(PersistentProperty::getOwner) //
.collect(Collectors.toList());
Collection<PersistentEntity<?, ?>> entities = new ArrayList<>();
for (MappingContext<?, ? extends PersistentProperty<?>> context : contexts) {
for (PersistentEntity<?, ? extends PersistentProperty<?>> persistentProperties : context
.getPersistentEntities()) {
var idProperty = persistentProperties.getIdProperty();
if (idProperty != null && type.equals(idProperty.getTypeInformation().getActualType())) {
var owner = idProperty.getOwner();
entities.add(owner);
}
}
}
if (entities.size() > 1) {
String message = "Found multiple entities identified by " + type.getType() + ": ";
var message = "Found multiple entities identified by " + type.getType() + ": ";
message += entities.stream().map(it -> it.getType().getName()).collect(Collectors.joining(", "));
message += "! Introduce dedicated unique identifier types or explicitly define the target type in @Reference!";

50
src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java

@ -19,7 +19,6 @@ import java.util.*; @@ -19,7 +19,6 @@ import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.mapping.PersistentEntity;
@ -181,26 +180,26 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -181,26 +180,26 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
*/
private PersistentPropertyPath<P> createPersistentPropertyPath(String propertyPath, TypeInformation<?> type) {
String trimmedPath = propertyPath.trim();
var trimmedPath = propertyPath.trim();
List<String> parts = trimmedPath.isEmpty() //
? Collections.emptyList() //
: Arrays.asList(trimmedPath.split("\\."));
DefaultPersistentPropertyPath<P> path = DefaultPersistentPropertyPath.empty();
Iterator<String> iterator = parts.iterator();
E current = context.getRequiredPersistentEntity(type);
var iterator = parts.iterator();
var current = context.getRequiredPersistentEntity(type);
while (iterator.hasNext()) {
String segment = iterator.next();
final DefaultPersistentPropertyPath<P> currentPath = path;
var segment = iterator.next();
final var currentPath = path;
Pair<DefaultPersistentPropertyPath<P>, E> pair = getPair(path, iterator, segment, current);
var pair = getPair(path, iterator, segment, current);
if (pair == null) {
String source = StringUtils.collectionToDelimitedString(parts, ".");
var source = StringUtils.collectionToDelimitedString(parts, ".");
throw new InvalidPersistentPropertyPath(source, type, segment, currentPath);
}
@ -216,7 +215,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -216,7 +215,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
private Pair<DefaultPersistentPropertyPath<P>, E> getPair(DefaultPersistentPropertyPath<P> path,
Iterator<String> iterator, String segment, E entity) {
P property = entity.getPersistentProperty(segment);
var property = entity.getPersistentProperty(segment);
if (property == null) {
return null;
@ -228,13 +227,13 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -228,13 +227,13 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
private <T> Collection<PersistentPropertyPath<P>> from(TypeInformation<T> type, Predicate<? super P> filter,
Predicate<P> traversalGuard, DefaultPersistentPropertyPath<P> basePath) {
TypeInformation<?> actualType = type.getActualType();
var actualType = type.getActualType();
if (actualType == null) {
return Collections.emptyList();
}
E entity = context.getRequiredPersistentEntity(actualType);
var entity = context.getRequiredPersistentEntity(actualType);
return from(entity, filter, traversalGuard, basePath);
}
@ -243,16 +242,16 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -243,16 +242,16 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
Set<PersistentPropertyPath<P>> properties = new HashSet<>();
PropertyHandler<P> propertyTester = persistentProperty -> {
var propertyTester = (PropertyHandler<P>) persistentProperty -> {
TypeInformation<?> typeInformation = persistentProperty.getTypeInformation();
TypeInformation<?> actualPropertyType = typeInformation.getActualType();
var typeInformation = persistentProperty.getTypeInformation();
var actualPropertyType = typeInformation.getActualType();
if (basePath.containsPropertyOfType(actualPropertyType)) {
return;
}
DefaultPersistentPropertyPath<P> currentPath = basePath.append(persistentProperty);
var currentPath = basePath.append(persistentProperty);
if (filter.test(persistentProperty)) {
properties.add(currentPath);
@ -265,7 +264,8 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -265,7 +264,8 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
entity.doWithProperties(propertyTester);
AssociationHandler<P> handler = association -> propertyTester.doWithPersistentProperty(association.getInverse());
var handler = (AssociationHandler<P>) association -> propertyTester
.doWithPersistentProperty(association.getInverse());
entity.doWithAssociations(handler);
return properties;
@ -304,12 +304,10 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -304,12 +304,10 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
return true;
}
if (!(o instanceof TypeAndPath)) {
if (!(o instanceof TypeAndPath that)) {
return false;
}
TypeAndPath that = (TypeAndPath) o;
if (!ObjectUtils.nullSafeEquals(type, that.type)) {
return false;
}
@ -323,7 +321,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -323,7 +321,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(type);
var result = ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(path);
return result;
}
@ -364,7 +362,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -364,7 +362,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
List<PersistentPropertyPath<P>> sorted = new ArrayList<>(paths);
Collections.sort(sorted, SHORTEST_PATH.thenComparing(ShortestSegmentFirst.INSTANCE));
sorted.sort(SHORTEST_PATH.thenComparing(ShortestSegmentFirst.INSTANCE));
return new DefaultPersistentPropertyPaths<>(type, sorted);
}
@ -400,7 +398,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -400,7 +398,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
return false;
}
String dotPath = path.toDotPath();
var dotPath = path.toDotPath();
return stream().anyMatch(it -> dotPath.equals(it.toDotPath()));
}
@ -423,7 +421,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -423,7 +421,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
Assert.notNull(predicate, "Predicate must not be null!");
List<PersistentPropertyPath<P>> paths = this.stream() //
var paths = this.stream() //
.filter(it -> !it.stream().anyMatch(predicate)) //
.collect(Collectors.toList());
@ -456,10 +454,10 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -456,10 +454,10 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
@SuppressWarnings("null")
public int compare(PersistentPropertyPath<?> left, PersistentPropertyPath<?> right) {
Function<PersistentProperty<?>, Integer> mapper = it -> it.getName().length();
var mapper = (Function<PersistentProperty<?>, Integer>) it -> it.getName().length();
Stream<Integer> leftNames = left.stream().map(mapper);
Stream<Integer> rightNames = right.stream().map(mapper);
var leftNames = left.stream().map(mapper);
var rightNames = right.stream().map(mapper);
return StreamUtils.zip(leftNames, rightNames, (l, r) -> l - r) //
.filter(it -> it != 0) //

16
src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java

@ -279,7 +279,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P> @@ -279,7 +279,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
@Override
public Class<?> getAssociationTargetType() {
TypeInformation<?> result = getAssociationTargetTypeInformation();
var result = getAssociationTargetTypeInformation();
return result != null ? result.getType() : null;
}
@ -350,7 +350,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P> @@ -350,7 +350,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
if (isMap()) {
TypeInformation<?> mapValueType = information.getMapValueType();
var mapValueType = information.getMapValueType();
if (mapValueType != null) {
return mapValueType.getType();
@ -383,7 +383,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P> @@ -383,7 +383,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
protected TypeInformation<?> getActualTypeInformation() {
TypeInformation<?> targetType = associationTargetType.getNullable();
var targetType = associationTargetType.getNullable();
return targetType == null ? information.getRequiredActualType() : targetType;
}
@ -398,12 +398,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P> @@ -398,12 +398,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
return true;
}
if (!(obj instanceof AbstractPersistentProperty)) {
if (!(obj instanceof AbstractPersistentProperty<?> that)) {
return false;
}
AbstractPersistentProperty<?> that = (AbstractPersistentProperty<?>) obj;
return this.property.equals(that.property);
}
@ -427,10 +425,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P> @@ -427,10 +425,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
private Set<TypeInformation<?>> detectEntityTypes(SimpleTypeHolder simpleTypes) {
TypeInformation<?> typeToStartWith = getAssociationTargetTypeInformation();
var typeToStartWith = getAssociationTargetTypeInformation();
typeToStartWith = typeToStartWith == null ? information : typeToStartWith;
Set<TypeInformation<?>> result = detectEntityTypes(typeToStartWith);
var result = detectEntityTypes(typeToStartWith);
return result.stream()
.filter(it -> !simpleTypes.isSimpleType(it.getType()))
@ -450,7 +448,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P> @@ -450,7 +448,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
result.addAll(detectEntityTypes(source.getComponentType()));
}
TypeInformation<?> actualType = source.getActualType();
var actualType = source.getActualType();
if (source.equals(actualType)) {
result.add(source);

24
src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java

@ -64,7 +64,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -64,7 +64,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
private final Lazy<Boolean> usePropertyAccess = Lazy.of(() -> {
AccessType accessType = findPropertyOrOwnerAnnotation(AccessType.class);
var accessType = findPropertyOrOwnerAnnotation(AccessType.class);
return accessType != null && Type.PROPERTY.equals(accessType.value()) || super.usePropertyAccess();
});
@ -105,7 +105,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -105,7 +105,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
populateAnnotationCache(property);
Value value = findAnnotation(Value.class);
var value = findAnnotation(Value.class);
this.value = value == null ? null : value.value();
}
@ -121,11 +121,11 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -121,11 +121,11 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
Optionals.toStream(property.getGetter(), property.getSetter()).forEach(it -> {
for (Annotation annotation : it.getAnnotations()) {
for (var annotation : it.getAnnotations()) {
Class<? extends Annotation> annotationType = annotation.annotationType();
var annotationType = annotation.annotationType();
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
var mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
validateAnnotation(mergedAnnotation,
"Ambiguous mapping! Annotation %s configured "
@ -139,10 +139,10 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -139,10 +139,10 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
property.getField().ifPresent(it -> {
for (Annotation annotation : it.getAnnotations()) {
for (var annotation : it.getAnnotations()) {
Class<? extends Annotation> annotationType = annotation.annotationType();
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
var annotationType = annotation.annotationType();
var mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
validateAnnotation(mergedAnnotation,
"Ambiguous mapping! Annotation %s configured " + "on field %s and one of its accessor methods in class %s!",
@ -164,7 +164,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -164,7 +164,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
*/
private void validateAnnotation(Annotation candidate, String message, Object... arguments) {
Class<? extends Annotation> annotationType = candidate.annotationType();
var annotationType = candidate.annotationType();
if (!annotationType.getName().startsWith(SPRING_DATA_PACKAGE)) {
return;
@ -251,7 +251,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -251,7 +251,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
@SuppressWarnings("unchecked")
private <A extends Annotation> Optional<A> doFindAnnotation(Class<A> annotationType) {
Optional<? extends Annotation> annotation = annotationCache.get(annotationType);
var annotation = annotationCache.get(annotationType);
if (annotation != null) {
return (Optional<A>) annotation;
@ -274,7 +274,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -274,7 +274,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
@Override
public <A extends Annotation> A findPropertyOrOwnerAnnotation(Class<A> annotationType) {
A annotation = findAnnotation(annotationType);
var annotation = findAnnotation(annotationType);
return annotation != null ? annotation : getOwner().findAnnotation(annotationType);
}
@ -319,7 +319,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -319,7 +319,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
populateAnnotationCache(getProperty());
}
String builder = annotationCache.values().stream() //
var builder = annotationCache.values().stream() //
.flatMap(Optionals::toStream) //
.map(Object::toString) //
.collect(Collectors.joining(" "));

25
src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java

@ -222,7 +222,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -222,7 +222,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
propertyCache.computeIfAbsent(property.getName(), key -> property);
P candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property);
var candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property);
if (candidate != null) {
this.idProperty = candidate;
@ -230,7 +230,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -230,7 +230,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
if (property.isVersionProperty()) {
P versionProperty = this.versionProperty;
var versionProperty = this.versionProperty;
if (versionProperty != null) {
@ -267,7 +267,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -267,7 +267,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
return null;
}
P idProperty = this.idProperty;
var idProperty = this.idProperty;
if (idProperty != null) {
throw new MappingException(String.format("Attempt to add id property %s but already have property %s registered "
@ -311,7 +311,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -311,7 +311,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
private List<P> doFindPersistentProperty(Class<? extends Annotation> annotationType) {
List<P> annotatedProperties = properties.stream() //
var annotatedProperties = properties.stream() //
.filter(it -> it.isAnnotationPresent(annotationType)) //
.collect(Collectors.toList());
@ -356,7 +356,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -356,7 +356,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
Assert.notNull(handler, "PropertyHandler must not be null!");
for (P property : persistentPropertiesCache) {
for (var property : persistentPropertiesCache) {
handler.doWithPersistentProperty(property);
}
}
@ -383,7 +383,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -383,7 +383,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
Assert.notNull(handler, "Handler must not be null!");
for (Association<P> association : associations) {
for (var association : associations) {
handler.doWithAssociation(association);
}
}
@ -522,7 +522,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -522,7 +522,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
@Override
public Iterator<P> iterator() {
Iterator<P> iterator = properties.iterator();
var iterator = properties.iterator();
return new Iterator<P>() {
@ -593,12 +593,13 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -593,12 +593,13 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
*/
private static Alias getAliasFromAnnotation(Class<?> type) {
Optional<String> typeAliasValue = Optional
.ofNullable(AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class))//
.map(TypeAlias::value)//
.filter(StringUtils::hasText);
var typeAlias = AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class);
return Alias.ofNullable(typeAliasValue.orElse(null));
if (typeAlias != null && StringUtils.hasText(typeAlias.value())) {
return Alias.of(typeAlias.value());
}
return Alias.empty();
}
/**

21
src/main/java/org/springframework/data/mapping/model/BeanWrapper.java

@ -19,10 +19,7 @@ import kotlin.reflect.KCallable; @@ -19,10 +19,7 @@ import kotlin.reflect.KCallable;
import kotlin.reflect.KParameter;
import kotlin.reflect.KParameter.Kind;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.data.mapping.MappingException;
@ -68,7 +65,7 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> { @@ -68,7 +65,7 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
if (property.isImmutable()) {
Method wither = property.getWither();
var wither = property.getWither();
if (wither != null) {
@ -89,14 +86,14 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> { @@ -89,14 +86,14 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
if (!property.usePropertyAccess()) {
Field field = property.getRequiredField();
var field = property.getRequiredField();
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, bean, value);
return;
}
Method setter = property.getRequiredSetter();
var setter = property.getRequiredSetter();
ReflectionUtils.makeAccessible(setter);
ReflectionUtils.invokeMethod(setter, bean, value);
@ -133,13 +130,13 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> { @@ -133,13 +130,13 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
if (!property.usePropertyAccess()) {
Field field = property.getRequiredField();
var field = property.getRequiredField();
ReflectionUtils.makeAccessible(field);
return ReflectionUtils.getField(field, bean);
}
Method getter = property.getRequiredGetter();
var getter = property.getRequiredGetter();
ReflectionUtils.makeAccessible(getter);
return ReflectionUtils.invokeMethod(getter, bean);
@ -175,8 +172,8 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> { @@ -175,8 +172,8 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
*/
static <T> Object setProperty(PersistentProperty<?> property, T bean, @Nullable Object value) {
Class<?> type = property.getOwner().getType();
KCallable<?> copy = copyMethodCache.computeIfAbsent(type, it -> getCopyMethod(it, property));
var type = property.getOwner().getType();
var copy = copyMethodCache.computeIfAbsent(type, it -> getCopyMethod(it, property));
if (copy == null) {
throw new UnsupportedOperationException(String.format(
@ -191,9 +188,9 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> { @@ -191,9 +188,9 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
Map<KParameter, Object> args = new LinkedHashMap<>(2, 1);
List<KParameter> parameters = callable.getParameters();
var parameters = callable.getParameters();
for (KParameter parameter : parameters) {
for (var parameter : parameters) {
if (parameter.getKind() == Kind.INSTANCE) {
args.put(parameter, bean);

6
src/main/java/org/springframework/data/mapping/model/CamelCaseSplittingFieldNamingStrategy.java

@ -52,12 +52,12 @@ public class CamelCaseSplittingFieldNamingStrategy implements FieldNamingStrateg @@ -52,12 +52,12 @@ public class CamelCaseSplittingFieldNamingStrategy implements FieldNamingStrateg
@Override
public String getFieldName(PersistentProperty<?> property) {
List<String> parts = ParsingUtils.splitCamelCaseToLower(property.getName());
var parts = ParsingUtils.splitCamelCaseToLower(property.getName());
List<String> result = new ArrayList<>();
for (String part : parts) {
for (var part : parts) {
String candidate = preparePart(part);
var candidate = preparePart(part);
if (StringUtils.hasText(candidate)) {
result.add(candidate);

43
src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java

@ -17,7 +17,6 @@ package org.springframework.data.mapping.model; @@ -17,7 +17,6 @@ package org.springframework.data.mapping.model;
import static org.springframework.asm.Opcodes.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
@ -80,7 +79,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -80,7 +79,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
EntityInstantiator instantiator = this.entityInstantiators.get(entity.getTypeInformation());
var instantiator = this.entityInstantiators.get(entity.getTypeInformation());
if (instantiator == null) {
instantiator = potentiallyCreateAndRegisterEntityInstantiator(entity);
@ -96,8 +95,8 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -96,8 +95,8 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private synchronized EntityInstantiator potentiallyCreateAndRegisterEntityInstantiator(
PersistentEntity<?, ?> entity) {
Map<TypeInformation<?>, EntityInstantiator> map = this.entityInstantiators;
EntityInstantiator instantiator = map.get(entity.getTypeInformation());
var map = this.entityInstantiators;
var instantiator = map.get(entity.getTypeInformation());
if (instantiator != null) {
return instantiator;
@ -164,7 +163,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -164,7 +163,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
return true;
}
Class<?> type = entity.getType();
var type = entity.getType();
if (type.isInterface() //
|| type.isArray() //
@ -174,7 +173,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -174,7 +173,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
return true;
}
PreferredConstructor<?, ?> persistenceConstructor = entity.getPersistenceConstructor();
var persistenceConstructor = entity.getPersistenceConstructor();
if (persistenceConstructor == null || Modifier.isPrivate(persistenceConstructor.getConstructor().getModifiers())) {
return true;
}
@ -245,7 +244,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -245,7 +244,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
Object[] params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
var params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
try {
return (T) instantiator.newInstance(params);
@ -269,9 +268,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -269,9 +268,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
return allocateArguments(0);
}
Object[] params = allocateArguments(constructor.getConstructor().getParameterCount());
var params = allocateArguments(constructor.getConstructor().getParameterCount());
int index = 0;
var index = 0;
for (Parameter<?, P> parameter : constructor.getParameters()) {
params[index++] = provider.getParameterValue(parameter);
}
@ -316,7 +315,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -316,7 +315,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
Object[] params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
var params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
throw new MappingInstantiationException(entity, Arrays.asList(params),
new BeanInstantiationException(typeToCreate, "Class is abstract"));
@ -382,9 +381,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -382,9 +381,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public Class<?> generateCustomInstantiatorClass(PersistentEntity<?, ?> entity,
@Nullable PreferredConstructor<?, ?> constructor) {
String className = generateClassName(entity);
Class<?> type = entity.getType();
ClassLoader classLoader = type.getClassLoader();
var className = generateClassName(entity);
var type = entity.getType();
var classLoader = type.getClassLoader();
if (ClassUtils.isPresent(className, classLoader)) {
@ -395,7 +394,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -395,7 +394,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
}
}
byte[] bytecode = generateBytecode(className, entity, constructor);
var bytecode = generateBytecode(className, entity, constructor);
try {
return ReflectUtils.defineClass(className, bytecode, classLoader, type.getProtectionDomain(), type);
@ -423,7 +422,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -423,7 +422,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public byte[] generateBytecode(String internalClassName, PersistentEntity<?, ?> entity,
@Nullable PreferredConstructor<?, ?> constructor) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_6, ACC_PUBLIC + ACC_SUPER, internalClassName.replace('.', '/'), null, JAVA_LANG_OBJECT,
IMPLEMENTED_INTERFACES);
@ -439,7 +438,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -439,7 +438,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private void visitDefaultConstructor(ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
var mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false);
@ -458,9 +457,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -458,9 +457,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private void visitCreateMethod(ClassWriter cw, PersistentEntity<?, ?> entity,
@Nullable PreferredConstructor<?, ?> constructor) {
String entityTypeResourcePath = Type.getInternalName(entity.getType());
var entityTypeResourcePath = Type.getInternalName(entity.getType());
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
var mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
"([Ljava/lang/Object;)Ljava/lang/Object;", null, null);
mv.visitCode();
mv.visitTypeInsn(NEW, entityTypeResourcePath);
@ -468,11 +467,11 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -468,11 +467,11 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
if (constructor != null) {
Constructor<?> ctor = constructor.getConstructor();
Class<?>[] parameterTypes = ctor.getParameterTypes();
var ctor = constructor.getConstructor();
var parameterTypes = ctor.getParameterTypes();
List<? extends Parameter<Object, ?>> parameters = constructor.getParameters();
for (int i = 0; i < parameterTypes.length; i++) {
for (var i = 0; i < parameterTypes.length; i++) {
mv.visitVarInsn(ALOAD, 1);
@ -483,7 +482,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -483,7 +482,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
if (parameterTypes[i].isPrimitive()) {
mv.visitInsn(DUP);
String parameterName = parameters.size() > i ? parameters.get(i).getName() : null;
var parameterName = parameters.size() > i ? parameters.get(i).getName() : null;
insertAssertNotNull(mv, parameterName == null ? String.format("at index %d", i) : parameterName);
insertUnboxInsns(mv, Type.getType(parameterTypes[i]).toString().charAt(0), "");

153
src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java

@ -48,7 +48,6 @@ import org.springframework.data.mapping.PersistentProperty; @@ -48,7 +48,6 @@ import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.SimpleAssociationHandler;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.mapping.model.KotlinCopyMethod.KotlinCopyByProperty;
import org.springframework.data.util.Optionals;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@ -83,11 +82,11 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -83,11 +82,11 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
@Override
public <T> PersistentPropertyAccessor<T> getPropertyAccessor(PersistentEntity<?, ?> entity, T bean) {
Constructor<?> constructor = constructorMap.get(entity);
var constructor = constructorMap.get(entity);
if (constructor == null) {
Class<PersistentPropertyAccessor<?>> accessorClass = potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
var accessorClass = potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
entity);
constructor = accessorClass.getConstructors()[0];
@ -96,7 +95,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -96,7 +95,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
this.constructorMap = constructorMap;
}
Object[] args = argumentCache.get();
var args = argumentCache.get();
args[0] = bean;
try {
@ -136,7 +135,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -136,7 +135,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static boolean isTypeInjectable(PersistentEntity<?, ?> entity) {
Class<?> type = entity.getType();
var type = entity.getType();
return type.getClassLoader() != null
&& (type.getPackage() == null || !type.getPackage().getName().startsWith("java"))
&& ClassUtils.isPresent(PersistentPropertyAccessor.class.getName(), type.getClassLoader())
@ -146,7 +145,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -146,7 +145,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private boolean hasUniquePropertyHashCodes(PersistentEntity<?, ?> entity) {
Set<Integer> hashCodes = new HashSet<>();
AtomicInteger propertyCount = new AtomicInteger();
var propertyCount = new AtomicInteger();
entity.doWithProperties((SimplePropertyHandler) property -> {
@ -172,8 +171,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -172,8 +171,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private synchronized Class<PersistentPropertyAccessor<?>> potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
PersistentEntity<?, ?> entity) {
Map<TypeInformation<?>, Class<PersistentPropertyAccessor<?>>> map = this.propertyAccessorClasses;
Class<PersistentPropertyAccessor<?>> propertyAccessorClass = map.get(entity.getTypeInformation());
var map = this.propertyAccessorClasses;
var propertyAccessorClass = map.get(entity.getTypeInformation());
if (propertyAccessorClass != null) {
return propertyAccessorClass;
@ -314,9 +313,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -314,9 +313,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
static Class<?> generateCustomAccessorClass(PersistentEntity<?, ?> entity) {
String className = generateClassName(entity);
Class<?> type = entity.getType();
ClassLoader classLoader = type.getClassLoader();
var className = generateClassName(entity);
var type = entity.getType();
var classLoader = type.getClassLoader();
if (ClassUtils.isPresent(className, classLoader)) {
@ -327,7 +326,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -327,7 +326,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
}
}
byte[] bytecode = generateBytecode(className.replace('.', '/'), entity);
var bytecode = generateBytecode(className.replace('.', '/'), entity);
try {
@ -343,10 +342,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -343,10 +342,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
static byte[] generateBytecode(String internalClassName, PersistentEntity<?, ?> entity) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_6, ACC_PUBLIC + ACC_SUPER, internalClassName, null, JAVA_LANG_OBJECT, IMPLEMENTED_INTERFACES);
List<PersistentProperty<?>> persistentProperties = getPersistentProperties(entity);
var persistentProperties = getPersistentProperties(entity);
visitFields(entity, persistentProperties, cw);
visitDefaultConstructor(entity, internalClassName, cw);
@ -393,7 +392,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -393,7 +392,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
cw.visitField(ACC_PRIVATE, BEAN_FIELD, getAccessibleTypeReferenceName(entity), null, null).visitEnd();
for (PersistentProperty<?> property : persistentProperties) {
for (var property : persistentProperties) {
if (property.isImmutable()) {
if (generateMethodHandle(entity, property.getWither())) {
@ -443,7 +442,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -443,7 +442,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv = cw.visitMethod(ACC_PUBLIC, INIT, String.format("(%s)V", getAccessibleTypeReferenceName(entity)), null, null);
mv.visitCode();
Label l0 = new Label();
var l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false);
@ -461,7 +460,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -461,7 +460,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitFieldInsn(PUTFIELD, internalClassName, BEAN_FIELD, getAccessibleTypeReferenceName(entity));
mv.visitInsn(RETURN);
Label l3 = new Label();
var l3 = new Label();
mv.visitLabel(l3);
mv.visitLocalVariable(THIS_REF, referenceName(internalClassName), null, l0, l3, 0);
mv.visitLocalVariable(BEAN_FIELD, getAccessibleTypeReferenceName(entity), null, l0, l3, 1);
@ -490,10 +489,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -490,10 +489,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitStaticInitializer(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
var mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
var l0 = new Label();
var l1 = new Label();
mv.visitLabel(l0);
// lookup = MethodHandles.lookup()
@ -501,9 +500,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -501,9 +500,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
String.format("()%s", referenceName(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP)), false);
mv.visitVarInsn(ASTORE, 0);
List<Class<?>> entityClasses = getPropertyDeclaratingClasses(persistentProperties);
var entityClasses = getPropertyDeclaratingClasses(persistentProperties);
for (Class<?> entityClass : entityClasses) {
for (var entityClass : entityClasses) {
mv.visitLdcInsn(entityClass.getName());
mv.visitMethodInsn(INVOKESTATIC, JAVA_LANG_CLASS, "forName",
@ -511,7 +510,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -511,7 +510,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitVarInsn(ASTORE, classVariableIndex5(entityClasses, entityClass));
}
for (PersistentProperty<?> property : persistentProperties) {
for (var property : persistentProperties) {
if (property.usePropertyAccess()) {
@ -544,9 +543,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -544,9 +543,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitLocalVariable("getter", referenceName(JAVA_LANG_REFLECT_METHOD), null, l0, l1, 3);
mv.visitLocalVariable("wither", referenceName(JAVA_LANG_REFLECT_METHOD), null, l0, l1, 4);
for (Class<?> entityClass : entityClasses) {
for (var entityClass : entityClasses) {
int index = classVariableIndex5(entityClasses, entityClass);
var index = classVariableIndex5(entityClasses, entityClass);
mv.visitLocalVariable(String.format("class_%d", index), referenceName(JAVA_LANG_CLASS), null, l0, l1, index);
}
@ -582,7 +581,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -582,7 +581,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
List<Class<?>> entityClasses, String internalClassName) {
// getter = <entity>.class.getDeclaredMethod()
Method getter = property.getGetter();
var getter = property.getGetter();
if (getter != null) {
@ -634,7 +633,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -634,7 +633,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
Class<?> parameterType = method.getParameterTypes()[0];
var parameterType = method.getParameterTypes()[0];
if (parameterType.isPrimitive()) {
mv.visitFieldInsn(GETSTATIC, Type.getInternalName(autoboxType(method.getParameterTypes()[0])), "TYPE",
@ -677,7 +676,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -677,7 +676,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
// field = <entity>.class.getDeclaredField()
Field field = property.getField();
var field = property.getField();
if (field != null) {
mv.visitVarInsn(ALOAD, classVariableIndex5(entityClasses, field.getDeclaringClass()));
@ -715,10 +714,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -715,10 +714,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitBeanGetter(PersistentEntity<?, ?> entity, String internalClassName, ClassWriter cw) {
// public Object getBean()
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)),
var mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)),
null, null);
mv.visitCode();
Label l0 = new Label();
var l0 = new Label();
// return this.bean
mv.visitLabel(l0);
@ -728,7 +727,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -728,7 +727,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitInsn(ARETURN);
Label l1 = new Label();
var l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable(THIS_REF, referenceName(internalClassName), null, l0, l1, 0);
mv.visitMaxs(1, 1);
@ -759,13 +758,13 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -759,13 +758,13 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitGetProperty(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getProperty",
var mv = cw.visitMethod(ACC_PUBLIC, "getProperty",
"(Lorg/springframework/data/mapping/PersistentProperty;)Ljava/lang/Object;",
"(Lorg/springframework/data/mapping/PersistentProperty<*>;)Ljava/lang/Object;", null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
var l0 = new Label();
var l1 = new Label();
mv.visitLabel(l0);
// Assert.notNull(property)
@ -798,21 +797,21 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -798,21 +797,21 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitGetPropertySwitch(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, MethodVisitor mv) {
Map<String, PropertyStackAddress> propertyStackMap = createPropertyStackMap(persistentProperties);
var propertyStackMap = createPropertyStackMap(persistentProperties);
int[] hashes = new int[propertyStackMap.size()];
Label[] switchJumpLabels = new Label[propertyStackMap.size()];
var hashes = new int[propertyStackMap.size()];
var switchJumpLabels = new Label[propertyStackMap.size()];
List<PropertyStackAddress> stackmap = new ArrayList<>(propertyStackMap.values());
Collections.sort(stackmap);
for (int i = 0; i < stackmap.size(); i++) {
for (var i = 0; i < stackmap.size(); i++) {
PropertyStackAddress propertyStackAddress = stackmap.get(i);
var propertyStackAddress = stackmap.get(i);
hashes[i] = propertyStackAddress.hash;
switchJumpLabels[i] = propertyStackAddress.label;
}
Label dfltLabel = new Label();
var dfltLabel = new Label();
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, PERSISTENT_PROPERTY, "getName",
@ -820,7 +819,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -820,7 +819,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_STRING, "hashCode", "()I", false);
mv.visitLookupSwitchInsn(dfltLabel, hashes, switchJumpLabels);
for (PersistentProperty<?> property : persistentProperties) {
for (var property : persistentProperties) {
mv.visitLabel(propertyStackMap.get(property.getName()).label);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
@ -844,7 +843,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -844,7 +843,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitGetProperty0(PersistentEntity<?, ?> entity, PersistentProperty<?> property,
MethodVisitor mv, String internalClassName) {
Method getter = property.getGetter();
var getter = property.getGetter();
if (property.usePropertyAccess() && getter != null) {
if (generateMethodHandle(entity, getter)) {
@ -858,9 +857,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -858,9 +857,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
// bean.get…
mv.visitVarInsn(ALOAD, 2);
int invokeOpCode = INVOKEVIRTUAL;
Class<?> declaringClass = getter.getDeclaringClass();
boolean interfaceDefinition = declaringClass.isInterface();
var invokeOpCode = INVOKEVIRTUAL;
var declaringClass = getter.getDeclaringClass();
var interfaceDefinition = declaringClass.isInterface();
if (interfaceDefinition) {
invokeOpCode = INVOKEINTERFACE;
@ -872,7 +871,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -872,7 +871,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
}
} else {
Field field = property.getRequiredField();
var field = property.getRequiredField();
if (generateMethodHandle(entity, field)) {
// $fieldGetter.invoke(bean)
@ -922,12 +921,12 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -922,12 +921,12 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetProperty(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "setProperty",
var mv = cw.visitMethod(ACC_PUBLIC, "setProperty",
"(Lorg/springframework/data/mapping/PersistentProperty;Ljava/lang/Object;)V",
"(Lorg/springframework/data/mapping/PersistentProperty<*>;Ljava/lang/Object;)V", null);
mv.visitCode();
Label l0 = new Label();
var l0 = new Label();
mv.visitLabel(l0);
visitAssertNotNull(mv);
@ -940,7 +939,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -940,7 +939,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
visitSetPropertySwitch(entity, persistentProperties, internalClassName, mv);
Label l1 = new Label();
var l1 = new Label();
mv.visitLabel(l1);
visitThrowUnsupportedOperationException(mv, "No accessor to set property %s!");
@ -962,20 +961,20 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -962,20 +961,20 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetPropertySwitch(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, MethodVisitor mv) {
Map<String, PropertyStackAddress> propertyStackMap = createPropertyStackMap(persistentProperties);
var propertyStackMap = createPropertyStackMap(persistentProperties);
int[] hashes = new int[propertyStackMap.size()];
Label[] switchJumpLabels = new Label[propertyStackMap.size()];
var hashes = new int[propertyStackMap.size()];
var switchJumpLabels = new Label[propertyStackMap.size()];
List<PropertyStackAddress> stackmap = new ArrayList<>(propertyStackMap.values());
Collections.sort(stackmap);
for (int i = 0; i < stackmap.size(); i++) {
PropertyStackAddress propertyStackAddress = stackmap.get(i);
for (var i = 0; i < stackmap.size(); i++) {
var propertyStackAddress = stackmap.get(i);
hashes[i] = propertyStackAddress.hash;
switchJumpLabels[i] = propertyStackAddress.label;
}
Label dfltLabel = new Label();
var dfltLabel = new Label();
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, PERSISTENT_PROPERTY, "getName",
@ -983,7 +982,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -983,7 +982,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_STRING, "hashCode", "()I", false);
mv.visitLookupSwitchInsn(dfltLabel, hashes, switchJumpLabels);
for (PersistentProperty<?> property : persistentProperties) {
for (var property : persistentProperties) {
mv.visitLabel(propertyStackMap.get(property.getName()).label);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
@ -1006,8 +1005,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1006,8 +1005,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetProperty0(PersistentEntity<?, ?> entity, PersistentProperty<?> property,
MethodVisitor mv, String internalClassName) {
Method setter = property.getSetter();
Method wither = property.getWither();
var setter = property.getSetter();
var wither = property.getWither();
if (property.isImmutable()) {
@ -1085,7 +1084,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1085,7 +1084,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitKotlinCopy(PersistentEntity<?, ?> entity, PersistentProperty<?> property, MethodVisitor mv,
String internalClassName) {
KotlinCopyMethod kotlinCopyMethod = KotlinCopyMethod.findCopyMethod(entity.getType())
var kotlinCopyMethod = KotlinCopyMethod.findCopyMethod(entity.getType())
.orElseThrow(() -> new IllegalStateException(
String.format("No usable .copy(…) method found in entity %s", entity.getType().getName())));
@ -1101,17 +1100,17 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1101,17 +1100,17 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
visitInvokeMethodSingleArg(mv, kotlinCopyMethod.getPublicCopyMethod());
} else {
Method copy = kotlinCopyMethod.getSyntheticCopyMethod();
Class<?>[] parameterTypes = copy.getParameterTypes();
var copy = kotlinCopyMethod.getSyntheticCopyMethod();
var parameterTypes = copy.getParameterTypes();
// PersonWithId.copy$default..(bean, object, MASK, null)
mv.visitVarInsn(ALOAD, 3);
KotlinCopyByProperty copyByProperty = kotlinCopyMethod.forProperty(property)
var copyByProperty = kotlinCopyMethod.forProperty(property)
.orElseThrow(() -> new IllegalStateException(
String.format("No usable .copy(…) method found for property %s", property)));
for (int i = 1; i < kotlinCopyMethod.getParameterCount(); i++) {
for (var i = 1; i < kotlinCopyMethod.getParameterCount(); i++) {
if (copyByProperty.getParameterPosition() == i) {
@ -1130,7 +1129,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1130,7 +1129,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitInsn(Opcodes.ACONST_NULL);
int invokeOpCode = getInvokeOp(copy, false);
var invokeOpCode = getInvokeOp(copy, false);
mv.visitMethodInsn(invokeOpCode, Type.getInternalName(copy.getDeclaringClass()), copy.getName(),
getArgumentSignature(copy), false);
@ -1190,7 +1189,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1190,7 +1189,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetField(PersistentEntity<?, ?> entity, PersistentProperty<?> property, MethodVisitor mv,
String internalClassName) {
Field field = property.getField();
var field = property.getField();
if (field != null) {
if (generateSetterMethodHandle(entity, field)) {
// $fieldSetter.invoke(bean, object)
@ -1205,7 +1204,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1205,7 +1204,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ALOAD, 2);
Class<?> fieldType = field.getType();
var fieldType = field.getType();
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(autoboxType(fieldType)));
autoboxIfNeeded(autoboxType(fieldType), fieldType, mv);
@ -1225,10 +1224,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1225,10 +1224,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
private static String getArgumentSignature(Method method) {
StringBuilder result = new StringBuilder("(");
var result = new StringBuilder("(");
List<String> argumentTypes = new ArrayList<>();
for (Class<?> parameterType : method.getParameterTypes()) {
for (var parameterType : method.getParameterTypes()) {
result.append("%s");
argumentTypes.add(signatureTypeName(parameterType));
@ -1324,7 +1323,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1324,7 +1323,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
if (isAccessible(entity)) {
if (Modifier.isProtected(member.getModifiers()) || isDefault(member.getModifiers())) {
Package declaringPackage = member.getDeclaringClass().getPackage();
var declaringPackage = member.getDeclaringClass().getPackage();
if (declaringPackage != null && !declaringPackage.equals(entity.getType().getPackage())) {
return true;
@ -1353,15 +1352,15 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1353,15 +1352,15 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitInvokeMethodSingleArg(MethodVisitor mv, Method method) {
Class<?>[] parameterTypes = method.getParameterTypes();
Class<?> parameterType = parameterTypes[0];
Class<?> declaringClass = method.getDeclaringClass();
boolean interfaceDefinition = declaringClass.isInterface();
var parameterTypes = method.getParameterTypes();
var parameterType = parameterTypes[0];
var declaringClass = method.getDeclaringClass();
var interfaceDefinition = declaringClass.isInterface();
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(autoboxType(parameterType)));
autoboxIfNeeded(autoboxType(parameterType), parameterType, mv);
int invokeOpCode = getInvokeOp(method, interfaceDefinition);
var invokeOpCode = getInvokeOp(method, interfaceDefinition);
mv.visitMethodInsn(invokeOpCode, Type.getInternalName(method.getDeclaringClass()), method.getName(),
String.format("(%s)%s", signatureTypeName(parameterType), signatureTypeName(method.getReturnType())),
@ -1370,7 +1369,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1370,7 +1369,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static int getInvokeOp(Method method, boolean interfaceDefinition) {
int invokeOpCode = Modifier.isStatic(method.getModifiers()) ? INVOKESTATIC : INVOKEVIRTUAL;
var invokeOpCode = Modifier.isStatic(method.getModifiers()) ? INVOKESTATIC : INVOKEVIRTUAL;
if (interfaceDefinition) {
invokeOpCode = INVOKEINTERFACE;
@ -1383,7 +1382,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1383,7 +1382,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
Map<String, PropertyStackAddress> stackmap = new HashMap<>();
for (PersistentProperty<?> property : persistentProperties) {
for (var property : persistentProperties) {
stackmap.put(property.getName(), new PropertyStackAddress(new Label(), property.getName().hashCode()));
}
return stackmap;
@ -1444,7 +1443,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert @@ -1444,7 +1443,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
private static boolean hasKotlinCopyMethod(PersistentProperty<?> property) {
Class<?> type = property.getOwner().getType();
var type = property.getOwner().getType();
if (isAccessible(type) && KotlinDetector.isKotlinType(type)) {
return KotlinCopyMethod.findCopyMethod(type).filter(it -> it.supportsProperty(property)).isPresent();

2
src/main/java/org/springframework/data/mapping/model/ConvertingPropertyAccessor.java

@ -70,7 +70,7 @@ public class ConvertingPropertyAccessor<T> extends SimplePersistentPropertyPathA @@ -70,7 +70,7 @@ public class ConvertingPropertyAccessor<T> extends SimplePersistentPropertyPathA
@Override
public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value) {
Object converted = convertIfNecessary(value, path.getRequiredLeafProperty().getType());
var converted = convertIfNecessary(value, path.getRequiredLeafProperty().getType());
super.setProperty(path, converted);
}

3
src/main/java/org/springframework/data/mapping/model/DefaultSpELExpressionEvaluator.java

@ -18,7 +18,6 @@ package org.springframework.data.mapping.model; @@ -18,7 +18,6 @@ package org.springframework.data.mapping.model;
import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@ -51,7 +50,7 @@ public class DefaultSpELExpressionEvaluator implements SpELExpressionEvaluator { @@ -51,7 +50,7 @@ public class DefaultSpELExpressionEvaluator implements SpELExpressionEvaluator {
@SuppressWarnings("unchecked")
public <T> T evaluate(String expression) {
Expression parseExpression = factory.getParser().parseExpression(expression);
var parseExpression = factory.getParser().parseExpression(expression);
return (T) parseExpression.getValue(factory.getEvaluationContext(source));
}
}

4
src/main/java/org/springframework/data/mapping/model/EntityInstantiators.java

@ -87,13 +87,13 @@ public class EntityInstantiators { @@ -87,13 +87,13 @@ public class EntityInstantiators {
public EntityInstantiator getInstantiatorFor(PersistentEntity<?, ?> entity) {
Assert.notNull(entity, "Entity must not be null!");
Class<?> type = entity.getType();
var type = entity.getType();
if (!customInstantiators.containsKey(type)) {
return fallback;
}
EntityInstantiator instantiator = customInstantiators.get(entity.getType());
var instantiator = customInstantiators.get(entity.getType());
return instantiator == null ? fallback : instantiator;
}
}

10
src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java

@ -19,10 +19,8 @@ import java.util.function.Function; @@ -19,10 +19,8 @@ import java.util.function.Function;
import org.springframework.core.KotlinDetector;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@ -76,8 +74,8 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty @@ -76,8 +74,8 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
@Override
public void setProperty(PersistentProperty<?> property, @Nullable Object value) {
PersistentEntity<?, ?> owner = property.getOwner();
PersistentPropertyAccessor<T> delegate = delegateFunction.apply(this.bean);
var owner = property.getOwner();
var delegate = delegateFunction.apply(this.bean);
if (!property.isImmutable() || property.getWither() != null || KotlinDetector.isKotlinType(owner.getType())) {
@ -87,7 +85,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty @@ -87,7 +85,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
return;
}
PreferredConstructor<?, ?> constructor = owner.getPersistenceConstructor();
var constructor = owner.getPersistenceConstructor();
if (constructor == null) {
throw new IllegalStateException(String.format(NO_SETTER_OR_CONSTRUCTOR, property.getName(), owner.getType()));
@ -106,7 +104,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty @@ -106,7 +104,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
}
});
EntityInstantiator instantiator = instantiators.getInstantiatorFor(owner);
var instantiator = instantiators.getInstantiatorFor(owner);
this.bean = (T) instantiator.createInstance(owner, new ParameterValueProvider() {

48
src/main/java/org/springframework/data/mapping/model/KotlinClassGeneratingEntityInstantiator.java

@ -49,16 +49,16 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -49,16 +49,16 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
@Override
protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> entity) {
PreferredConstructor<?, ?> constructor = entity.getPersistenceConstructor();
var constructor = entity.getPersistenceConstructor();
if (KotlinReflectionUtils.isSupportedKotlinClass(entity.getType()) && constructor != null) {
PreferredConstructor<?, ?> defaultConstructor = new DefaultingKotlinConstructorResolver(entity)
var defaultConstructor = new DefaultingKotlinConstructorResolver(entity)
.getDefaultConstructor();
if (defaultConstructor != null) {
ObjectInstantiator instantiator = createObjectInstantiator(entity, defaultConstructor);
var instantiator = createObjectInstantiator(entity, defaultConstructor);
return new DefaultingKotlinClassInstantiatorAdapter(instantiator, constructor);
}
@ -81,8 +81,8 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -81,8 +81,8 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
@SuppressWarnings("unchecked")
DefaultingKotlinConstructorResolver(PersistentEntity<?, ?> entity) {
Constructor<?> hit = resolveDefaultConstructor(entity);
PreferredConstructor<?, ?> persistenceConstructor = entity.getPersistenceConstructor();
var hit = resolveDefaultConstructor(entity);
var persistenceConstructor = entity.getPersistenceConstructor();
if (hit != null && persistenceConstructor != null) {
this.defaultConstructor = new PreferredConstructor<>(hit,
@ -95,16 +95,16 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -95,16 +95,16 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
@Nullable
private static Constructor<?> resolveDefaultConstructor(PersistentEntity<?, ?> entity) {
PreferredConstructor<?, ?> persistenceConstructor = entity.getPersistenceConstructor();
var persistenceConstructor = entity.getPersistenceConstructor();
if (persistenceConstructor == null) {
return null;
}
Constructor<?> hit = null;
Constructor<?> constructor = persistenceConstructor.getConstructor();
var constructor = persistenceConstructor.getConstructor();
for (Constructor<?> candidate : entity.getType().getDeclaredConstructors()) {
for (var candidate : entity.getType().getDeclaredConstructors()) {
// use only synthetic constructors
if (!candidate.isSynthetic()) {
@ -113,15 +113,15 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -113,15 +113,15 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
// candidates must contain at least two additional parameters (int, DefaultConstructorMarker).
// Number of defaulting masks derives from the original constructor arg count
int syntheticParameters = KotlinDefaultMask.getMaskCount(constructor.getParameterCount())
var syntheticParameters = KotlinDefaultMask.getMaskCount(constructor.getParameterCount())
+ /* DefaultConstructorMarker */ 1;
if (constructor.getParameterCount() + syntheticParameters != candidate.getParameterCount()) {
continue;
}
java.lang.reflect.Parameter[] constructorParameters = constructor.getParameters();
java.lang.reflect.Parameter[] candidateParameters = candidate.getParameters();
var constructorParameters = constructor.getParameters();
var candidateParameters = candidate.getParameters();
if (!candidateParameters[candidateParameters.length - 1].getType().getName()
.equals("kotlin.jvm.internal.DefaultConstructorMarker")) {
@ -177,7 +177,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -177,7 +177,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
DefaultingKotlinClassInstantiatorAdapter(ObjectInstantiator instantiator, PreferredConstructor<?, ?> constructor) {
KFunction<?> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(constructor.getConstructor());
var kotlinConstructor = ReflectJvmMapping.getKotlinFunction(constructor.getConstructor());
if (kotlinConstructor == null) {
throw new IllegalArgumentException(
@ -199,7 +199,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -199,7 +199,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
Object[] params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
var params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
try {
return (T) instantiator.newInstance(params);
@ -215,25 +215,25 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -215,25 +215,25 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
throw new IllegalArgumentException("PreferredConstructor must not be null!");
}
Object[] params = allocateArguments(synthetic.getParameterCount()
var params = allocateArguments(synthetic.getParameterCount()
+ KotlinDefaultMask.getMaskCount(synthetic.getParameterCount()) + /* DefaultConstructorMarker */1);
int userParameterCount = kParameters.size();
var userParameterCount = kParameters.size();
List<Parameter<Object, P>> parameters = preferredConstructor.getParameters();
var parameters = preferredConstructor.getParameters();
// Prepare user-space arguments
for (int i = 0; i < userParameterCount; i++) {
for (var i = 0; i < userParameterCount; i++) {
Parameter<Object, P> parameter = parameters.get(i);
var parameter = parameters.get(i);
params[i] = provider.getParameterValue(parameter);
}
KotlinDefaultMask defaultMask = KotlinDefaultMask.from(constructor, it -> {
var defaultMask = KotlinDefaultMask.from(constructor, it -> {
int index = kParameters.indexOf(it);
var index = kParameters.indexOf(it);
Parameter<Object, P> parameter = parameters.get(index);
Class<Object> type = parameter.getType().getType();
var parameter = parameters.get(index);
var type = parameter.getType().getType();
if (it.isOptional() && params[index] == null) {
if (type.isPrimitive()) {
@ -247,9 +247,9 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta @@ -247,9 +247,9 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
return true;
});
int[] defaulting = defaultMask.getDefaulting();
var defaulting = defaultMask.getDefaulting();
// append nullability masks to creation arguments
for (int i = 0; i < defaulting.length; i++) {
for (var i = 0; i < defaulting.length; i++) {
params[userParameterCount + i] = defaulting[i];
}

48
src/main/java/org/springframework/data/mapping/model/KotlinCopyMethod.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.data.mapping.model;
import kotlin.jvm.JvmClassMappingKt;
import kotlin.reflect.KClass;
import kotlin.reflect.KFunction;
import kotlin.reflect.KParameter;
import kotlin.reflect.KParameter.Kind;
@ -26,7 +25,6 @@ import kotlin.reflect.jvm.ReflectJvmMapping; @@ -26,7 +25,6 @@ import kotlin.reflect.jvm.ReflectJvmMapping;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -78,13 +76,13 @@ class KotlinCopyMethod { @@ -78,13 +76,13 @@ class KotlinCopyMethod {
Assert.notNull(type, "Type must not be null!");
Optional<Method> syntheticCopyMethod = findSyntheticCopyMethod(type);
var syntheticCopyMethod = findSyntheticCopyMethod(type);
if (!syntheticCopyMethod.isPresent()) {
return Optional.empty();
}
Optional<Method> publicCopyMethod = syntheticCopyMethod.flatMap(KotlinCopyMethod::findPublicCopyMethod);
var publicCopyMethod = syntheticCopyMethod.flatMap(KotlinCopyMethod::findPublicCopyMethod);
return publicCopyMethod.map(method -> new KotlinCopyMethod(method, syntheticCopyMethod.get()));
}
@ -123,7 +121,7 @@ class KotlinCopyMethod { @@ -123,7 +121,7 @@ class KotlinCopyMethod {
*/
Optional<KotlinCopyByProperty> forProperty(PersistentProperty<?> property) {
int index = KotlinCopyByProperty.findIndex(copyFunction, property.getName());
var index = KotlinCopyByProperty.findIndex(copyFunction, property.getName());
if (index == -1) {
return Optional.empty();
@ -149,9 +147,9 @@ class KotlinCopyMethod { @@ -149,9 +147,9 @@ class KotlinCopyMethod {
return false;
}
Class<?>[] parameterTypes = publicCopyMethod.getParameterTypes();
var parameterTypes = publicCopyMethod.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
for (var i = 0; i < parameterTypes.length; i++) {
if (!parameterTypes[i].equals(persistentProperties.get(i).getType())) {
return false;
}
@ -162,16 +160,16 @@ class KotlinCopyMethod { @@ -162,16 +160,16 @@ class KotlinCopyMethod {
private static Optional<Method> findPublicCopyMethod(Method defaultKotlinMethod) {
Class<?> type = defaultKotlinMethod.getDeclaringClass();
KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(type);
var type = defaultKotlinMethod.getDeclaringClass();
var kotlinClass = JvmClassMappingKt.getKotlinClass(type);
KFunction<?> primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
var primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
if (primaryConstructor == null) {
return Optional.empty();
}
List<KParameter> constructorArguments = getComponentArguments(primaryConstructor);
var constructorArguments = getComponentArguments(primaryConstructor);
return Arrays.stream(type.getDeclaredMethods()).filter(it -> it.getName().equals("copy") //
&& !it.isSynthetic() //
@ -180,7 +178,7 @@ class KotlinCopyMethod { @@ -180,7 +178,7 @@ class KotlinCopyMethod {
&& it.getParameterCount() == constructorArguments.size()) //
.filter(it -> {
KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(it);
var kotlinFunction = ReflectJvmMapping.getKotlinFunction(it);
if (kotlinFunction == null) {
return false;
@ -192,10 +190,10 @@ class KotlinCopyMethod { @@ -192,10 +190,10 @@ class KotlinCopyMethod {
private static boolean parameterMatches(List<KParameter> constructorArguments, KFunction<?> kotlinFunction) {
boolean foundInstance = false;
int constructorArgIndex = 0;
var foundInstance = false;
var constructorArgIndex = 0;
for (KParameter parameter : kotlinFunction.getParameters()) {
for (var parameter : kotlinFunction.getParameters()) {
if (parameter.getKind() == Kind.INSTANCE) {
foundInstance = true;
@ -206,7 +204,7 @@ class KotlinCopyMethod { @@ -206,7 +204,7 @@ class KotlinCopyMethod {
return false;
}
KParameter constructorParameter = constructorArguments.get(constructorArgIndex);
var constructorParameter = constructorArguments.get(constructorArgIndex);
if (constructorParameter.getName() == null || !constructorParameter.getName().equals(parameter.getName())
|| !constructorParameter.getType().equals(parameter.getType())) {
@ -221,8 +219,8 @@ class KotlinCopyMethod { @@ -221,8 +219,8 @@ class KotlinCopyMethod {
private static Optional<Method> findSyntheticCopyMethod(Class<?> type) {
KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(type);
KFunction<?> primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
var kotlinClass = JvmClassMappingKt.getKotlinClass(type);
var primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
if (primaryConstructor == null) {
return Optional.empty();
@ -242,9 +240,9 @@ class KotlinCopyMethod { @@ -242,9 +240,9 @@ class KotlinCopyMethod {
*/
private static boolean matchesPrimaryConstructor(Class<?>[] parameterTypes, KFunction<?> primaryConstructor) {
List<KParameter> constructorArguments = getComponentArguments(primaryConstructor);
var constructorArguments = getComponentArguments(primaryConstructor);
int defaultingArgs = KotlinDefaultMask.from(primaryConstructor, kParameter -> false).getDefaulting().length;
var defaultingArgs = KotlinDefaultMask.from(primaryConstructor, kParameter -> false).getDefaulting().length;
if (parameterTypes.length != 1 /* $this */ + constructorArguments.size() + defaultingArgs + 1 /* object marker */) {
return false;
@ -255,9 +253,9 @@ class KotlinCopyMethod { @@ -255,9 +253,9 @@ class KotlinCopyMethod {
return false;
}
for (int i = 0; i < constructorArguments.size(); i++) {
for (var i = 0; i < constructorArguments.size(); i++) {
KParameter kParameter = constructorArguments.get(i);
var kParameter = constructorArguments.get(i);
if (!isAssignableFrom(parameterTypes[i + 1], kParameter.getType())) {
return false;
@ -276,9 +274,9 @@ class KotlinCopyMethod { @@ -276,9 +274,9 @@ class KotlinCopyMethod {
private static boolean isAssignableFrom(Class<?> target, KType source) {
Type parameterType = ReflectJvmMapping.getJavaType(source);
var parameterType = ReflectJvmMapping.getJavaType(source);
Class<?> rawClass = ResolvableType.forType(parameterType).getRawClass();
var rawClass = ResolvableType.forType(parameterType).getRawClass();
return rawClass == null || target.isAssignableFrom(rawClass);
}
@ -302,7 +300,7 @@ class KotlinCopyMethod { @@ -302,7 +300,7 @@ class KotlinCopyMethod {
static int findIndex(KFunction<?> function, String parameterName) {
for (KParameter parameter : function.getParameters()) {
for (var parameter : function.getParameters()) {
if (parameterName.equals(parameter.getName())) {
return parameter.getIndex();
}

10
src/main/java/org/springframework/data/mapping/model/KotlinDefaultMask.java

@ -45,7 +45,7 @@ public class KotlinDefaultMask { @@ -45,7 +45,7 @@ public class KotlinDefaultMask {
*/
public void forEach(IntConsumer maskCallback) {
for (int i : defaulting) {
for (var i : defaulting) {
maskCallback.accept(i);
}
}
@ -71,12 +71,12 @@ public class KotlinDefaultMask { @@ -71,12 +71,12 @@ public class KotlinDefaultMask {
public static KotlinDefaultMask from(KFunction<?> function, Predicate<KParameter> isPresent) {
List<Integer> masks = new ArrayList<>();
int index = 0;
int mask = 0;
var index = 0;
var mask = 0;
List<KParameter> parameters = function.getParameters();
var parameters = function.getParameters();
for (KParameter parameter : parameters) {
for (var parameter : parameters) {
if (index != 0 && index % Integer.SIZE == 0) {
masks.add(mask);

7
src/main/java/org/springframework/data/mapping/model/MappingInstantiationException.java

@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
*/
package org.springframework.data.mapping.model;
import kotlin.reflect.KFunction;
import kotlin.reflect.jvm.ReflectJvmMapping;
import java.lang.reflect.Constructor;
@ -87,7 +86,7 @@ public class MappingInstantiationException extends RuntimeException { @@ -87,7 +86,7 @@ public class MappingInstantiationException extends RuntimeException {
Optional<? extends PreferredConstructor<?, ?>> constructor = Optional.ofNullable(it.getPersistenceConstructor());
List<String> toStringArgs = new ArrayList<>(arguments.size());
for (Object o : arguments) {
for (var o : arguments) {
toStringArgs.add(ObjectUtils.nullSafeToString(o));
}
@ -100,11 +99,11 @@ public class MappingInstantiationException extends RuntimeException { @@ -100,11 +99,11 @@ public class MappingInstantiationException extends RuntimeException {
private static String toString(PreferredConstructor<?, ?> preferredConstructor) {
Constructor<?> constructor = preferredConstructor.getConstructor();
var constructor = preferredConstructor.getConstructor();
if (KotlinReflectionUtils.isSupportedKotlinClass(constructor.getDeclaringClass())) {
KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(constructor);
var kotlinFunction = ReflectJvmMapping.getKotlinFunction(constructor);
if (kotlinFunction != null) {
return kotlinFunction.toString();

4
src/main/java/org/springframework/data/mapping/model/PersistentEntityIsNewStrategy.java

@ -53,7 +53,7 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy { @@ -53,7 +53,7 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy {
? entity.getRequiredVersionProperty().getType() //
: entity.hasIdProperty() ? entity.getRequiredIdProperty().getType() : null;
Class<?> type = valueType;
var type = valueType;
if (type != null && type.isPrimitive()) {
@ -93,7 +93,7 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy { @@ -93,7 +93,7 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy {
@Override
public boolean isNew(Object entity) {
Object value = valueLookup.apply(entity);
var value = valueLookup.apply(entity);
if (value == null) {
return true;

7
src/main/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProvider.java

@ -18,7 +18,6 @@ package org.springframework.data.mapping.model; @@ -18,7 +18,6 @@ package org.springframework.data.mapping.model;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.lang.Nullable;
@ -52,19 +51,19 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty @@ -52,19 +51,19 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty
@SuppressWarnings("unchecked")
public <T> T getParameterValue(Parameter<T, P> parameter) {
PreferredConstructor<?, P> constructor = entity.getPersistenceConstructor();
var constructor = entity.getPersistenceConstructor();
if (constructor != null && constructor.isEnclosingClassParameter(parameter)) {
return (T) parent;
}
String name = parameter.getName();
var name = parameter.getName();
if (name == null) {
throw new MappingException(String.format("Parameter %s does not have a name!", parameter));
}
P property = entity.getPersistentProperty(name);
var property = entity.getPersistentProperty(name);
if (property == null) {
throw new MappingException(

22
src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java

@ -16,11 +16,9 @@ @@ -16,11 +16,9 @@
package org.springframework.data.mapping.model;
import kotlin.jvm.JvmClassMappingKt;
import kotlin.reflect.KFunction;
import kotlin.reflect.full.KClasses;
import kotlin.reflect.jvm.ReflectJvmMapping;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
@ -113,7 +111,7 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty< @@ -113,7 +111,7 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
List<Constructor<?>> candidates = new ArrayList<>();
Constructor<?> noArg = null;
for (Constructor<?> candidate : rawOwningType.getDeclaredConstructors()) {
for (var candidate : rawOwningType.getDeclaredConstructors()) {
// Synthetic constructors should not be considered
if (candidate.isSynthetic()) {
@ -164,14 +162,14 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty< @@ -164,14 +162,14 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
.findFirst() //
.orElseGet(() -> {
KFunction<T> primaryConstructor = KClasses
var primaryConstructor = KClasses
.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(type.getType()));
if (primaryConstructor == null) {
return DEFAULT.discover(type, entity);
}
Constructor<T> javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
var javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
return javaConstructor != null ? buildPreferredConstructor(javaConstructor, type, entity) : null;
});
@ -209,17 +207,17 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty< @@ -209,17 +207,17 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
return new PreferredConstructor<>((Constructor<T>) constructor);
}
List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor);
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
var parameterTypes = typeInformation.getParameterTypes(constructor);
var parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
Parameter<Object, P>[] parameters = new Parameter[parameterTypes.size()];
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
var parameterAnnotations = constructor.getParameterAnnotations();
for (int i = 0; i < parameterTypes.size(); i++) {
for (var i = 0; i < parameterTypes.size(); i++) {
String name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
TypeInformation<?> type = parameterTypes.get(i);
Annotation[] annotations = parameterAnnotations[i];
var name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
var type = parameterTypes.get(i);
var annotations = parameterAnnotations[i];
parameters[i] = new Parameter(name, type, annotations, entity);
}

10
src/main/java/org/springframework/data/mapping/model/Property.java

@ -223,12 +223,10 @@ public class Property { @@ -223,12 +223,10 @@ public class Property {
return true;
}
if (!(obj instanceof Property)) {
if (!(obj instanceof Property that)) {
return false;
}
Property that = (Property) obj;
return this.field.isPresent() ? this.field.equals(that.field) : this.descriptor.equals(that.descriptor);
}
@ -278,8 +276,8 @@ public class Property { @@ -278,8 +276,8 @@ public class Property {
private static Optional<Method> findWither(TypeInformation<?> owner, String propertyName, Class<?> rawType) {
AtomicReference<Method> resultHolder = new AtomicReference<>();
String methodName = String.format("with%s", StringUtils.capitalize(propertyName));
var resultHolder = new AtomicReference<Method>();
var methodName = String.format("with%s", StringUtils.capitalize(propertyName));
ReflectionUtils.doWithMethods(owner.getType(), it -> {
@ -288,7 +286,7 @@ public class Property { @@ -288,7 +286,7 @@ public class Property {
}
}, it -> isMethodWithSingleParameterOfType(it, methodName, rawType));
Method method = resultHolder.get();
var method = resultHolder.get();
return method != null ? Optional.of(method) : Optional.empty();
}

12
src/main/java/org/springframework/data/mapping/model/ReflectionEntityInstantiator.java

@ -44,15 +44,15 @@ enum ReflectionEntityInstantiator implements EntityInstantiator { @@ -44,15 +44,15 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
PreferredConstructor<? extends T, P> constructor = entity.getPersistenceConstructor();
var constructor = entity.getPersistenceConstructor();
if (constructor == null) {
try {
Class<?> clazz = entity.getType();
if (clazz.isArray()) {
Class<?> ctype = clazz;
int dims = 0;
var ctype = clazz;
var dims = 0;
while (ctype.isArray()) {
ctype = ctype.getComponentType();
dims++;
@ -65,10 +65,10 @@ enum ReflectionEntityInstantiator implements EntityInstantiator { @@ -65,10 +65,10 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
throw new MappingInstantiationException(entity, Collections.emptyList(), e);
}
}
int parameterCount = constructor.getConstructor().getParameterCount();
var parameterCount = constructor.getConstructor().getParameterCount();
Object[] params = parameterCount == 0 ? EMPTY_ARGS : new Object[parameterCount];
int i = 0;
var params = parameterCount == 0 ? EMPTY_ARGS : new Object[parameterCount];
var i = 0;
for (Parameter<?, P> parameter : constructor.getParameters()) {
params[i++] = provider.getParameterValue(parameter);
}

28
src/main/java/org/springframework/data/mapping/model/SimplePersistentPropertyPathAccessor.java

@ -24,6 +24,7 @@ import java.util.stream.Collectors; @@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.CollectionFactory;
import org.springframework.data.mapping.AccessOptions;
import org.springframework.data.mapping.AccessOptions.GetOptions;
@ -31,7 +32,6 @@ import org.springframework.data.mapping.AccessOptions.GetOptions.GetNulls; @@ -31,7 +32,6 @@ import org.springframework.data.mapping.AccessOptions.GetOptions.GetNulls;
import org.springframework.data.mapping.AccessOptions.SetOptions;
import org.springframework.data.mapping.AccessOptions.SetOptions.SetNulls;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPath;
@ -97,7 +97,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -97,7 +97,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, GetOptions options) {
Object bean = getBean();
Object current = bean;
var current = bean;
if (path.isEmpty()) {
return bean;
@ -109,8 +109,8 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -109,8 +109,8 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return handleNull(path, options.getNullValues().toNullHandling());
}
PersistentEntity<?, ? extends PersistentProperty<?>> entity = property.getOwner();
PersistentPropertyAccessor<Object> accessor = entity.getPropertyAccessor(current);
var entity = property.getOwner();
var accessor = entity.getPropertyAccessor(current);
current = accessor.getProperty(property);
}
@ -148,18 +148,18 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -148,18 +148,18 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
Assert.notNull(path, "PersistentPropertyPath must not be null!");
Assert.isTrue(!path.isEmpty(), "PersistentPropertyPath must not be empty!");
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
PersistentProperty<?> leafProperty = path.getRequiredLeafProperty();
var parentPath = path.getParentPath();
var leafProperty = path.getRequiredLeafProperty();
if (!options.propagate(parentPath.getLeafProperty())) {
return;
}
GetOptions lookupOptions = options.getNullHandling() != REJECT
var lookupOptions = options.getNullHandling() != REJECT
? DEFAULT_GET_OPTIONS.withNullValues(GetNulls.EARLY_RETURN)
: DEFAULT_GET_OPTIONS;
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
var parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
if (parent == null) {
handleNull(path, options.getNullHandling());
@ -172,7 +172,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -172,7 +172,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return;
}
PersistentProperty<?> parentProperty = parentPath.getRequiredLeafProperty();
var parentProperty = parentPath.getRequiredLeafProperty();
Object newValue;
@ -196,7 +196,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -196,7 +196,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return;
}
Map<Object, Object> result = CollectionFactory.createApproximateMap(source, source.size());
var result = CollectionFactory.createApproximateMap(source, source.size());
for (Entry<?, Object> entry : source.entrySet()) {
result.put(entry.getKey(), setValue(entry.getValue(), leafProperty, value));
@ -225,14 +225,14 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -225,14 +225,14 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return null;
}
String nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
if (SetNulls.SKIP_AND_LOG.equals(handling)) {
logger.info(nullIntermediateMessage);
return null;
}
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
var parentPath = path.getParentPath();
throw new MappingException(String.format(nullIntermediateMessage, parentPath.getLeafProperty(), path.toDotPath(),
getBean().getClass().getName()));
@ -249,7 +249,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -249,7 +249,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
*/
private static Object setValue(Object parent, PersistentProperty<?> property, @Nullable Object newValue) {
PersistentPropertyAccessor<Object> accessor = property.getAccessorForOwner(parent);
var accessor = property.getAccessorForOwner(parent);
accessor.setProperty(property, newValue);
return accessor.getBean();
}
@ -269,7 +269,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA @@ -269,7 +269,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
Assert.notNull(property, "Property must not be null!");
Assert.notNull(type, "Type must not be null!");
Object value = getProperty(property);
var value = getProperty(property);
if (value == null) {
return null;

11
src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java

@ -21,7 +21,6 @@ import java.util.Date; @@ -21,7 +21,6 @@ import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
@ -123,7 +122,7 @@ public class SimpleTypeHolder { @@ -123,7 +122,7 @@ public class SimpleTypeHolder {
private void registerCachePositives(Map<Class<?>, Boolean> source) {
for (Entry<Class<?>, Boolean> entry : source.entrySet()) {
for (var entry : source.entrySet()) {
if (!entry.getValue()) {
continue;
@ -143,8 +142,8 @@ public class SimpleTypeHolder { @@ -143,8 +142,8 @@ public class SimpleTypeHolder {
Assert.notNull(type, "Type must not be null!");
Map<Class<?>, Boolean> localSimpleTypes = this.simpleTypes;
Boolean isSimpleType = localSimpleTypes.get(type);
var localSimpleTypes = this.simpleTypes;
var isSimpleType = localSimpleTypes.get(type);
if (Object.class.equals(type) || Enum.class.isAssignableFrom(type)) {
return true;
@ -154,13 +153,13 @@ public class SimpleTypeHolder { @@ -154,13 +153,13 @@ public class SimpleTypeHolder {
return isSimpleType;
}
String typeName = type.getName();
var typeName = type.getName();
if (typeName.startsWith("java.lang") || type.getName().startsWith("java.time") || typeName.equals("kotlin.Unit")) {
return true;
}
for (Class<?> simpleType : localSimpleTypes.keySet()) {
for (var simpleType : localSimpleTypes.keySet()) {
if (simpleType.isAssignableFrom(type)) {

2
src/main/java/org/springframework/data/mapping/model/SpELContext.java

@ -100,7 +100,7 @@ public class SpELContext { @@ -100,7 +100,7 @@ public class SpELContext {
*/
public EvaluationContext getEvaluationContext(Object source) {
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(source);
var evaluationContext = new StandardEvaluationContext(source);
evaluationContext.addPropertyAccessor(accessor);
if (factory != null) {

2
src/main/java/org/springframework/data/mapping/model/SpELExpressionParameterValueProvider.java

@ -53,7 +53,7 @@ public class SpELExpressionParameterValueProvider<P extends PersistentProperty<P @@ -53,7 +53,7 @@ public class SpELExpressionParameterValueProvider<P extends PersistentProperty<P
return delegate == null ? null : delegate.getParameterValue(parameter);
}
Object object = evaluator.evaluate(parameter.getSpelExpression());
var object = evaluator.evaluate(parameter.getSpelExpression());
return object == null ? null : potentiallyConvertSpelValue(object, parameter);
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save