Reintroduce explicit local variable types.

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

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

View File

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

View File

@@ -129,7 +129,7 @@ public abstract class AuditingHandlerSupport {
private <T> T touch(Auditor<?> auditor, T target, boolean isNew) {
var wrapper = factory.getBeanWrapperFor(target);
Optional<AuditableBeanWrapper<T>> wrapper = factory.getBeanWrapperFor(target);
return wrapper.map(it -> {
@@ -185,7 +185,7 @@ public abstract class AuditingHandlerSupport {
Assert.notNull(wrapper, "AuditableBeanWrapper must not be null!");
var now = dateTimeProvider.getNow();
Optional<TemporalAccessor> now = dateTimeProvider.getNow();
Assert.notNull(now, () -> String.format("Now must not be null! Returned by: %s!", dateTimeProvider.getClass()));

View File

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

View File

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

View File

@@ -16,6 +16,7 @@
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;
@@ -61,7 +62,7 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
return object;
}
var entity = entities
PersistentEntity<?, ? extends PersistentProperty<?>> entity = entities
.getRequiredPersistentEntity(object.getClass());
return entity.isNew(object) ? markCreated(object) : markModified(object);

View File

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

View File

@@ -18,6 +18,7 @@ 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;
@@ -61,7 +62,7 @@ public class ReactiveIsNewAwareAuditingHandler extends ReactiveAuditingHandler {
return Mono.just(object);
}
var entity = entities
PersistentEntity<?, ? extends PersistentProperty<?>> entity = entities
.getRequiredPersistentEntity(object.getClass());
return entity.isNew(object) ? markCreated(object) : markModified(object);

View File

@@ -16,6 +16,7 @@
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;
@@ -46,7 +47,7 @@ public class AnnotationAuditingConfiguration implements AuditingConfiguration {
Assert.notNull(metadata, "AnnotationMetadata must not be null!");
Assert.notNull(annotation, "Annotation must not be null!");
var attributesSource = metadata.getAnnotationAttributes(annotation.getName());
Map<String, Object> attributesSource = metadata.getAnnotationAttributes(annotation.getName());
if (attributesSource == null) {
throw new IllegalArgumentException(String.format(MISSING_ANNOTATION_ATTRIBUTES, annotation, metadata));

View File

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

View File

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

View File

@@ -16,6 +16,7 @@
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;
@@ -60,8 +61,8 @@ public class BeanComponentDefinitionBuilder {
Assert.notNull(builder, "Builder must not be null!");
var definition = builder.getRawBeanDefinition();
var name = BeanDefinitionReaderUtils.generateBeanName(definition, context.getRegistry(), context.isNested());
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
String name = BeanDefinitionReaderUtils.generateBeanName(definition, context.getRegistry(), context.isNested());
return getComponent(builder, name);
}
@@ -78,7 +79,7 @@ public class BeanComponentDefinitionBuilder {
Assert.hasText(fallback, "Fallback component id must not be null or empty!");
var id = defaultSource.getAttribute("id");
String id = defaultSource.getAttribute("id");
return getComponent(builder, StringUtils.hasText(id) ? id : fallback);
}
@@ -107,7 +108,7 @@ public class BeanComponentDefinitionBuilder {
Assert.notNull(builder, "Builder must not be null!");
Assert.hasText(name, "Name of bean must not be null or empty!");
var definition = builder.getRawBeanDefinition();
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
definition.setSource(context.extractSource(rawSource));
return new BeanComponentDefinition(definition, name);

View File

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

View File

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

View File

@@ -35,6 +35,7 @@ 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 +86,13 @@ public class TypeFilterParser {
*/
public Collection<TypeFilter> parseTypeFilters(Element element, Type type) {
var nodeList = element.getChildNodes();
NodeList nodeList = element.getChildNodes();
Collection<TypeFilter> filters = new HashSet<>();
for (var i = 0; i < nodeList.getLength(); i++) {
for (int i = 0; i < nodeList.getLength(); i++) {
var node = nodeList.item(i);
var childElement = type.getElement(node);
Node node = nodeList.item(i);
Element childElement = type.getElement(node);
if (childElement == null) {
continue;
@@ -116,12 +117,12 @@ public class TypeFilterParser {
*/
protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) {
var filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
var expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
try {
var filter = FilterType.fromString(filterType);
FilterType filter = FilterType.fromString(filterType);
return filter.getFilter(expression, classLoader);
} catch (ClassNotFoundException ex) {
@@ -171,7 +172,7 @@ public class TypeFilterParser {
@Override
public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException {
var filterClass = classLoader.loadClass(expression);
Class<?> filterClass = classLoader.loadClass(expression);
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
throw new IllegalArgumentException(
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
@@ -199,7 +200,7 @@ public class TypeFilterParser {
*/
static FilterType fromString(String typeString) {
for (var filter : FilterType.values()) {
for (FilterType filter : FilterType.values()) {
if (filter.name().equalsIgnoreCase(typeString)) {
return filter;
}
@@ -230,7 +231,7 @@ public class TypeFilterParser {
Element getElement(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
var localName = node.getLocalName();
String localName = node.getLocalName();
if (elementName.equals(localName)) {
return (Element) node;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -61,7 +61,7 @@ public class HashMapChangeSet implements ChangeSet {
@Nullable
public <T> T get(String key, Class<T> requiredClass, ConversionService conversionService) {
var value = values.get(key);
Object value = values.get(key);
if (value == null) {
return null;

View File

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

View File

@@ -132,8 +132,8 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
return false;
}
var contentEqual = this.content.equals(that.content);
var pageableEqual = this.pageable.equals(that.pageable);
boolean contentEqual = this.content.equals(that.content);
boolean pageableEqual = this.pageable.equals(that.pageable);
return contentEqual && pageableEqual;
}
@@ -141,7 +141,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
@Override
public int hashCode() {
var result = 17;
int result = 17;
result += 31 * pageable.hashCode();
result += 31 * content.hashCode();

View File

@@ -124,7 +124,7 @@ public interface ExampleMatcher {
Assert.hasText(propertyPath, "PropertyPath must not be empty!");
Assert.notNull(matcherConfigurer, "MatcherConfigurer must not be empty!");
var genericPropertyMatcher = new GenericPropertyMatcher();
GenericPropertyMatcher genericPropertyMatcher = new GenericPropertyMatcher();
matcherConfigurer.configureMatcher(genericPropertyMatcher);
return withMatcher(propertyPath, genericPropertyMatcher);
@@ -463,7 +463,7 @@ public interface ExampleMatcher {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(stringMatcher);
int result = ObjectUtils.nullSafeHashCode(stringMatcher);
result = 31 * result + ObjectUtils.nullSafeHashCode(ignoreCase);
result = 31 * result + ObjectUtils.nullSafeHashCode(valueTransformer);
return result;
@@ -753,7 +753,7 @@ public interface ExampleMatcher {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(path);
int result = ObjectUtils.nullSafeHashCode(path);
result = 31 * result + ObjectUtils.nullSafeHashCode(stringMatcher);
result = 31 * result + ObjectUtils.nullSafeHashCode(ignoreCase);
result = 31 * result + ObjectUtils.nullSafeHashCode(valueTransformer);

View File

@@ -89,8 +89,8 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
@Override
public String toString() {
var contentType = "UNKNOWN";
var content = getContent();
String contentType = "UNKNOWN";
List<T> content = getContent();
if (!content.isEmpty() && content.get(0) != null) {
contentType = content.get(0).getClass().getName();
@@ -116,7 +116,7 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
@Override
public int hashCode() {
var result = 17;
int result = 17;
result += 31 * (int) (total ^ total >>> 32);
result += 31 * super.hashCode();

View File

@@ -231,7 +231,7 @@ public final class Range<T extends Comparable<T>> {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(lowerBound);
int result = ObjectUtils.nullSafeHashCode(lowerBound);
result = 31 * result + ObjectUtils.nullSafeHashCode(upperBound);
return result;
}
@@ -426,7 +426,7 @@ public final class Range<T extends Comparable<T>> {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(value);
int result = ObjectUtils.nullSafeHashCode(value);
result = 31 * result + (inclusive ? 1 : 0);
return result;
}

View File

@@ -71,8 +71,8 @@ public class SliceImpl<T> extends Chunk<T> {
@Override
public String toString() {
var contentType = "UNKNOWN";
var content = getContent();
String contentType = "UNKNOWN";
List<T> content = getContent();
if (content.size() > 0) {
contentType = content.get(0).getClass().getName();
@@ -98,7 +98,7 @@ public class SliceImpl<T> extends Chunk<T> {
@Override
public int hashCode() {
var result = 17;
int result = 17;
result += 31 * (hasNext ? 1 : 0);
result += 31 * super.hashCode();

View File

@@ -193,9 +193,9 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
Assert.notNull(sort, "Sort must not be null!");
var these = new ArrayList<Order>(this.toList());
ArrayList<Order> these = new ArrayList<Order>(this.toList());
for (var order : sort) {
for (Order order : sort) {
these.add(order);
}
@@ -211,7 +211,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Nullable
public Order getOrderFor(String property) {
for (var order : this) {
for (Order order : this) {
if (order.getProperty().equals(property)) {
return order;
}
@@ -241,7 +241,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Override
public int hashCode() {
var result = 17;
int result = 17;
result = 31 * result + orders.hashCode();
return result;
}
@@ -585,7 +585,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Override
public int hashCode() {
var result = 17;
int result = 17;
result = 31 * result + direction.hashCode();
result = 31 * result + property.hashCode();
@@ -613,7 +613,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
@Override
public String toString() {
var result = String.format("%s: %s", property, direction);
String result = String.format("%s: %s", property, direction);
if (!NullHandling.NATIVE.equals(nullHandling)) {
result += ", " + nullHandling;

View File

@@ -66,7 +66,7 @@ class TypedExample<T> implements Example<T> {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(probe);
int result = ObjectUtils.nullSafeHashCode(probe);
result = 31 * result + ObjectUtils.nullSafeHashCode(matcher);
return result;
}

View File

@@ -89,8 +89,8 @@ class TypedExampleMatcher implements ExampleMatcher {
Assert.hasText(propertyPath, "PropertyPath must not be empty!");
Assert.notNull(genericPropertyMatcher, "GenericPropertyMatcher must not be empty!");
var propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
var propertySpecifier = new PropertySpecifier(propertyPath);
PropertySpecifiers propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
PropertySpecifier propertySpecifier = new PropertySpecifier(propertyPath);
if (genericPropertyMatcher.ignoreCase != null) {
propertySpecifier = propertySpecifier.withIgnoreCase(genericPropertyMatcher.ignoreCase);
@@ -114,8 +114,8 @@ class TypedExampleMatcher implements ExampleMatcher {
Assert.hasText(propertyPath, "PropertyPath must not be empty!");
Assert.notNull(propertyValueTransformer, "PropertyValueTransformer must not be empty!");
var propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
var propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
PropertySpecifiers propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
PropertySpecifier propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
propertySpecifiers.add(propertySpecifier.withValueTransformer(propertyValueTransformer));
@@ -129,10 +129,10 @@ class TypedExampleMatcher implements ExampleMatcher {
Assert.notEmpty(propertyPaths, "PropertyPaths must not be empty!");
Assert.noNullElements(propertyPaths, "PropertyPaths must not contain null elements!");
var propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
PropertySpecifiers propertySpecifiers = new PropertySpecifiers(this.propertySpecifiers);
for (var propertyPath : propertyPaths) {
var propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
for (String propertyPath : propertyPaths) {
PropertySpecifier propertySpecifier = getOrCreatePropertySpecifier(propertyPath, propertySpecifiers);
propertySpecifiers.add(propertySpecifier.withIgnoreCase(true));
}
@@ -230,7 +230,7 @@ class TypedExampleMatcher implements ExampleMatcher {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(nullHandler);
int result = ObjectUtils.nullSafeHashCode(nullHandler);
result = 31 * result + ObjectUtils.nullSafeHashCode(defaultStringMatcher);
result = 31 * result + ObjectUtils.nullSafeHashCode(propertySpecifiers);
result = 31 * result + ObjectUtils.nullSafeHashCode(ignoredPaths);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -89,7 +89,7 @@ public class Box implements Shape {
@Override
public int hashCode() {
var result = 31;
int result = 31;
result += 17 * first.hashCode();
result += 17 * second.hashCode();

View File

@@ -111,7 +111,7 @@ public class Circle implements Shape {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(center);
int result = ObjectUtils.nullSafeHashCode(center);
result = 31 * result + ObjectUtils.nullSafeHashCode(radius);
return result;
}

View File

@@ -121,7 +121,7 @@ public final class Distance implements Serializable, Comparable<Distance> {
Assert.notNull(other, "Distance to add must not be null!");
var newNormalizedValue = getNormalizedValue() + other.getNormalizedValue();
double newNormalizedValue = getNormalizedValue() + other.getNormalizedValue();
return new Distance(newNormalizedValue * metric.getMultiplier(), metric);
}
@@ -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!");
var newLeft = getNormalizedValue() * metric.getMultiplier();
var newRight = other.getNormalizedValue() * metric.getMultiplier();
double newLeft = getNormalizedValue() * metric.getMultiplier();
double newRight = other.getNormalizedValue() * metric.getMultiplier();
return new Distance(newLeft + newRight, metric);
}
@@ -165,7 +165,7 @@ public final class Distance implements Serializable, Comparable<Distance> {
return 1;
}
var difference = this.getNormalizedValue() - that.getNormalizedValue();
double difference = this.getNormalizedValue() - that.getNormalizedValue();
return difference == 0 ? 0 : difference > 0 ? 1 : -1;
}
@@ -173,7 +173,7 @@ public final class Distance implements Serializable, Comparable<Distance> {
@Override
public String toString() {
var builder = new StringBuilder();
StringBuilder builder = new StringBuilder();
builder.append(value);
if (metric != Metrics.NEUTRAL) {

View File

@@ -71,7 +71,7 @@ public final class GeoResult<T> implements Serializable {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(content);
int result = ObjectUtils.nullSafeHashCode(content);
result = 31 * result + ObjectUtils.nullSafeHashCode(distance);
return result;
}

View File

@@ -120,7 +120,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(results);
int result = ObjectUtils.nullSafeHashCode(results);
result = 31 * result + ObjectUtils.nullSafeHashCode(averageDistance);
return result;
}
@@ -140,7 +140,7 @@ public class GeoResults<T> implements Iterable<GeoResult<T>>, Serializable {
return new Distance(0, metric);
}
var averageDistance = results.stream()//
double averageDistance = results.stream()//
.mapToDouble(it -> it.getDistance().getValue())//
.average().orElse(0);

View File

@@ -83,9 +83,9 @@ public class Point implements Serializable {
@Override
public int hashCode() {
var result = 1;
int result = 1;
var temp = Double.doubleToLongBits(x);
long temp = Double.doubleToLongBits(x);
result = 31 * result + (int) (temp ^ temp >>> 32);
temp = Double.doubleToLongBits(y);

View File

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

View File

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

View File

@@ -140,7 +140,7 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(metadata);
int result = ObjectUtils.nullSafeHashCode(metadata);
result = 31 * result + ObjectUtils.nullSafeHashCode(entity);
return result;
}

View File

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

View File

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

View File

@@ -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()));
var caster = (Function<Object, T>) it -> type.cast(it);
Function<Object, T> caster = (Function<Object, T>) it -> type.cast(it);
return registerHandler(property, caster.andThen(handler));
}
@@ -201,7 +201,7 @@ public class AccessOptions {
@Nullable
Object postProcess(PersistentProperty<?> property, @Nullable Object value) {
var handler = handlers.get(property);
Function<Object, Object> handler = handlers.get(property);
return handler == null ? value : handler.apply(value);
}

View File

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

View File

@@ -87,13 +87,13 @@ class InstanceCreatorMetadataSupport<T, P extends PersistentProperty<P>> impleme
Assert.notNull(property, "Property must not be null!");
var cached = isPropertyParameterCache.get(property);
Boolean cached = isPropertyParameterCache.get(property);
if (cached != null) {
return cached;
}
var result = doGetIsCreatorParameter(property);
boolean result = doGetIsCreatorParameter(property);
isPropertyParameterCache.put(property, result);

View File

@@ -71,7 +71,7 @@ public class Parameter<T, P extends PersistentProperty<P>> {
throw new IllegalStateException();
}
var owningType = entity.getType();
Class<T> owningType = entity.getType();
return owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass());
});
@@ -179,7 +179,7 @@ public class Parameter<T, P extends PersistentProperty<P>> {
*/
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(name);
int result = ObjectUtils.nullSafeHashCode(name);
result = 31 * result + ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(key);
result = 31 * result + ObjectUtils.nullSafeHashCode(entity);
@@ -194,10 +194,10 @@ public class Parameter<T, P extends PersistentProperty<P>> {
*/
boolean maps(PersistentProperty<?> property) {
var entity = this.entity;
var name = this.name;
PersistentEntity<T, P> entity = this.entity;
String name = this.name;
var referencedProperty = entity == null ? null : name == null ? null : entity.getPersistentProperty(name);
P referencedProperty = entity == null ? null : name == null ? null : entity.getPersistentProperty(name);
return property.equals(referencedProperty);
}

View File

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

View File

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

View File

@@ -61,26 +61,27 @@ public interface PersistentPropertyAccessor<T> {
Assert.notNull(path, "PersistentPropertyPath must not be null!");
Assert.isTrue(!path.isEmpty(), "PersistentPropertyPath must not be empty!");
var parentPath = path.getParentPath();
var leafProperty = path.getRequiredLeafProperty();
var parentProperty = parentPath.isEmpty() ? null : parentPath.getLeafProperty();
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
PersistentProperty<? extends PersistentProperty<?>> leafProperty = path.getRequiredLeafProperty();
PersistentProperty<? extends PersistentProperty<?>> 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()));
}
var parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
if (parent == null) {
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
String 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()));
}
var accessor = parent == getBean() //
PersistentPropertyAccessor<?> accessor = parent == getBean() //
? this //
: leafProperty.getOwner().getPropertyAccessor(parent);
@@ -90,7 +91,7 @@ public interface PersistentPropertyAccessor<T> {
return;
}
var bean = accessor.getBean();
Object bean = accessor.getBean();
if (bean != parent) {
setProperty(parentPath, bean);
@@ -140,7 +141,7 @@ public interface PersistentPropertyAccessor<T> {
default Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, TraversalContext context) {
Object bean = getBean();
var current = bean;
Object current = bean;
if (path.isEmpty()) {
return bean;
@@ -150,14 +151,14 @@ public interface PersistentPropertyAccessor<T> {
if (current == null) {
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
String 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()));
}
var entity = property.getOwner();
var accessor = entity.getPropertyAccessor(current);
PersistentEntity<?, ? extends PersistentProperty<?>> entity = property.getOwner();
PersistentPropertyAccessor<Object> accessor = entity.getPropertyAccessor(current);
current = context.postProcess(property, accessor.getProperty(property));
}

View File

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

View File

@@ -22,6 +22,7 @@ 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;
@@ -82,8 +83,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!");
var propertyName = Introspector.decapitalize(name);
var propertyType = owningType.getProperty(propertyName);
String propertyName = Introspector.decapitalize(name);
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
if (propertyType == null) {
throw new PropertyReferenceException(propertyName, owningType, base);
@@ -122,7 +123,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
public PropertyPath getLeafProperty() {
var result = this;
PropertyPath result = this;
while (result.hasNext()) {
result = result.requiredNext();
@@ -208,7 +209,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
Assert.hasText(path, "Path must not be null or empty!");
var lookup = toDotPath().concat(".").concat(path);
String lookup = toDotPath().concat(".").concat(path);
return PropertyPath.from(lookup, owningType);
}
@@ -226,7 +227,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
@Nullable
public PropertyPath next() {
var result = current;
PropertyPath result = current;
if (result == null) {
return null;
@@ -278,7 +279,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(owningType);
int result = ObjectUtils.nullSafeHashCode(owningType);
result = 31 * result + ObjectUtils.nullSafeHashCode(name);
result = 31 * result + ObjectUtils.nullSafeHashCode(typeInformation);
result = 31 * result + ObjectUtils.nullSafeHashCode(actualTypeInformation);
@@ -295,7 +296,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
private PropertyPath requiredNext() {
var result = next;
PropertyPath result = next;
if (result == null) {
throw new IllegalStateException(
@@ -334,17 +335,17 @@ public class PropertyPath implements Streamable<PropertyPath> {
List<String> iteratorSource = new ArrayList<>();
var matcher = isQuoted(it.path) ? SPLITTER_FOR_QUOTED.matcher(it.path.replace("\\Q", "").replace("\\E", ""))
Matcher 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));
}
var parts = iteratorSource.iterator();
Iterator<String> parts = iteratorSource.iterator();
PropertyPath result = null;
var current = new Stack<PropertyPath>();
Stack<PropertyPath> current = new Stack<PropertyPath>();
while (parts.hasNext()) {
if (result == null) {
@@ -377,9 +378,9 @@ public class PropertyPath implements Streamable<PropertyPath> {
*/
private static PropertyPath create(String source, Stack<PropertyPath> base) {
var previous = base.peek();
PropertyPath previous = base.peek();
var propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base);
PropertyPath propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base);
previous.next = propertyPath;
return propertyPath;
}
@@ -443,13 +444,13 @@ public class PropertyPath implements Streamable<PropertyPath> {
exception = e;
}
var matcher = NESTED_PROPERTY_PATTERN.matcher(source);
Matcher matcher = NESTED_PROPERTY_PATTERN.matcher(source);
if (matcher.find() && matcher.start() != 0) {
var position = matcher.start();
var head = source.substring(0, position);
var tail = source.substring(position);
int position = matcher.start();
String head = source.substring(0, position);
String tail = source.substring(position);
try {
return create(head, type, tail + addTail, base);
@@ -508,7 +509,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(type);
int result = ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(path);
return result;
}

View File

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

View File

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

View File

@@ -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()));
var caster = (Function<Object, T>) it -> type.cast(it);
Function<Object, T> caster = (Function<Object, T>) it -> type.cast(it);
return registerHandler(property, caster.andThen(handler));
}
@@ -139,7 +139,7 @@ public class TraversalContext {
@Nullable
Object postProcess(PersistentProperty<?> property, @Nullable Object value) {
var handler = handlers.get(property);
Function<Object, Object> handler = handlers.get(property);
return handler == null ? value : handler.apply(value);
}

View File

@@ -19,6 +19,7 @@ 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;
@@ -64,22 +65,22 @@ class DefaultEntityCallbacks implements EntityCallbacks {
Assert.notNull(entity, "Entity must not be null!");
var entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
Class<T> entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
: callbackDiscoverer.resolveDeclaredEntityType(callbackType).getRawClass());
var callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
Method callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
var method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
Method method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
ReflectionUtils.makeAccessible(method);
return method;
});
var value = entity;
T value = entity;
for (var callback : callbackDiscoverer.getEntityCallbacks(entityType,
for (EntityCallback<T> callback : callbackDiscoverer.getEntityCallbacks(entityType,
ResolvableType.forClass(callbackType))) {
var callbackFunction = EntityCallbackDiscoverer
BiFunction<EntityCallback<T>, T, Object> callbackFunction = EntityCallbackDiscoverer
.computeCallbackInvokerFunction(callback, callbackMethod, args);
value = callbackInvoker.invokeCallback(callback, value, callbackFunction);
}
@@ -100,7 +101,7 @@ class DefaultEntityCallbacks implements EntityCallbacks {
try {
var value = callbackInvokerFunction.apply(callback, entity);
Object value = callbackInvokerFunction.apply(callback, entity);
if (value != null) {
return (T) value;
@@ -111,12 +112,12 @@ class DefaultEntityCallbacks implements EntityCallbacks {
} catch (IllegalArgumentException | ClassCastException ex) {
var msg = ex.getMessage();
String 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.
var logger = LogFactory.getLog(getClass());
Log logger = LogFactory.getLog(getClass());
if (logger.isDebugEnabled()) {
logger.debug("Non-matching callback type for entity callback: " + callback, ex);
}

View File

@@ -21,6 +21,7 @@ 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;
@@ -65,22 +66,22 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
Assert.notNull(entity, "Entity must not be null!");
var entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
Class<T> entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
: callbackDiscoverer.resolveDeclaredEntityType(callbackType).getRawClass());
var callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
Method callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
var method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
Method method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
ReflectionUtils.makeAccessible(method);
return method;
});
var deferredCallbackChain = Mono.just(entity);
Mono<T> deferredCallbackChain = Mono.just(entity);
for (var callback : callbackDiscoverer.getEntityCallbacks(entityType,
for (EntityCallback<T> callback : callbackDiscoverer.getEntityCallbacks(entityType,
ResolvableType.forClass(callbackType))) {
var callbackFunction = EntityCallbackDiscoverer
BiFunction<EntityCallback<T>, T, Object> callbackFunction = EntityCallbackDiscoverer
.computeCallbackInvokerFunction(callback, callbackMethod, args);
deferredCallbackChain = deferredCallbackChain
@@ -103,7 +104,7 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
try {
var value = callbackInvokerFunction.apply(callback, entity);
Object value = callbackInvokerFunction.apply(callback, entity);
if (value != null) {
return value instanceof Publisher ? Mono.from((Publisher<T>) value) : Mono.just((T) value);
@@ -113,12 +114,12 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
String.format("Callback invocation on %s returned null value for %s", callback.getClass(), entity));
} catch (ClassCastException ex) {
var msg = ex.getMessage();
String 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.
var logger = LogFactory.getLog(getClass());
Log logger = LogFactory.getLog(getClass());
if (logger.isDebugEnabled()) {
logger.debug("Non-matching callback type for entity callback: " + callback, ex);
}

View File

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

View File

@@ -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..."
var moduleSeparatorIndex = exceptionMessage.indexOf('/');
int moduleSeparatorIndex = exceptionMessage.indexOf('/');
if (moduleSeparatorIndex != -1 && exceptionMessage.startsWith(eventClass.getName(), moduleSeparatorIndex + 1)) {
return true;
}

View File

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

View File

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

View File

@@ -17,6 +17,7 @@ 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;
@@ -112,8 +113,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
var instantiators = new EntityInstantiators();
var accessorFactory = NativeDetector.inNativeImage()
EntityInstantiators instantiators = new EntityInstantiators();
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage()
? BeanWrapperPropertyAccessorFactory.INSTANCE
: new ClassGeneratingPropertyAccessorFactory();
@@ -196,7 +197,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
Assert.notNull(type, "Type must not be null!");
var entity = persistentEntities.get(ClassTypeInformation.from(type));
Optional<E> entity = persistentEntities.get(ClassTypeInformation.from(type));
return entity == null ? false : entity.isPresent();
}
@@ -211,7 +212,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
read.lock();
var entity = persistentEntities.get(type);
Optional<E> entity = persistentEntities.get(type);
if (entity != null) {
return entity.orElse(null);
@@ -250,7 +251,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
return null;
}
var typeInfo = persistentProperty.getTypeInformation();
TypeInformation<?> typeInfo = persistentProperty.getTypeInformation();
return getPersistentEntity(typeInfo.getRequiredActualType());
}
@@ -313,7 +314,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
read.lock();
var persistentEntity = persistentEntities.get(typeInformation);
Optional<E> persistentEntity = persistentEntities.get(typeInformation);
if (persistentEntity != null) {
return persistentEntity;
@@ -358,9 +359,9 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
try {
var type = userTypeInformation.getType();
Class<?> type = userTypeInformation.getType();
var entity = createPersistentEntity(userTypeInformation);
E entity = createPersistentEntity(userTypeInformation);
entity.setEvaluationContextProvider(evaluationContextProvider);
// Eagerly cache the entity as we might have to find it during recursive lookups.
@@ -371,14 +372,14 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
persistentEntities.put(typeInformation, Optional.of(entity));
}
var pds = BeanUtils.getPropertyDescriptors(type);
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
Map<String, PropertyDescriptor> descriptors = new HashMap<>();
for (var descriptor : pds) {
for (PropertyDescriptor descriptor : pds) {
descriptors.put(descriptor.getName(), descriptor);
}
var persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
@@ -490,12 +491,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
public void doWith(Field field) {
var fieldName = field.getName();
var type = entity.getTypeInformation();
String fieldName = field.getName();
TypeInformation<?> type = entity.getTypeInformation();
ReflectionUtils.makeAccessible(field);
var property = Optional.ofNullable(descriptors.get(fieldName))//
Property property = Optional.ofNullable(descriptors.get(fieldName))//
.map(it -> Property.of(type, field, it))//
.orElseGet(() -> Property.of(type, field));
@@ -521,7 +522,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private void createAndRegisterProperty(Property input) {
var property = createPersistentProperty(input, entity, simpleTypeHolder);
P property = createPersistentProperty(input, entity, simpleTypeHolder);
if (property.isTransient()) {
return;
@@ -555,17 +556,17 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
protected boolean shouldSkipOverrideProperty(P property) {
var existingProperty = entity.getPersistentProperty(property.getName());
P existingProperty = entity.getPersistentProperty(property.getName());
if (existingProperty == null) {
return false;
}
var declaringClass = getDeclaringClass(property);
var existingDeclaringClass = getDeclaringClass(existingProperty);
Class<?> declaringClass = getDeclaringClass(property);
Class<?> existingDeclaringClass = getDeclaringClass(existingProperty);
var propertyType = getPropertyType(property);
var existingPropertyType = getPropertyType(existingProperty);
Class<?> propertyType = getPropertyType(property);
Class<?> existingPropertyType = getPropertyType(existingProperty);
if (!propertyType.isAssignableFrom(existingPropertyType)) {
@@ -584,12 +585,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private Class<?> getDeclaringClass(PersistentProperty<?> persistentProperty) {
var field = persistentProperty.getField();
Field field = persistentProperty.getField();
if (field != null) {
return field.getDeclaringClass();
}
var accessor = persistentProperty.getGetter();
Method accessor = persistentProperty.getGetter();
if (accessor == null) {
accessor = persistentProperty.getSetter();
@@ -608,22 +609,22 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private Class<?> getPropertyType(PersistentProperty<?> persistentProperty) {
var field = persistentProperty.getField();
Field field = persistentProperty.getField();
if (field != null) {
return field.getType();
}
var getter = persistentProperty.getGetter();
Method getter = persistentProperty.getGetter();
if (getter != null) {
return getter.getReturnType();
}
var setter = persistentProperty.getSetter();
Method setter = persistentProperty.getSetter();
if (setter != null) {
return setter.getParameterTypes()[0];
}
var wither = persistentProperty.getWither();
Method wither = persistentProperty.getWither();
if (wither != null) {
return wither.getParameterTypes()[0];
}

View File

@@ -80,7 +80,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
}
@SuppressWarnings("null")
var leafPropertyType = getLeafProperty().getActualType();
Class<?> leafPropertyType = getLeafProperty().getActualType();
Assert.isTrue(property.getOwner().getType().equals(leafPropertyType),
() -> String.format("Cannot append property %s to type %s!", property.getName(), leafPropertyType.getName()));
@@ -112,7 +112,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!");
var result = properties.stream() //
String result = properties.stream() //
.map(converter::convert) //
.filter(StringUtils::hasText) //
.collect(Collectors.joining(delimiter));
@@ -134,15 +134,15 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
Assert.notNull(path, "PersistentPropertyPath must not be null!");
var iterator = path.iterator();
Iterator<P> iterator = path.iterator();
for (var property : this) {
for (P property : this) {
if (!iterator.hasNext()) {
return false;
}
var reference = iterator.next();
P reference = iterator.next();
if (!property.equals(reference)) {
return false;
@@ -159,9 +159,9 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
}
List<P> result = new ArrayList<>();
var iterator = iterator();
Iterator<P> iterator = iterator();
for (var i = 0; i < base.getLength(); i++) {
for (int i = 0; i < base.getLength(); i++) {
iterator.next();
}
@@ -174,7 +174,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
public PersistentPropertyPath<P> getParentPath() {
var size = properties.size();
int size = properties.size();
return size == 0 ? this : new DefaultPersistentPropertyPath<>(properties.subList(0, size - 1));
}

View File

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

View File

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

View File

@@ -192,13 +192,13 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
@Nullable
public PersistentEntity<?, ?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property) {
var propertyType = property.getTypeInformation().getActualType();
TypeInformation<?> propertyType = property.getTypeInformation().getActualType();
if (propertyType == null || !property.isAssociation()) {
return null;
}
var associationTargetType = property.getAssociationTargetType();
Class<?> associationTargetType = property.getAssociationTargetType();
return associationTargetType == null //
? getEntityIdentifiedBy(propertyType) //
@@ -216,7 +216,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
Assert.notNull(property, "PersistentProperty must not be null!");
var entity = getEntityUltimatelyReferredToBy(property);
PersistentEntity<?, ? extends PersistentProperty<?>> entity = getEntityUltimatelyReferredToBy(property);
return entity == null //
? property.getTypeInformation().getRequiredActualType() //
@@ -240,10 +240,10 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
for (PersistentEntity<?, ? extends PersistentProperty<?>> persistentProperties : context
.getPersistentEntities()) {
var idProperty = persistentProperties.getIdProperty();
PersistentProperty<? extends PersistentProperty<?>> idProperty = persistentProperties.getIdProperty();
if (idProperty != null && type.equals(idProperty.getTypeInformation().getActualType())) {
var owner = idProperty.getOwner();
PersistentEntity<?, ? extends PersistentProperty<?>> owner = idProperty.getOwner();
entities.add(owner);
}
}
@@ -251,7 +251,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
if (entities.size() > 1) {
var message = "Found multiple entities identified by " + type.getType() + ": ";
String 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!";

View File

@@ -19,6 +19,7 @@ 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;
@@ -180,26 +181,26 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
*/
private PersistentPropertyPath<P> createPersistentPropertyPath(String propertyPath, TypeInformation<?> type) {
var trimmedPath = propertyPath.trim();
String trimmedPath = propertyPath.trim();
List<String> parts = trimmedPath.isEmpty() //
? Collections.emptyList() //
: Arrays.asList(trimmedPath.split("\\."));
DefaultPersistentPropertyPath<P> path = DefaultPersistentPropertyPath.empty();
var iterator = parts.iterator();
var current = context.getRequiredPersistentEntity(type);
Iterator<String> iterator = parts.iterator();
E current = context.getRequiredPersistentEntity(type);
while (iterator.hasNext()) {
var segment = iterator.next();
final var currentPath = path;
String segment = iterator.next();
final DefaultPersistentPropertyPath<P> currentPath = path;
var pair = getPair(path, iterator, segment, current);
Pair<DefaultPersistentPropertyPath<P>, E> pair = getPair(path, iterator, segment, current);
if (pair == null) {
var source = StringUtils.collectionToDelimitedString(parts, ".");
String source = StringUtils.collectionToDelimitedString(parts, ".");
throw new InvalidPersistentPropertyPath(source, type, segment, currentPath);
}
@@ -215,7 +216,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) {
var property = entity.getPersistentProperty(segment);
P property = entity.getPersistentProperty(segment);
if (property == null) {
return null;
@@ -227,13 +228,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) {
var actualType = type.getActualType();
TypeInformation<?> actualType = type.getActualType();
if (actualType == null) {
return Collections.emptyList();
}
var entity = context.getRequiredPersistentEntity(actualType);
E entity = context.getRequiredPersistentEntity(actualType);
return from(entity, filter, traversalGuard, basePath);
}
@@ -242,16 +243,16 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
Set<PersistentPropertyPath<P>> properties = new HashSet<>();
var propertyTester = (PropertyHandler<P>) persistentProperty -> {
PropertyHandler<P> propertyTester = (PropertyHandler<P>) persistentProperty -> {
var typeInformation = persistentProperty.getTypeInformation();
var actualPropertyType = typeInformation.getActualType();
TypeInformation<?> typeInformation = persistentProperty.getTypeInformation();
TypeInformation<?> actualPropertyType = typeInformation.getActualType();
if (basePath.containsPropertyOfType(actualPropertyType)) {
return;
}
var currentPath = basePath.append(persistentProperty);
DefaultPersistentPropertyPath<P> currentPath = basePath.append(persistentProperty);
if (filter.test(persistentProperty)) {
properties.add(currentPath);
@@ -264,7 +265,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
entity.doWithProperties(propertyTester);
var handler = (AssociationHandler<P>) association -> propertyTester
AssociationHandler<P> handler = (AssociationHandler<P>) association -> propertyTester
.doWithPersistentProperty(association.getInverse());
entity.doWithAssociations(handler);
@@ -313,7 +314,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(type);
int result = ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(path);
return result;
}
@@ -374,7 +375,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
return false;
}
var dotPath = path.toDotPath();
String dotPath = path.toDotPath();
return stream().anyMatch(it -> dotPath.equals(it.toDotPath()));
}
@@ -389,7 +390,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
Assert.notNull(predicate, "Predicate must not be null!");
var paths = this.stream() //
List<PersistentPropertyPath<P>> paths = this.stream() //
.filter(it -> !it.stream().anyMatch(predicate)) //
.collect(Collectors.toList());
@@ -418,10 +419,11 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
@SuppressWarnings("null")
public int compare(PersistentPropertyPath<?> left, PersistentPropertyPath<?> right) {
var mapper = (Function<PersistentProperty<?>, Integer>) it -> it.getName().length();
Function<PersistentProperty<?>, Integer> mapper = (Function<PersistentProperty<?>, Integer>) it -> it.getName()
.length();
var leftNames = left.stream().map(mapper);
var rightNames = right.stream().map(mapper);
Stream<Integer> leftNames = left.stream().map(mapper);
Stream<Integer> rightNames = right.stream().map(mapper);
return StreamUtils.zip(leftNames, rightNames, (l, r) -> l - r) //
.filter(it -> it != 0) //

View File

@@ -210,7 +210,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
@Override
public Class<?> getAssociationTargetType() {
var result = getAssociationTargetTypeInformation();
TypeInformation<?> result = getAssociationTargetTypeInformation();
return result != null ? result.getType() : null;
}
@@ -253,7 +253,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
if (isMap()) {
var mapValueType = information.getMapValueType();
TypeInformation<?> mapValueType = information.getMapValueType();
if (mapValueType != null) {
return mapValueType.getType();
@@ -278,7 +278,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
protected TypeInformation<?> getActualTypeInformation() {
var targetType = associationTargetType.getNullable();
TypeInformation<?> targetType = associationTargetType.getNullable();
return targetType == null ? information.getRequiredActualType() : targetType;
}
@@ -308,10 +308,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
private Set<TypeInformation<?>> detectEntityTypes(SimpleTypeHolder simpleTypes) {
var typeToStartWith = getAssociationTargetTypeInformation();
TypeInformation<?> typeToStartWith = getAssociationTargetTypeInformation();
typeToStartWith = typeToStartWith == null ? information : typeToStartWith;
var result = detectEntityTypes(typeToStartWith);
Set<TypeInformation<?>> result = detectEntityTypes(typeToStartWith);
return result.stream()
.filter(it -> !simpleTypes.isSimpleType(it.getType()))
@@ -331,7 +331,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
result.addAll(detectEntityTypes(source.getComponentType()));
}
var actualType = source.getActualType();
TypeInformation<?> actualType = source.getActualType();
if (source.equals(actualType)) {
result.add(source);

View File

@@ -33,9 +33,9 @@ import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.annotation.Reference;
import org.springframework.data.annotation.Transient;
import org.springframework.data.annotation.Version;
import org.springframework.data.convert.ValueConverter;
import org.springframework.data.convert.PropertyValueConverter;
import org.springframework.data.convert.ValueConversionContext;
import org.springframework.data.convert.ValueConverter;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentEntity;
@@ -67,7 +67,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
private final Lazy<Boolean> usePropertyAccess = Lazy.of(() -> {
var accessType = findPropertyOrOwnerAnnotation(AccessType.class);
AccessType accessType = findPropertyOrOwnerAnnotation(AccessType.class);
return accessType != null && Type.PROPERTY.equals(accessType.value()) || super.usePropertyAccess();
});
@@ -108,7 +108,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
populateAnnotationCache(property);
var value = findAnnotation(Value.class);
Value value = findAnnotation(Value.class);
this.value = value == null ? null : value.value();
}
@@ -124,11 +124,11 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
Optionals.toStream(property.getGetter(), property.getSetter()).forEach(it -> {
for (var annotation : it.getAnnotations()) {
for (Annotation annotation : it.getAnnotations()) {
var annotationType = annotation.annotationType();
Class<? extends Annotation> annotationType = annotation.annotationType();
var mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
validateAnnotation(mergedAnnotation,
"Ambiguous mapping! Annotation %s configured "
@@ -141,10 +141,10 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
property.getField().ifPresent(it -> {
for (var annotation : it.getAnnotations()) {
for (Annotation annotation : it.getAnnotations()) {
var annotationType = annotation.annotationType();
var mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
Class<? extends Annotation> annotationType = annotation.annotationType();
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
validateAnnotation(mergedAnnotation,
"Ambiguous mapping! Annotation %s configured " + "on field %s and one of its accessor methods in class %s!",
@@ -165,7 +165,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
*/
private void validateAnnotation(Annotation candidate, String message, Object... arguments) {
var annotationType = candidate.annotationType();
Class<? extends Annotation> annotationType = candidate.annotationType();
if (!annotationType.getName().startsWith(SPRING_DATA_PACKAGE)) {
return;
@@ -240,7 +240,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
@SuppressWarnings("unchecked")
private <A extends Annotation> Optional<A> doFindAnnotation(Class<A> annotationType) {
var annotation = annotationCache.get(annotationType);
Optional<? extends Annotation> annotation = annotationCache.get(annotationType);
if (annotation != null) {
return (Optional<A>) annotation;
@@ -259,7 +259,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
@Override
public <A extends Annotation> A findPropertyOrOwnerAnnotation(Class<A> annotationType) {
var annotation = findAnnotation(annotationType);
A annotation = findAnnotation(annotationType);
return annotation != null ? annotation : getOwner().findAnnotation(annotationType);
}
@@ -303,7 +303,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
populateAnnotationCache(getProperty());
}
var builder = annotationCache.values().stream() //
String builder = annotationCache.values().stream() //
.flatMap(Optionals::toStream) //
.map(Object::toString) //
.collect(Collectors.joining(" "));

View File

@@ -17,7 +17,16 @@ package org.springframework.data.mapping.model;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.springframework.core.annotation.AnnotatedElementUtils;
@@ -182,7 +191,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
propertyCache.computeIfAbsent(property.getName(), key -> property);
var candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property);
P candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property);
if (candidate != null) {
this.idProperty = candidate;
@@ -190,7 +199,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
if (property.isVersionProperty()) {
var versionProperty = this.versionProperty;
P versionProperty = this.versionProperty;
if (versionProperty != null) {
@@ -223,7 +232,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
return null;
}
var idProperty = this.idProperty;
P idProperty = this.idProperty;
if (idProperty != null) {
throw new MappingException(String.format("Attempt to add id property %s but already have property %s registered "
@@ -255,7 +264,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
private List<P> doFindPersistentProperty(Class<? extends Annotation> annotationType) {
var annotatedProperties = properties.stream() //
List<P> annotatedProperties = properties.stream() //
.filter(it -> it.isAnnotationPresent(annotationType)) //
.collect(Collectors.toList());
@@ -284,7 +293,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
Assert.notNull(handler, "PropertyHandler must not be null!");
for (var property : persistentPropertiesCache) {
for (P property : persistentPropertiesCache) {
handler.doWithPersistentProperty(property);
}
}
@@ -303,7 +312,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
Assert.notNull(handler, "Handler must not be null!");
for (var association : associations) {
for (Association<P> association : associations) {
handler.doWithAssociation(association);
}
}
@@ -394,7 +403,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
@Override
public Iterator<P> iterator() {
var iterator = properties.iterator();
Iterator<P> iterator = properties.iterator();
return new Iterator<P>() {
@@ -465,7 +474,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
*/
private static Alias getAliasFromAnnotation(Class<?> type) {
var typeAlias = AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class);
TypeAlias typeAlias = AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class);
if (typeAlias != null && StringUtils.hasText(typeAlias.value())) {
return Alias.of(typeAlias.value());

View File

@@ -19,7 +19,10 @@ 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;
@@ -61,7 +64,7 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
if (property.isImmutable()) {
var wither = property.getWither();
Method wither = property.getWither();
if (wither != null) {
@@ -82,14 +85,14 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
if (!property.usePropertyAccess()) {
var field = property.getRequiredField();
Field field = property.getRequiredField();
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, bean, value);
return;
}
var setter = property.getRequiredSetter();
Method setter = property.getRequiredSetter();
ReflectionUtils.makeAccessible(setter);
ReflectionUtils.invokeMethod(setter, bean, value);
@@ -122,13 +125,13 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
if (!property.usePropertyAccess()) {
var field = property.getRequiredField();
Field field = property.getRequiredField();
ReflectionUtils.makeAccessible(field);
return ReflectionUtils.getField(field, bean);
}
var getter = property.getRequiredGetter();
Method getter = property.getRequiredGetter();
ReflectionUtils.makeAccessible(getter);
return ReflectionUtils.invokeMethod(getter, bean);
@@ -160,8 +163,8 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
*/
static <T> Object setProperty(PersistentProperty<?> property, T bean, @Nullable Object value) {
var type = property.getOwner().getType();
var copy = copyMethodCache.computeIfAbsent(type, it -> getCopyMethod(it, property));
Class<?> type = property.getOwner().getType();
KCallable<?> copy = copyMethodCache.computeIfAbsent(type, it -> getCopyMethod(it, property));
if (copy == null) {
throw new UnsupportedOperationException(String.format(
@@ -176,9 +179,9 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
Map<KParameter, Object> args = new LinkedHashMap<>(2, 1);
var parameters = callable.getParameters();
List<KParameter> parameters = callable.getParameters();
for (var parameter : parameters) {
for (KParameter parameter : parameters) {
if (parameter.getKind() == Kind.INSTANCE) {
args.put(parameter, bean);

View File

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

View File

@@ -17,6 +17,8 @@ package org.springframework.data.mapping.model;
import static org.springframework.asm.Opcodes.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
@@ -87,7 +89,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
var instantiator = this.entityInstantiators.get(entity.getTypeInformation());
EntityInstantiator instantiator = this.entityInstantiators.get(entity.getTypeInformation());
if (instantiator == null) {
instantiator = potentiallyCreateAndRegisterEntityInstantiator(entity);
@@ -103,8 +105,8 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private synchronized EntityInstantiator potentiallyCreateAndRegisterEntityInstantiator(
PersistentEntity<?, ?> entity) {
var map = this.entityInstantiators;
var instantiator = map.get(entity.getTypeInformation());
Map<TypeInformation<?>, EntityInstantiator> map = this.entityInstantiators;
EntityInstantiator instantiator = map.get(entity.getTypeInformation());
if (instantiator != null) {
return instantiator;
@@ -176,7 +178,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
return true;
}
var type = entity.getType();
Class<?> type = entity.getType();
if (type.isInterface() //
|| type.isArray() //
@@ -186,7 +188,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
return true;
}
var creatorMetadata = entity.getInstanceCreatorMetadata();
InstanceCreatorMetadata<? extends PersistentProperty<?>> creatorMetadata = entity.getInstanceCreatorMetadata();
if (creatorMetadata == null) {
return true;
@@ -268,7 +270,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
var params = extractInvocationArguments(entity.getInstanceCreatorMetadata(), provider);
Object[] params = extractInvocationArguments(entity.getInstanceCreatorMetadata(), provider);
try {
return (T) instantiator.newInstance(params);
@@ -292,9 +294,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
return allocateArguments(0);
}
var params = allocateArguments(constructor.getParameterCount());
Object[] params = allocateArguments(constructor.getParameterCount());
var index = 0;
int index = 0;
for (Parameter<?, P> parameter : constructor.getParameters()) {
params[index++] = provider.getParameterValue(parameter);
}
@@ -335,7 +337,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
var params = extractInvocationArguments(entity.getInstanceCreatorMetadata(), provider);
Object[] params = extractInvocationArguments(entity.getInstanceCreatorMetadata(), provider);
throw new MappingInstantiationException(entity, Arrays.asList(params),
new BeanInstantiationException(typeToCreate, "Class is abstract"));
@@ -401,9 +403,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public Class<?> generateCustomInstantiatorClass(PersistentEntity<?, ?> entity,
@Nullable InstanceCreatorMetadata<?> constructor) {
var className = generateClassName(entity);
var type = entity.getType();
var classLoader = type.getClassLoader();
String className = generateClassName(entity);
Class<?> type = entity.getType();
ClassLoader classLoader = type.getClassLoader();
if (ClassUtils.isPresent(className, classLoader)) {
@@ -414,7 +416,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
}
}
var bytecode = generateBytecode(className, entity, constructor);
byte[] bytecode = generateBytecode(className, entity, constructor);
try {
return ReflectUtils.defineClass(className, bytecode, classLoader, type.getProtectionDomain(), type);
@@ -442,7 +444,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
public byte[] generateBytecode(String internalClassName, PersistentEntity<?, ?> entity,
@Nullable InstanceCreatorMetadata<?> entityCreator) {
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_6, ACC_PUBLIC + ACC_SUPER, internalClassName.replace('.', '/'), null, JAVA_LANG_OBJECT,
IMPLEMENTED_INTERFACES);
@@ -458,7 +460,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private void visitDefaultConstructor(ClassWriter cw) {
var mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false);
@@ -477,9 +479,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private void visitCreateMethod(ClassWriter cw, PersistentEntity<?, ?> entity,
@Nullable InstanceCreatorMetadata<?> entityCreator) {
var entityTypeResourcePath = Type.getInternalName(entity.getType());
String entityTypeResourcePath = Type.getInternalName(entity.getType());
var mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
"([" + BytecodeUtil.referenceName(Object.class) + ")" + BytecodeUtil.referenceName(Object.class),
null, null);
mv.visitCode();
@@ -502,8 +504,8 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private static void visitConstructorCreation(PreferredConstructor<?, ?> constructor, MethodVisitor mv,
String entityTypeResourcePath) {
var ctor = constructor.getConstructor();
var parameterTypes = ctor.getParameterTypes();
Constructor<?> ctor = constructor.getConstructor();
Class<?>[] parameterTypes = ctor.getParameterTypes();
List<? extends Parameter<Object, ?>> parameters = constructor.getParameters();
visitParameterTypes(mv, parameterTypes, parameters);
@@ -514,8 +516,8 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private static void visitFactoryMethodCreation(FactoryMethod<?, ?> factoryMethod, MethodVisitor mv,
String entityTypeResourcePath) {
var method = factoryMethod.getFactoryMethod();
var parameterTypes = method.getParameterTypes();
Method method = factoryMethod.getFactoryMethod();
Class<?>[] parameterTypes = method.getParameterTypes();
List<? extends Parameter<Object, ?>> parameters = factoryMethod.getParameters();
visitParameterTypes(mv, parameterTypes, parameters);
@@ -527,7 +529,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private static void visitParameterTypes(MethodVisitor mv, Class<?>[] parameterTypes,
List<? extends Parameter<Object, ?>> parameters) {
for (var i = 0; i < parameterTypes.length; i++) {
for (int i = 0; i < parameterTypes.length; i++) {
mv.visitVarInsn(ALOAD, 1);
@@ -538,7 +540,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
if (parameterTypes[i].isPrimitive()) {
mv.visitInsn(DUP);
var parameterName = parameters.size() > i ? parameters.get(i).getName() : null;
String 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), "");

View File

@@ -78,11 +78,11 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
@Override
public <T> PersistentPropertyAccessor<T> getPropertyAccessor(PersistentEntity<?, ?> entity, T bean) {
var constructor = constructorMap.get(entity);
Constructor<?> constructor = constructorMap.get(entity);
if (constructor == null) {
var accessorClass = potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
Class<PersistentPropertyAccessor<?>> accessorClass = potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
entity);
constructor = accessorClass.getConstructors()[0];
@@ -91,7 +91,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
this.constructorMap = constructorMap;
}
var args = argumentCache.get();
Object[] args = argumentCache.get();
args[0] = bean;
try {
@@ -131,7 +131,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static boolean isTypeInjectable(PersistentEntity<?, ?> entity) {
var type = entity.getType();
Class<?> type = entity.getType();
return type.getClassLoader() != null
&& (type.getPackage() == null || !type.getPackage().getName().startsWith("java"))
&& ClassUtils.isPresent(PersistentPropertyAccessor.class.getName(), type.getClassLoader())
@@ -141,7 +141,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private boolean hasUniquePropertyHashCodes(PersistentEntity<?, ?> entity) {
Set<Integer> hashCodes = new HashSet<>();
var propertyCount = new AtomicInteger();
AtomicInteger propertyCount = new AtomicInteger();
entity.doWithProperties((SimplePropertyHandler) property -> {
@@ -167,8 +167,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private synchronized Class<PersistentPropertyAccessor<?>> potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
PersistentEntity<?, ?> entity) {
var map = this.propertyAccessorClasses;
var propertyAccessorClass = map.get(entity.getTypeInformation());
Map<TypeInformation<?>, Class<PersistentPropertyAccessor<?>>> map = this.propertyAccessorClasses;
Class<PersistentPropertyAccessor<?>> propertyAccessorClass = map.get(entity.getTypeInformation());
if (propertyAccessorClass != null) {
return propertyAccessorClass;
@@ -309,9 +309,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
static Class<?> generateCustomAccessorClass(PersistentEntity<?, ?> entity) {
var className = generateClassName(entity);
var type = entity.getType();
var classLoader = type.getClassLoader();
String className = generateClassName(entity);
Class<?> type = entity.getType();
ClassLoader classLoader = type.getClassLoader();
if (ClassUtils.isPresent(className, classLoader)) {
@@ -322,7 +322,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
}
}
var bytecode = generateBytecode(className.replace('.', '/'), entity);
byte[] bytecode = generateBytecode(className.replace('.', '/'), entity);
try {
@@ -338,10 +338,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
static byte[] generateBytecode(String internalClassName, PersistentEntity<?, ?> entity) {
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_6, ACC_PUBLIC + ACC_SUPER, internalClassName, null, JAVA_LANG_OBJECT, IMPLEMENTED_INTERFACES);
var persistentProperties = getPersistentProperties(entity);
List<PersistentProperty<?>> persistentProperties = getPersistentProperties(entity);
visitFields(entity, persistentProperties, cw);
visitDefaultConstructor(entity, internalClassName, cw);
@@ -388,7 +388,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
cw.visitField(ACC_PRIVATE, BEAN_FIELD, getAccessibleTypeReferenceName(entity), null, null).visitEnd();
for (var property : persistentProperties) {
for (PersistentProperty<?> property : persistentProperties) {
if (property.isImmutable()) {
if (generateMethodHandle(entity, property.getWither())) {
@@ -438,7 +438,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv = cw.visitMethod(ACC_PUBLIC, INIT, String.format("(%s)V", getAccessibleTypeReferenceName(entity)), null, null);
mv.visitCode();
var l0 = new Label();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false);
@@ -456,7 +456,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitFieldInsn(PUTFIELD, internalClassName, BEAN_FIELD, getAccessibleTypeReferenceName(entity));
mv.visitInsn(RETURN);
var l3 = new Label();
Label 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);
@@ -485,10 +485,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitStaticInitializer(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
var mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
MethodVisitor mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
mv.visitCode();
var l0 = new Label();
var l1 = new Label();
Label l0 = new Label();
Label l1 = new Label();
mv.visitLabel(l0);
// lookup = MethodHandles.lookup()
@@ -496,9 +496,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
String.format("()%s", referenceName(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP)), false);
mv.visitVarInsn(ASTORE, 0);
var entityClasses = getPropertyDeclaratingClasses(persistentProperties);
List<Class<?>> entityClasses = getPropertyDeclaratingClasses(persistentProperties);
for (var entityClass : entityClasses) {
for (Class<?> entityClass : entityClasses) {
mv.visitLdcInsn(entityClass.getName());
mv.visitMethodInsn(INVOKESTATIC, JAVA_LANG_CLASS, "forName",
@@ -506,7 +506,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitVarInsn(ASTORE, classVariableIndex5(entityClasses, entityClass));
}
for (var property : persistentProperties) {
for (PersistentProperty<?> property : persistentProperties) {
if (property.usePropertyAccess()) {
@@ -539,9 +539,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 (var entityClass : entityClasses) {
for (Class<?> entityClass : entityClasses) {
var index = classVariableIndex5(entityClasses, entityClass);
int index = classVariableIndex5(entityClasses, entityClass);
mv.visitLocalVariable(String.format("class_%d", index), referenceName(JAVA_LANG_CLASS), null, l0, l1, index);
}
@@ -577,7 +577,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
List<Class<?>> entityClasses, String internalClassName) {
// getter = <entity>.class.getDeclaredMethod()
var getter = property.getGetter();
Method getter = property.getGetter();
if (getter != null) {
@@ -629,7 +629,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
var parameterType = method.getParameterTypes()[0];
Class<?> parameterType = method.getParameterTypes()[0];
if (parameterType.isPrimitive()) {
mv.visitFieldInsn(GETSTATIC, Type.getInternalName(autoboxType(method.getParameterTypes()[0])), "TYPE",
@@ -672,7 +672,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
// field = <entity>.class.getDeclaredField()
var field = property.getField();
Field field = property.getField();
if (field != null) {
mv.visitVarInsn(ALOAD, classVariableIndex5(entityClasses, field.getDeclaringClass()));
@@ -710,10 +710,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitBeanGetter(PersistentEntity<?, ?> entity, String internalClassName, ClassWriter cw) {
// public Object getBean()
var mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)),
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)),
null, null);
mv.visitCode();
var l0 = new Label();
Label l0 = new Label();
// return this.bean
mv.visitLabel(l0);
@@ -723,7 +723,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitInsn(ARETURN);
var l1 = new Label();
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable(THIS_REF, referenceName(internalClassName), null, l0, l1, 0);
mv.visitMaxs(1, 1);
@@ -754,13 +754,13 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitGetProperty(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
var mv = cw.visitMethod(ACC_PUBLIC, "getProperty",
MethodVisitor 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();
var l0 = new Label();
var l1 = new Label();
Label l0 = new Label();
Label l1 = new Label();
mv.visitLabel(l0);
// Assert.notNull(property)
@@ -793,21 +793,21 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitGetPropertySwitch(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, MethodVisitor mv) {
var propertyStackMap = createPropertyStackMap(persistentProperties);
Map<String, PropertyStackAddress> propertyStackMap = createPropertyStackMap(persistentProperties);
var hashes = new int[propertyStackMap.size()];
var switchJumpLabels = new Label[propertyStackMap.size()];
int[] hashes = new int[propertyStackMap.size()];
Label[] switchJumpLabels = new Label[propertyStackMap.size()];
List<PropertyStackAddress> stackmap = new ArrayList<>(propertyStackMap.values());
Collections.sort(stackmap);
for (var i = 0; i < stackmap.size(); i++) {
for (int i = 0; i < stackmap.size(); i++) {
var propertyStackAddress = stackmap.get(i);
PropertyStackAddress propertyStackAddress = stackmap.get(i);
hashes[i] = propertyStackAddress.hash;
switchJumpLabels[i] = propertyStackAddress.label;
}
var dfltLabel = new Label();
Label dfltLabel = new Label();
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, PERSISTENT_PROPERTY, "getName",
@@ -815,7 +815,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_STRING, "hashCode", "()I", false);
mv.visitLookupSwitchInsn(dfltLabel, hashes, switchJumpLabels);
for (var property : persistentProperties) {
for (PersistentProperty<?> property : persistentProperties) {
mv.visitLabel(propertyStackMap.get(property.getName()).label);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
@@ -839,7 +839,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitGetProperty0(PersistentEntity<?, ?> entity, PersistentProperty<?> property,
MethodVisitor mv, String internalClassName) {
var getter = property.getGetter();
Method getter = property.getGetter();
if (property.usePropertyAccess() && getter != null) {
if (generateMethodHandle(entity, getter)) {
@@ -853,9 +853,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
// bean.get…
mv.visitVarInsn(ALOAD, 2);
var invokeOpCode = INVOKEVIRTUAL;
var declaringClass = getter.getDeclaringClass();
var interfaceDefinition = declaringClass.isInterface();
int invokeOpCode = INVOKEVIRTUAL;
Class<?> declaringClass = getter.getDeclaringClass();
boolean interfaceDefinition = declaringClass.isInterface();
if (interfaceDefinition) {
invokeOpCode = INVOKEINTERFACE;
@@ -867,7 +867,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
}
} else {
var field = property.getRequiredField();
Field field = property.getRequiredField();
if (generateMethodHandle(entity, field)) {
// $fieldGetter.invoke(bean)
@@ -917,12 +917,12 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetProperty(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
var mv = cw.visitMethod(ACC_PUBLIC, "setProperty",
MethodVisitor 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();
var l0 = new Label();
Label l0 = new Label();
mv.visitLabel(l0);
visitAssertNotNull(mv);
@@ -935,7 +935,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
visitSetPropertySwitch(entity, persistentProperties, internalClassName, mv);
var l1 = new Label();
Label l1 = new Label();
mv.visitLabel(l1);
visitThrowUnsupportedOperationException(mv, "No accessor to set property %s!");
@@ -957,20 +957,20 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetPropertySwitch(PersistentEntity<?, ?> entity,
List<PersistentProperty<?>> persistentProperties, String internalClassName, MethodVisitor mv) {
var propertyStackMap = createPropertyStackMap(persistentProperties);
Map<String, PropertyStackAddress> propertyStackMap = createPropertyStackMap(persistentProperties);
var hashes = new int[propertyStackMap.size()];
var switchJumpLabels = new Label[propertyStackMap.size()];
int[] hashes = new int[propertyStackMap.size()];
Label[] switchJumpLabels = new Label[propertyStackMap.size()];
List<PropertyStackAddress> stackmap = new ArrayList<>(propertyStackMap.values());
Collections.sort(stackmap);
for (var i = 0; i < stackmap.size(); i++) {
var propertyStackAddress = stackmap.get(i);
for (int i = 0; i < stackmap.size(); i++) {
PropertyStackAddress propertyStackAddress = stackmap.get(i);
hashes[i] = propertyStackAddress.hash;
switchJumpLabels[i] = propertyStackAddress.label;
}
var dfltLabel = new Label();
Label dfltLabel = new Label();
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, PERSISTENT_PROPERTY, "getName",
@@ -978,7 +978,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_STRING, "hashCode", "()I", false);
mv.visitLookupSwitchInsn(dfltLabel, hashes, switchJumpLabels);
for (var property : persistentProperties) {
for (PersistentProperty<?> property : persistentProperties) {
mv.visitLabel(propertyStackMap.get(property.getName()).label);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
@@ -1001,8 +1001,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetProperty0(PersistentEntity<?, ?> entity, PersistentProperty<?> property,
MethodVisitor mv, String internalClassName) {
var setter = property.getSetter();
var wither = property.getWither();
Method setter = property.getSetter();
Method wither = property.getWither();
if (property.isImmutable()) {
@@ -1080,7 +1080,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitKotlinCopy(PersistentEntity<?, ?> entity, PersistentProperty<?> property, MethodVisitor mv,
String internalClassName) {
var kotlinCopyMethod = KotlinCopyMethod.findCopyMethod(entity.getType())
KotlinCopyMethod kotlinCopyMethod = KotlinCopyMethod.findCopyMethod(entity.getType())
.orElseThrow(() -> new IllegalStateException(
String.format("No usable .copy(…) method found in entity %s", entity.getType().getName())));
@@ -1096,17 +1096,17 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
visitInvokeMethodSingleArg(mv, kotlinCopyMethod.getPublicCopyMethod());
} else {
var copy = kotlinCopyMethod.getSyntheticCopyMethod();
var parameterTypes = copy.getParameterTypes();
Method copy = kotlinCopyMethod.getSyntheticCopyMethod();
Class<?>[] parameterTypes = copy.getParameterTypes();
// PersonWithId.copy$default..(bean, object, MASK, null)
mv.visitVarInsn(ALOAD, 3);
var copyByProperty = kotlinCopyMethod.forProperty(property)
KotlinCopyMethod.KotlinCopyByProperty copyByProperty = kotlinCopyMethod.forProperty(property)
.orElseThrow(() -> new IllegalStateException(
String.format("No usable .copy(…) method found for property %s", property)));
for (var i = 1; i < kotlinCopyMethod.getParameterCount(); i++) {
for (int i = 1; i < kotlinCopyMethod.getParameterCount(); i++) {
if (copyByProperty.getParameterPosition() == i) {
@@ -1125,7 +1125,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitInsn(Opcodes.ACONST_NULL);
var invokeOpCode = getInvokeOp(copy, false);
int invokeOpCode = getInvokeOp(copy, false);
mv.visitMethodInsn(invokeOpCode, Type.getInternalName(copy.getDeclaringClass()), copy.getName(),
getArgumentSignature(copy), false);
@@ -1185,7 +1185,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitSetField(PersistentEntity<?, ?> entity, PersistentProperty<?> property, MethodVisitor mv,
String internalClassName) {
var field = property.getField();
Field field = property.getField();
if (field != null) {
if (generateSetterMethodHandle(entity, field)) {
// $fieldSetter.invoke(bean, object)
@@ -1200,7 +1200,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ALOAD, 2);
var fieldType = field.getType();
Class<?> fieldType = field.getType();
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(autoboxType(fieldType)));
autoboxIfNeeded(autoboxType(fieldType), fieldType, mv);
@@ -1220,10 +1220,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
private static String getArgumentSignature(Method method) {
var result = new StringBuilder("(");
StringBuilder result = new StringBuilder("(");
List<String> argumentTypes = new ArrayList<>();
for (var parameterType : method.getParameterTypes()) {
for (Class<?> parameterType : method.getParameterTypes()) {
result.append("%s");
argumentTypes.add(signatureTypeName(parameterType));
@@ -1319,7 +1319,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
if (isAccessible(entity)) {
if (Modifier.isProtected(member.getModifiers()) || isDefault(member.getModifiers())) {
var declaringPackage = member.getDeclaringClass().getPackage();
Package declaringPackage = member.getDeclaringClass().getPackage();
if (declaringPackage != null && !declaringPackage.equals(entity.getType().getPackage())) {
return true;
@@ -1348,15 +1348,15 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static void visitInvokeMethodSingleArg(MethodVisitor mv, Method method) {
var parameterTypes = method.getParameterTypes();
var parameterType = parameterTypes[0];
var declaringClass = method.getDeclaringClass();
var interfaceDefinition = declaringClass.isInterface();
Class<?>[] parameterTypes = method.getParameterTypes();
Class<?> parameterType = parameterTypes[0];
Class<?> declaringClass = method.getDeclaringClass();
boolean interfaceDefinition = declaringClass.isInterface();
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(autoboxType(parameterType)));
autoboxIfNeeded(autoboxType(parameterType), parameterType, mv);
var invokeOpCode = getInvokeOp(method, interfaceDefinition);
int invokeOpCode = getInvokeOp(method, interfaceDefinition);
mv.visitMethodInsn(invokeOpCode, Type.getInternalName(method.getDeclaringClass()), method.getName(),
String.format("(%s)%s", signatureTypeName(parameterType), signatureTypeName(method.getReturnType())),
@@ -1365,7 +1365,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
private static int getInvokeOp(Method method, boolean interfaceDefinition) {
var invokeOpCode = Modifier.isStatic(method.getModifiers()) ? INVOKESTATIC : INVOKEVIRTUAL;
int invokeOpCode = Modifier.isStatic(method.getModifiers()) ? INVOKESTATIC : INVOKEVIRTUAL;
if (interfaceDefinition) {
invokeOpCode = INVOKEINTERFACE;
@@ -1378,7 +1378,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
Map<String, PropertyStackAddress> stackmap = new HashMap<>();
for (var property : persistentProperties) {
for (PersistentProperty<?> property : persistentProperties) {
stackmap.put(property.getName(), new PropertyStackAddress(new Label(), property.getName().hashCode()));
}
return stackmap;
@@ -1435,7 +1435,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
*/
private static boolean hasKotlinCopyMethod(PersistentProperty<?> property) {
var type = property.getOwner().getType();
Class<?> type = property.getOwner().getType();
if (isAccessible(type) && KotlinDetector.isKotlinType(type)) {
return KotlinCopyMethod.findCopyMethod(type).filter(it -> it.supportsProperty(property)).isPresent();

View File

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

View File

@@ -18,6 +18,7 @@ package org.springframework.data.mapping.model;
import org.springframework.data.mapping.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;
@@ -46,7 +47,7 @@ public class DefaultSpELExpressionEvaluator implements SpELExpressionEvaluator {
@SuppressWarnings("unchecked")
public <T> T evaluate(String expression) {
var parseExpression = factory.getParser().parseExpression(expression);
Expression parseExpression = factory.getParser().parseExpression(expression);
return (T) parseExpression.getValue(factory.getEvaluationContext(source));
}
}

View File

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

View File

@@ -17,6 +17,7 @@ package org.springframework.data.mapping.model;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -26,12 +27,13 @@ import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.FactoryMethod;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
/**
@@ -55,11 +57,11 @@ class InstanceCreatorMetadataDiscoverer {
@Nullable
public static <T, P extends PersistentProperty<P>> InstanceCreatorMetadata<P> discover(PersistentEntity<T, P> entity) {
var declaredConstructors = entity.getType().getDeclaredConstructors();
var declaredMethods = entity.getType().getDeclaredMethods();
Constructor<?>[] declaredConstructors = entity.getType().getDeclaredConstructors();
Method[] declaredMethods = entity.getType().getDeclaredMethods();
var hasAnnotatedFactoryMethod = findAnnotation(PersistenceCreator.class, declaredMethods);
var hasAnnotatedConstructor = findAnnotation(PersistenceCreator.class, declaredConstructors);
boolean hasAnnotatedFactoryMethod = findAnnotation(PersistenceCreator.class, declaredMethods);
boolean hasAnnotatedConstructor = findAnnotation(PersistenceCreator.class, declaredConstructors);
if (hasAnnotatedConstructor && hasAnnotatedFactoryMethod) {
throw new MappingException(
@@ -69,7 +71,7 @@ class InstanceCreatorMetadataDiscoverer {
if (hasAnnotatedFactoryMethod) {
var candidates = discoverFactoryMethods(entity, declaredMethods);
List<Method> candidates = discoverFactoryMethods(entity, declaredMethods);
if (candidates.size() == 1) {
return getFactoryMethod(entity, candidates.get(0));
@@ -84,7 +86,7 @@ class InstanceCreatorMetadataDiscoverer {
List<Method> candidates = new ArrayList<>();
for (var method : declaredMethods) {
for (Method method : declaredMethods) {
validateMethod(method);
@@ -105,16 +107,16 @@ class InstanceCreatorMetadataDiscoverer {
PersistentEntity<T, P> entity, Method method) {
Parameter<Object, P>[] parameters = new Parameter[method.getParameterCount()];
var parameterAnnotations = method.getParameterAnnotations();
var types = entity.getTypeInformation().getParameterTypes(method);
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
List<TypeInformation<?>> types = entity.getTypeInformation().getParameterTypes(method);
var parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method);
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method);
for (var i = 0; i < parameters.length; i++) {
for (int i = 0; i < parameters.length; i++) {
var name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
var type = types.get(i);
var annotations = parameterAnnotations[i];
String name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
TypeInformation<?> type = types.get(i);
Annotation[] annotations = parameterAnnotations[i];
parameters[i] = new Parameter(name, type, annotations, entity);
}
@@ -150,7 +152,7 @@ class InstanceCreatorMetadataDiscoverer {
private static boolean findAnnotation(Class<? extends Annotation> annotationType, AnnotatedElement... elements) {
for (var element : elements) {
for (AnnotatedElement element : elements) {
if (MergedAnnotations.from(element).isPresent(annotationType)) {
return true;
}

View File

@@ -19,7 +19,9 @@ import java.util.function.Function;
import org.springframework.core.KotlinDetector;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.lang.Nullable;
@@ -70,8 +72,8 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
@Override
public void setProperty(PersistentProperty<?> property, @Nullable Object value) {
var owner = property.getOwner();
var delegate = delegateFunction.apply(this.bean);
PersistentEntity<?, ? extends PersistentProperty<?>> owner = property.getOwner();
PersistentPropertyAccessor<T> delegate = delegateFunction.apply(this.bean);
if (!property.isImmutable() || property.getWither() != null || KotlinDetector.isKotlinType(owner.getType())) {
@@ -81,7 +83,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
return;
}
var creator = owner.getInstanceCreatorMetadata();
InstanceCreatorMetadata<? extends PersistentProperty<?>> creator = owner.getInstanceCreatorMetadata();
if (creator == null) {
throw new IllegalStateException(String.format(NO_SETTER_OR_CONSTRUCTOR, property.getName(), owner.getType()));
@@ -100,7 +102,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
}
});
var instantiator = instantiators.getInstantiatorFor(owner);
EntityInstantiator instantiator = instantiators.getInstantiatorFor(owner);
this.bean = (T) instantiator.createInstance(owner, new ParameterValueProvider() {

View File

@@ -46,17 +46,18 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
@Override
protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> entity) {
var creator = entity.getInstanceCreatorMetadata();
InstanceCreatorMetadata<? extends PersistentProperty<?>> creator = entity.getInstanceCreatorMetadata();
if (KotlinReflectionUtils.isSupportedKotlinClass(entity.getType())
&& creator instanceof PreferredConstructor<?, ?> constructor) {
var defaultConstructor = new DefaultingKotlinConstructorResolver(entity)
PreferredConstructor<?, ? extends PersistentProperty<?>> defaultConstructor = new DefaultingKotlinConstructorResolver(
entity)
.getDefaultConstructor();
if (defaultConstructor != null) {
var instantiator = createObjectInstantiator(entity, defaultConstructor);
ObjectInstantiator instantiator = createObjectInstantiator(entity, defaultConstructor);
return new DefaultingKotlinClassInstantiatorAdapter(instantiator, constructor);
}
@@ -79,8 +80,8 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
@SuppressWarnings("unchecked")
DefaultingKotlinConstructorResolver(PersistentEntity<?, ?> entity) {
var hit = resolveDefaultConstructor(entity);
var creator = entity.getInstanceCreatorMetadata();
Constructor<?> hit = resolveDefaultConstructor(entity);
InstanceCreatorMetadata<? extends PersistentProperty<?>> creator = entity.getInstanceCreatorMetadata();
if ((hit != null) && creator instanceof PreferredConstructor<?, ?> persistenceConstructor) {
this.defaultConstructor = new PreferredConstructor<>(hit,
@@ -98,9 +99,9 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
}
Constructor<?> hit = null;
var constructor = persistenceConstructor.getConstructor();
Constructor<?> constructor = persistenceConstructor.getConstructor();
for (var candidate : entity.getType().getDeclaredConstructors()) {
for (Constructor<?> candidate : entity.getType().getDeclaredConstructors()) {
// use only synthetic constructors
if (!candidate.isSynthetic()) {
@@ -109,15 +110,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
var syntheticParameters = KotlinDefaultMask.getMaskCount(constructor.getParameterCount())
int syntheticParameters = KotlinDefaultMask.getMaskCount(constructor.getParameterCount())
+ /* DefaultConstructorMarker */ 1;
if ((constructor.getParameterCount() + syntheticParameters) != candidate.getParameterCount()) {
continue;
}
var constructorParameters = constructor.getParameters();
var candidateParameters = candidate.getParameters();
java.lang.reflect.Parameter[] constructorParameters = constructor.getParameters();
java.lang.reflect.Parameter[] candidateParameters = candidate.getParameters();
if (!candidateParameters[candidateParameters.length - 1].getType().getName()
.equals("kotlin.jvm.internal.DefaultConstructorMarker")) {
@@ -173,7 +174,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
DefaultingKotlinClassInstantiatorAdapter(ObjectInstantiator instantiator, PreferredConstructor<?, ?> constructor) {
var kotlinConstructor = ReflectJvmMapping.getKotlinFunction(constructor.getConstructor());
KFunction<?> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(constructor.getConstructor());
if (kotlinConstructor == null) {
throw new IllegalArgumentException(
@@ -191,7 +192,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
var params = extractInvocationArguments(entity.getInstanceCreatorMetadata(), provider);
Object[] params = extractInvocationArguments(entity.getInstanceCreatorMetadata(), provider);
try {
return (T) instantiator.newInstance(params);
@@ -207,25 +208,25 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
throw new IllegalArgumentException("EntityCreator must not be null!");
}
var params = allocateArguments(synthetic.getParameterCount()
Object[] params = allocateArguments(synthetic.getParameterCount()
+ KotlinDefaultMask.getMaskCount(synthetic.getParameterCount()) + /* DefaultConstructorMarker */1);
var userParameterCount = kParameters.size();
int userParameterCount = kParameters.size();
var parameters = entityCreator.getParameters();
List<Parameter<Object, P>> parameters = entityCreator.getParameters();
// Prepare user-space arguments
for (var i = 0; i < userParameterCount; i++) {
for (int i = 0; i < userParameterCount; i++) {
var parameter = parameters.get(i);
Parameter<Object, P> parameter = parameters.get(i);
params[i] = provider.getParameterValue(parameter);
}
var defaultMask = KotlinDefaultMask.from(constructor, it -> {
KotlinDefaultMask defaultMask = KotlinDefaultMask.from(constructor, it -> {
var index = kParameters.indexOf(it);
int index = kParameters.indexOf(it);
var parameter = parameters.get(index);
var type = parameter.getType().getType();
Parameter<Object, P> parameter = parameters.get(index);
Class<Object> type = parameter.getType().getType();
if (it.isOptional() && (params[index] == null)) {
if (type.isPrimitive()) {
@@ -239,9 +240,9 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
return true;
});
var defaulting = defaultMask.getDefaulting();
int[] defaulting = defaultMask.getDefaulting();
// append nullability masks to creation arguments
for (var i = 0; i < defaulting.length; i++) {
for (int i = 0; i < defaulting.length; i++) {
params[userParameterCount + i] = defaulting[i];
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.mapping.model;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentEntity;
@@ -47,19 +48,19 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty
@SuppressWarnings("unchecked")
public <T> T getParameterValue(Parameter<T, P> parameter) {
var creator = entity.getInstanceCreatorMetadata();
InstanceCreatorMetadata<P> creator = entity.getInstanceCreatorMetadata();
if (creator != null && creator.isParentParameter(parameter)) {
return (T) parent;
}
var name = parameter.getName();
String name = parameter.getName();
if (name == null) {
throw new MappingException(String.format("Parameter %s does not have a name!", parameter));
}
var property = entity.getPersistentProperty(name);
P property = entity.getPersistentProperty(name);
if (property == null) {
throw new MappingException(

View File

@@ -16,9 +16,11 @@
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;
@@ -104,7 +106,7 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
List<Constructor<?>> candidates = new ArrayList<>();
Constructor<?> noArg = null;
for (var candidate : rawOwningType.getDeclaredConstructors()) {
for (Constructor<?> candidate : rawOwningType.getDeclaredConstructors()) {
// Synthetic constructors should not be considered
if (candidate.isSynthetic()) {
@@ -151,14 +153,14 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
.findFirst() //
.orElseGet(() -> {
var primaryConstructor = KClasses
KFunction<T> primaryConstructor = KClasses
.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(type.getType()));
if (primaryConstructor == null) {
return DEFAULT.discover(type, entity);
}
var javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
Constructor<T> javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
return javaConstructor != null ? buildPreferredConstructor(javaConstructor, type, entity) : null;
});
@@ -196,17 +198,17 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
return new PreferredConstructor<>((Constructor<T>) constructor);
}
var parameterTypes = typeInformation.getParameterTypes(constructor);
var parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor);
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
Parameter<Object, P>[] parameters = new Parameter[parameterTypes.size()];
var parameterAnnotations = constructor.getParameterAnnotations();
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
for (var i = 0; i < parameterTypes.size(); i++) {
for (int i = 0; i < parameterTypes.size(); i++) {
var name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
var type = parameterTypes.get(i);
var annotations = parameterAnnotations[i];
String name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
TypeInformation<?> type = parameterTypes.get(i);
Annotation[] annotations = parameterAnnotations[i];
parameters[i] = new Parameter(name, type, annotations, entity);
}

View File

@@ -264,8 +264,8 @@ public class Property {
private static Optional<Method> findWither(TypeInformation<?> owner, String propertyName, Class<?> rawType) {
var resultHolder = new AtomicReference<Method>();
var methodName = String.format("with%s", StringUtils.capitalize(propertyName));
AtomicReference<Method> resultHolder = new AtomicReference<Method>();
String methodName = String.format("with%s", StringUtils.capitalize(propertyName));
ReflectionUtils.doWithMethods(owner.getType(), it -> {
@@ -274,7 +274,7 @@ public class Property {
}
}, it -> isMethodWithSingleParameterOfType(it, methodName, rawType));
var method = resultHolder.get();
Method method = resultHolder.get();
return method != null ? Optional.of(method) : Optional.empty();
}

View File

@@ -23,6 +23,7 @@ import java.util.Collections;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.data.mapping.FactoryMethod;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
@@ -46,15 +47,15 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
ParameterValueProvider<P> provider) {
var creator = entity.getInstanceCreatorMetadata();
InstanceCreatorMetadata<P> creator = entity.getInstanceCreatorMetadata();
if (creator == null) {
return instantiateClass(entity);
}
var parameterCount = creator.getParameterCount();
int parameterCount = creator.getParameterCount();
var params = parameterCount == 0 ? EMPTY_ARGS : new Object[parameterCount];
var i = 0;
Object[] params = parameterCount == 0 ? EMPTY_ARGS : new Object[parameterCount];
int i = 0;
for (Parameter<?, P> parameter : creator.getParameters()) {
params[i++] = provider.getParameterValue(parameter);
}
@@ -62,7 +63,7 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
if (creator instanceof FactoryMethod<?, ?> method) {
try {
var t = (T) ReflectionUtils.invokeMethod(method.getFactoryMethod(), null, params);
T t = (T) ReflectionUtils.invokeMethod(method.getFactoryMethod(), null, params);
if (t == null) {
throw new IllegalStateException("Method %s returned null!".formatted(method.getFactoryMethod()));
@@ -87,8 +88,8 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
try {
Class<?> clazz = entity.getType();
if (clazz.isArray()) {
var ctype = clazz;
var dims = 0;
Class<?> ctype = clazz;
int dims = 0;
while (ctype.isArray()) {
ctype = ctype.getComponentType();
dims++;

View File

@@ -32,6 +32,7 @@ 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;
@@ -81,7 +82,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, GetOptions options) {
Object bean = getBean();
var current = bean;
Object current = bean;
if (path.isEmpty()) {
return bean;
@@ -93,8 +94,8 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return handleNull(path, options.getNullValues().toNullHandling());
}
var entity = property.getOwner();
var accessor = entity.getPropertyAccessor(current);
PersistentEntity<?, ? extends PersistentProperty<?>> entity = property.getOwner();
PersistentPropertyAccessor<Object> accessor = entity.getPropertyAccessor(current);
current = accessor.getProperty(property);
}
@@ -120,18 +121,18 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
Assert.notNull(path, "PersistentPropertyPath must not be null!");
Assert.isTrue(!path.isEmpty(), "PersistentPropertyPath must not be empty!");
var parentPath = path.getParentPath();
var leafProperty = path.getRequiredLeafProperty();
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
PersistentProperty<? extends PersistentProperty<?>> leafProperty = path.getRequiredLeafProperty();
if (!options.propagate(parentPath.getLeafProperty())) {
return;
}
var lookupOptions = options.getNullHandling() != REJECT
GetOptions lookupOptions = options.getNullHandling() != REJECT
? DEFAULT_GET_OPTIONS.withNullValues(GetNulls.EARLY_RETURN)
: DEFAULT_GET_OPTIONS;
var parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
if (parent == null) {
handleNull(path, options.getNullHandling());
@@ -144,7 +145,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return;
}
var parentProperty = parentPath.getRequiredLeafProperty();
PersistentProperty<? extends PersistentProperty<?>> parentProperty = parentPath.getRequiredLeafProperty();
Object newValue;
@@ -168,7 +169,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return;
}
var result = CollectionFactory.createApproximateMap(source, source.size());
Map<Object, Object> result = CollectionFactory.createApproximateMap(source, source.size());
for (Entry<?, Object> entry : source.entrySet()) {
result.put(entry.getKey(), setValue(entry.getValue(), leafProperty, value));
@@ -197,14 +198,14 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
return null;
}
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
String 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;
}
var parentPath = path.getParentPath();
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
throw new MappingException(String.format(nullIntermediateMessage, parentPath.getLeafProperty(), path.toDotPath(),
getBean().getClass().getName()));
@@ -221,7 +222,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
*/
private static Object setValue(Object parent, PersistentProperty<?> property, @Nullable Object newValue) {
var accessor = property.getAccessorForOwner(parent);
PersistentPropertyAccessor<Object> accessor = property.getAccessorForOwner(parent);
accessor.setProperty(property, newValue);
return accessor.getBean();
}
@@ -241,7 +242,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
Assert.notNull(property, "Property must not be null!");
Assert.notNull(type, "Type must not be null!");
var value = getProperty(property);
Object value = getProperty(property);
if (value == null) {
return null;

View File

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

View File

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

View File

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

View File

@@ -44,7 +44,7 @@ public final class Accessor {
Assert.notNull(method, "Method must not be null!");
var descriptor = BeanUtils.findPropertyForMethod(method);
PropertyDescriptor descriptor = BeanUtils.findPropertyForMethod(method);
if (descriptor == null) {
throw new IllegalArgumentException(String.format("Invoked method %s is no accessor method!", method));

View File

@@ -55,9 +55,9 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
*/
public static boolean hasDefaultMethods(Class<?> interfaceClass) {
var methods = ReflectionUtils.getAllDeclaredMethods(interfaceClass);
Method[] methods = ReflectionUtils.getAllDeclaredMethods(interfaceClass);
for (var method : methods) {
for (Method method : methods) {
if (method.isDefault()) {
return true;
}
@@ -70,21 +70,21 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
@Override
public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) throws Throwable {
var method = invocation.getMethod();
Method method = invocation.getMethod();
if (!method.isDefault()) {
return invocation.proceed();
}
var arguments = invocation.getArguments();
var proxy = ((ProxyMethodInvocation) invocation).getProxy();
Object[] arguments = invocation.getArguments();
Object proxy = ((ProxyMethodInvocation) invocation).getProxy();
return getMethodHandle(method).bindTo(proxy).invokeWithArguments(arguments);
}
private MethodHandle getMethodHandle(Method method) throws Exception {
var handle = methodHandleCache.get(method);
MethodHandle handle = methodHandleCache.get(method);
if (handle == null) {
@@ -127,7 +127,7 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
private Lookup getLookup(Class<?> declaringClass, Method privateLookupIn) {
var lookup = MethodHandles.lookup();
Lookup lookup = MethodHandles.lookup();
try {
return (Lookup) privateLookupIn.invoke(MethodHandles.class, declaringClass, lookup);
@@ -152,7 +152,7 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
throw new IllegalStateException("Could not obtain MethodHandles.lookup constructor!");
}
var constructor = this.constructor.get();
Constructor<Lookup> constructor = this.constructor.get();
return constructor.newInstance(method.getDeclaringClass()).unreflectSpecial(method, method.getDeclaringClass());
}
@@ -184,7 +184,7 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
private static MethodHandle doLookup(Method method, Lookup lookup)
throws NoSuchMethodException, IllegalAccessException {
var methodType = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
MethodType methodType = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
if (Modifier.isStatic(method.getModifiers())) {
return lookup.findStatic(method.getDeclaringClass(), method.getName(), methodType);
@@ -215,7 +215,7 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
*/
public static MethodHandleLookup getMethodHandleLookup() {
for (var it : MethodHandleLookup.values()) {
for (MethodHandleLookup it : MethodHandleLookup.values()) {
if (it.isAvailable()) {
return it;
@@ -230,7 +230,7 @@ public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor
try {
var constructor = Lookup.class.getDeclaredConstructor(Class.class);
Constructor<Lookup> constructor = Lookup.class.getDeclaredConstructor(Class.class);
ReflectionUtils.makeAccessible(constructor);
return constructor;

View File

@@ -17,6 +17,7 @@ package org.springframework.data.projection;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -33,6 +34,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.core.log.LogMessage;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.data.util.StreamUtils;
import org.springframework.util.Assert;
@@ -103,7 +105,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
*/
private static boolean hasDefaultGetter(PropertyDescriptor descriptor) {
var method = descriptor.getReadMethod();
Method method = descriptor.getReadMethod();
return method != null && method.isDefault();
}
@@ -153,13 +155,13 @@ class DefaultProjectionInformation implements ProjectionInformation {
*/
private Stream<PropertyDescriptor> collectDescriptors() {
var allButDefaultGetters = Arrays.stream(BeanUtils.getPropertyDescriptors(type)) //
Stream<PropertyDescriptor> allButDefaultGetters = Arrays.stream(BeanUtils.getPropertyDescriptors(type)) //
.filter(it -> !hasDefaultGetter(it));
var ownDescriptors = metadata.map(it -> filterAndOrder(allButDefaultGetters, it))
Stream<PropertyDescriptor> ownDescriptors = metadata.map(it -> filterAndOrder(allButDefaultGetters, it))
.orElse(allButDefaultGetters);
var superTypeDescriptors = metadata.map(this::fromMetadata) //
Stream<PropertyDescriptor> superTypeDescriptors = metadata.map(this::fromMetadata) //
.orElseGet(this::fromType) //
.flatMap(it -> new PropertyDescriptorSource(it).collectDescriptors());
@@ -177,7 +179,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
private static Stream<PropertyDescriptor> filterAndOrder(Stream<PropertyDescriptor> source,
AnnotationMetadata metadata) {
var orderedMethods = getMethodOrder(metadata);
Map<String, Integer> orderedMethods = getMethodOrder(metadata);
if (orderedMethods.isEmpty()) {
return source;
@@ -218,8 +220,8 @@ class DefaultProjectionInformation implements ProjectionInformation {
try {
var factory = new SimpleMetadataReaderFactory(type.getClassLoader());
var metadataReader = factory.getMetadataReader(ClassUtils.getQualifiedName(type));
SimpleMetadataReaderFactory factory = new SimpleMetadataReaderFactory(type.getClassLoader());
MetadataReader metadataReader = factory.getMetadataReader(ClassUtils.getQualifiedName(type));
return Optional.of(metadataReader.getAnnotationMetadata());
@@ -254,7 +256,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
*/
private static Map<String, Integer> getMethodOrder(AnnotationMetadata metadata) {
var methods = metadata.getDeclaredMethods() //
List<String> methods = metadata.getDeclaredMethods() //
.stream() //
.map(MethodMetadata::getMethodName) //
.distinct() //

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