Migrate code to Java 17 style.
Use var instead of explicit local types where applicable. Use pattern variable instead instanceof and cast. Prefer loops and nullable types over Stream and Optional. Convert classes to records where applicable. See #2465
This commit is contained in:
committed by
Jens Schauder
parent
d4036ec0a9
commit
c735b58607
@@ -186,7 +186,7 @@ public class AccessOptions {
|
||||
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
|
||||
.format("Cannot register a property handler for %s on a property of type %s!", type, property.getType()));
|
||||
|
||||
Function<Object, T> caster = it -> type.cast(it);
|
||||
var caster = (Function<Object, T>) it -> type.cast(it);
|
||||
|
||||
return registerHandler(property, caster.andThen(handler));
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public class AccessOptions {
|
||||
@Nullable
|
||||
Object postProcess(PersistentProperty<?> property, @Nullable Object value) {
|
||||
|
||||
Function<Object, Object> handler = handlers.get(property);
|
||||
var handler = handlers.get(property);
|
||||
|
||||
return handler == null ? value : handler.apply(value);
|
||||
}
|
||||
|
||||
@@ -158,11 +158,10 @@ public final class Alias {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Alias)) {
|
||||
if (!(o instanceof Alias alias)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Alias alias = (Alias) o;
|
||||
return ObjectUtils.nullSafeEquals(value, alias.value);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface IdentifierAccessor {
|
||||
*/
|
||||
default Object getRequiredIdentifier() {
|
||||
|
||||
Object identifier = getIdentifier();
|
||||
var identifier = getIdentifier();
|
||||
|
||||
if (identifier != null) {
|
||||
return identifier;
|
||||
|
||||
@@ -97,7 +97,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
*/
|
||||
default P getRequiredIdProperty() {
|
||||
|
||||
P property = getIdProperty();
|
||||
var property = getIdProperty();
|
||||
|
||||
if (property != null) {
|
||||
return property;
|
||||
@@ -125,7 +125,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
*/
|
||||
default P getRequiredVersionProperty() {
|
||||
|
||||
P property = getVersionProperty();
|
||||
var property = getVersionProperty();
|
||||
|
||||
if (property != null) {
|
||||
return property;
|
||||
@@ -152,7 +152,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
*/
|
||||
default P getRequiredPersistentProperty(String name) {
|
||||
|
||||
P property = getPersistentProperty(name);
|
||||
var property = getPersistentProperty(name);
|
||||
|
||||
if (property != null) {
|
||||
return property;
|
||||
@@ -171,7 +171,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
@Nullable
|
||||
default P getPersistentProperty(Class<? extends Annotation> annotationType) {
|
||||
|
||||
Iterator<P> it = getPersistentProperties(annotationType).iterator();
|
||||
var it = getPersistentProperties(annotationType).iterator();
|
||||
return it.hasNext() ? it.next() : null;
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
*/
|
||||
default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType) throws IllegalStateException {
|
||||
|
||||
A annotation = findAnnotation(annotationType);
|
||||
var annotation = findAnnotation(annotationType);
|
||||
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
|
||||
@@ -85,7 +85,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
|
||||
default Method getRequiredGetter() {
|
||||
|
||||
Method getter = getGetter();
|
||||
var getter = getGetter();
|
||||
|
||||
if (getter == null) {
|
||||
throw new IllegalArgumentException(String.format("No getter available for persistent property %s!", this));
|
||||
@@ -105,7 +105,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
|
||||
default Method getRequiredSetter() {
|
||||
|
||||
Method setter = getSetter();
|
||||
var setter = getSetter();
|
||||
|
||||
if (setter == null) {
|
||||
throw new IllegalArgumentException(String.format("No setter available for persistent property %s!", this));
|
||||
@@ -143,7 +143,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
|
||||
default Method getRequiredWither() {
|
||||
|
||||
Method wither = getWither();
|
||||
var wither = getWither();
|
||||
|
||||
if (wither == null) {
|
||||
throw new IllegalArgumentException(String.format("No wither available for persistent property %s!", this));
|
||||
@@ -157,7 +157,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
|
||||
default Field getRequiredField() {
|
||||
|
||||
Field field = getField();
|
||||
var field = getField();
|
||||
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException(String.format("No field backing persistent property %s!", this));
|
||||
@@ -186,7 +186,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
*/
|
||||
default Association<P> getRequiredAssociation() {
|
||||
|
||||
Association<P> association = getAssociation();
|
||||
var association = getAssociation();
|
||||
|
||||
if (association != null) {
|
||||
return association;
|
||||
@@ -332,7 +332,7 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
*/
|
||||
default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType) throws IllegalStateException {
|
||||
|
||||
A annotation = findAnnotation(annotationType);
|
||||
var annotation = findAnnotation(annotationType);
|
||||
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
|
||||
@@ -61,26 +61,26 @@ public interface PersistentPropertyAccessor<T> {
|
||||
Assert.notNull(path, "PersistentPropertyPath must not be null!");
|
||||
Assert.isTrue(!path.isEmpty(), "PersistentPropertyPath must not be empty!");
|
||||
|
||||
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
|
||||
PersistentProperty<?> leafProperty = path.getRequiredLeafProperty();
|
||||
PersistentProperty<?> parentProperty = parentPath.isEmpty() ? null : parentPath.getLeafProperty();
|
||||
var parentPath = path.getParentPath();
|
||||
var leafProperty = path.getRequiredLeafProperty();
|
||||
var parentProperty = parentPath.isEmpty() ? null : parentPath.getLeafProperty();
|
||||
|
||||
if (parentProperty != null && (parentProperty.isCollectionLike() || parentProperty.isMap())) {
|
||||
throw new MappingException(
|
||||
String.format("Cannot traverse collection or map intermediate %s", parentPath.toDotPath()));
|
||||
}
|
||||
|
||||
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
|
||||
var parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
|
||||
|
||||
if (parent == null) {
|
||||
|
||||
String nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
|
||||
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
|
||||
|
||||
throw new MappingException(
|
||||
String.format(nullIntermediateMessage, parentProperty, path.toDotPath(), getBean().getClass().getName()));
|
||||
}
|
||||
|
||||
PersistentPropertyAccessor<?> accessor = parent == getBean() //
|
||||
var accessor = parent == getBean() //
|
||||
? this //
|
||||
: leafProperty.getOwner().getPropertyAccessor(parent);
|
||||
|
||||
@@ -90,7 +90,7 @@ public interface PersistentPropertyAccessor<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
Object bean = accessor.getBean();
|
||||
var bean = accessor.getBean();
|
||||
|
||||
if (bean != parent) {
|
||||
setProperty(parentPath, bean);
|
||||
@@ -140,7 +140,7 @@ public interface PersistentPropertyAccessor<T> {
|
||||
default Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, TraversalContext context) {
|
||||
|
||||
Object bean = getBean();
|
||||
Object current = bean;
|
||||
var current = bean;
|
||||
|
||||
if (path.isEmpty()) {
|
||||
return bean;
|
||||
@@ -150,14 +150,14 @@ public interface PersistentPropertyAccessor<T> {
|
||||
|
||||
if (current == null) {
|
||||
|
||||
String nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
|
||||
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
|
||||
|
||||
throw new MappingException(
|
||||
String.format(nullIntermediateMessage, property, path.toDotPath(), bean.getClass().getName()));
|
||||
}
|
||||
|
||||
PersistentEntity<?, ? extends PersistentProperty<?>> entity = property.getOwner();
|
||||
PersistentPropertyAccessor<Object> accessor = entity.getPropertyAccessor(current);
|
||||
var entity = property.getOwner();
|
||||
var accessor = entity.getPropertyAccessor(current);
|
||||
|
||||
current = context.postProcess(property, accessor.getProperty(property));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends
|
||||
|
||||
default P getRequiredLeafProperty() {
|
||||
|
||||
P property = getLeafProperty();
|
||||
var property = getLeafProperty();
|
||||
|
||||
if (property == null) {
|
||||
throw new IllegalStateException("No leaf property found!");
|
||||
|
||||
@@ -131,13 +131,13 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
|
||||
Assert.notNull(property, "Property must not be null!");
|
||||
|
||||
Boolean cached = isPropertyParameterCache.get(property);
|
||||
var cached = isPropertyParameterCache.get(property);
|
||||
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
boolean result = false;
|
||||
var result = false;
|
||||
for (Parameter<?, P> parameter : parameters) {
|
||||
if (parameter.maps(property)) {
|
||||
result = true;
|
||||
@@ -214,7 +214,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
Class<T> owningType = entity.getType();
|
||||
var owningType = entity.getType();
|
||||
return owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass());
|
||||
});
|
||||
|
||||
@@ -297,12 +297,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Parameter)) {
|
||||
if (!(o instanceof Parameter<?, ?> parameter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Parameter<?, ?> parameter = (Parameter<?, ?>) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(name, parameter.name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -324,7 +322,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(name);
|
||||
var result = ObjectUtils.nullSafeHashCode(name);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(type);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(key);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(entity);
|
||||
@@ -339,10 +337,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
*/
|
||||
boolean maps(PersistentProperty<?> property) {
|
||||
|
||||
PersistentEntity<T, P> entity = this.entity;
|
||||
String name = this.name;
|
||||
var entity = this.entity;
|
||||
var name = this.name;
|
||||
|
||||
P referencedProperty = entity == null ? null : name == null ? null : entity.getPersistentProperty(name);
|
||||
var referencedProperty = entity == null ? null : name == null ? null : entity.getPersistentProperty(name);
|
||||
|
||||
return property.equals(referencedProperty);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
@@ -83,8 +82,8 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
Assert.notNull(owningType, "Owning type must not be null!");
|
||||
Assert.notNull(base, "Previously found properties must not be null!");
|
||||
|
||||
String propertyName = Introspector.decapitalize(name);
|
||||
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
|
||||
var propertyName = Introspector.decapitalize(name);
|
||||
var propertyType = owningType.getProperty(propertyName);
|
||||
|
||||
if (propertyType == null) {
|
||||
throw new PropertyReferenceException(propertyName, owningType, base);
|
||||
@@ -123,7 +122,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
*/
|
||||
public PropertyPath getLeafProperty() {
|
||||
|
||||
PropertyPath result = this;
|
||||
var result = this;
|
||||
|
||||
while (result.hasNext()) {
|
||||
result = result.requiredNext();
|
||||
@@ -209,7 +208,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
|
||||
Assert.hasText(path, "Path must not be null or empty!");
|
||||
|
||||
String lookup = toDotPath().concat(".").concat(path);
|
||||
var lookup = toDotPath().concat(".").concat(path);
|
||||
|
||||
return PropertyPath.from(lookup, owningType);
|
||||
}
|
||||
@@ -231,7 +230,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
@Nullable
|
||||
public PropertyPath next() {
|
||||
|
||||
PropertyPath result = current;
|
||||
var result = current;
|
||||
|
||||
if (result == null) {
|
||||
return null;
|
||||
@@ -258,12 +257,10 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof PropertyPath)) {
|
||||
if (!(o instanceof PropertyPath that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PropertyPath that = (PropertyPath) o;
|
||||
|
||||
if (isCollection != that.isCollection) {
|
||||
return false;
|
||||
}
|
||||
@@ -293,7 +290,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(owningType);
|
||||
var result = ObjectUtils.nullSafeHashCode(owningType);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(name);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(typeInformation);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(actualTypeInformation);
|
||||
@@ -310,7 +307,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
*/
|
||||
private PropertyPath requiredNext() {
|
||||
|
||||
PropertyPath result = next;
|
||||
var result = next;
|
||||
|
||||
if (result == null) {
|
||||
throw new IllegalStateException(
|
||||
@@ -349,17 +346,17 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
|
||||
List<String> iteratorSource = new ArrayList<>();
|
||||
|
||||
Matcher matcher = isQuoted(it.path) ? SPLITTER_FOR_QUOTED.matcher(it.path.replace("\\Q", "").replace("\\E", ""))
|
||||
var matcher = isQuoted(it.path) ? SPLITTER_FOR_QUOTED.matcher(it.path.replace("\\Q", "").replace("\\E", ""))
|
||||
: SPLITTER.matcher("_" + it.path);
|
||||
|
||||
while (matcher.find()) {
|
||||
iteratorSource.add(matcher.group(1));
|
||||
}
|
||||
|
||||
Iterator<String> parts = iteratorSource.iterator();
|
||||
var parts = iteratorSource.iterator();
|
||||
|
||||
PropertyPath result = null;
|
||||
Stack<PropertyPath> current = new Stack<>();
|
||||
var current = new Stack<PropertyPath>();
|
||||
|
||||
while (parts.hasNext()) {
|
||||
if (result == null) {
|
||||
@@ -392,9 +389,9 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
*/
|
||||
private static PropertyPath create(String source, Stack<PropertyPath> base) {
|
||||
|
||||
PropertyPath previous = base.peek();
|
||||
var previous = base.peek();
|
||||
|
||||
PropertyPath propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base);
|
||||
var propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base);
|
||||
previous.next = propertyPath;
|
||||
return propertyPath;
|
||||
}
|
||||
@@ -458,13 +455,13 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
Matcher matcher = NESTED_PROPERTY_PATTERN.matcher(source);
|
||||
var matcher = NESTED_PROPERTY_PATTERN.matcher(source);
|
||||
|
||||
if (matcher.find() && matcher.start() != 0) {
|
||||
|
||||
int position = matcher.start();
|
||||
String head = source.substring(0, position);
|
||||
String tail = source.substring(position);
|
||||
var position = matcher.start();
|
||||
var head = source.substring(0, position);
|
||||
var tail = source.substring(position);
|
||||
|
||||
try {
|
||||
return create(head, type, tail + addTail, base);
|
||||
@@ -518,12 +515,10 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Key)) {
|
||||
if (!(o instanceof Key key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Key key = (Key) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(type, key.type)) {
|
||||
return false;
|
||||
}
|
||||
@@ -537,7 +532,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(type);
|
||||
var result = ObjectUtils.nullSafeHashCode(type);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -99,12 +99,12 @@ public class PropertyReferenceException extends RuntimeException {
|
||||
@Override
|
||||
public String getMessage() {
|
||||
|
||||
StringBuilder builder = new StringBuilder(
|
||||
var builder = new StringBuilder(
|
||||
String.format(ERROR_TEMPLATE, propertyName, type.getType().getSimpleName()));
|
||||
|
||||
Collection<String> potentialMatches = getPropertyMatches();
|
||||
var potentialMatches = getPropertyMatches();
|
||||
if (!potentialMatches.isEmpty()) {
|
||||
String matches = StringUtils.collectionToDelimitedString(potentialMatches, ",", "'", "'");
|
||||
var matches = StringUtils.collectionToDelimitedString(potentialMatches, ",", "'", "'");
|
||||
builder.append(String.format(HINTS_TEMPLATE, matches));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class TargetAwareIdentifierAccessor implements IdentifierAccesso
|
||||
@Override
|
||||
public Object getRequiredIdentifier() {
|
||||
|
||||
Object identifier = getIdentifier();
|
||||
var identifier = getIdentifier();
|
||||
|
||||
if (identifier != null) {
|
||||
return identifier;
|
||||
|
||||
@@ -124,7 +124,7 @@ public class TraversalContext {
|
||||
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
|
||||
.format("Cannot register a property handler for %s on a property of type %s!", type, property.getType()));
|
||||
|
||||
Function<Object, T> caster = it -> type.cast(it);
|
||||
var caster = (Function<Object, T>) it -> type.cast(it);
|
||||
|
||||
return registerHandler(property, caster.andThen(handler));
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class TraversalContext {
|
||||
@Nullable
|
||||
Object postProcess(PersistentProperty<?> property, @Nullable Object value) {
|
||||
|
||||
Function<Object, Object> handler = handlers.get(property);
|
||||
var handler = handlers.get(property);
|
||||
|
||||
return handler == null ? value : handler.apply(value);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -68,22 +68,22 @@ class DefaultEntityCallbacks implements EntityCallbacks {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
|
||||
Class<T> entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
|
||||
var entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
|
||||
: callbackDiscoverer.resolveDeclaredEntityType(callbackType).getRawClass());
|
||||
|
||||
Method callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
|
||||
var callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
|
||||
|
||||
Method method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
|
||||
var method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
return method;
|
||||
});
|
||||
|
||||
T value = entity;
|
||||
var value = entity;
|
||||
|
||||
for (EntityCallback<T> callback : callbackDiscoverer.getEntityCallbacks(entityType,
|
||||
for (var callback : callbackDiscoverer.getEntityCallbacks(entityType,
|
||||
ResolvableType.forClass(callbackType))) {
|
||||
|
||||
BiFunction<EntityCallback<T>, T, Object> callbackFunction = EntityCallbackDiscoverer
|
||||
var callbackFunction = EntityCallbackDiscoverer
|
||||
.computeCallbackInvokerFunction(callback, callbackMethod, args);
|
||||
value = callbackInvoker.invokeCallback(callback, value, callbackFunction);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class DefaultEntityCallbacks implements EntityCallbacks {
|
||||
this.callbackDiscoverer.addEntityCallback(callback);
|
||||
}
|
||||
|
||||
class SimpleEntityCallbackInvoker implements org.springframework.data.mapping.callback.EntityCallbackInvoker {
|
||||
static class SimpleEntityCallbackInvoker implements org.springframework.data.mapping.callback.EntityCallbackInvoker {
|
||||
|
||||
@Override
|
||||
public <T> T invokeCallback(EntityCallback<T> callback, T entity,
|
||||
@@ -108,7 +108,7 @@ class DefaultEntityCallbacks implements EntityCallbacks {
|
||||
|
||||
try {
|
||||
|
||||
Object value = callbackInvokerFunction.apply(callback, entity);
|
||||
var value = callbackInvokerFunction.apply(callback, entity);
|
||||
|
||||
if (value != null) {
|
||||
return (T) value;
|
||||
@@ -119,12 +119,12 @@ class DefaultEntityCallbacks implements EntityCallbacks {
|
||||
|
||||
} catch (ClassCastException ex) {
|
||||
|
||||
String msg = ex.getMessage();
|
||||
var msg = ex.getMessage();
|
||||
if (msg == null || EntityCallbackInvoker.matchesClassCastMessage(msg, entity.getClass())) {
|
||||
|
||||
// Possibly a lambda-defined listener which we could not resolve the generic event type for
|
||||
// -> let's suppress the exception and just log a debug message.
|
||||
Log logger = LogFactory.getLog(getClass());
|
||||
var logger = LogFactory.getLog(getClass());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Non-matching callback type for entity callback: " + callback, ex);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -69,22 +69,22 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
|
||||
Class<T> entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
|
||||
var entityType = (Class<T>) (entity != null ? ClassUtils.getUserClass(entity.getClass())
|
||||
: callbackDiscoverer.resolveDeclaredEntityType(callbackType).getRawClass());
|
||||
|
||||
Method callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
|
||||
var callbackMethod = callbackMethodCache.computeIfAbsent(callbackType, it -> {
|
||||
|
||||
Method method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
|
||||
var method = EntityCallbackDiscoverer.lookupCallbackMethod(it, entityType, args);
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
return method;
|
||||
});
|
||||
|
||||
Mono<T> deferredCallbackChain = Mono.just(entity);
|
||||
var deferredCallbackChain = Mono.just(entity);
|
||||
|
||||
for (EntityCallback<T> callback : callbackDiscoverer.getEntityCallbacks(entityType,
|
||||
for (var callback : callbackDiscoverer.getEntityCallbacks(entityType,
|
||||
ResolvableType.forClass(callbackType))) {
|
||||
|
||||
BiFunction<EntityCallback<T>, T, Object> callbackFunction = EntityCallbackDiscoverer
|
||||
var callbackFunction = EntityCallbackDiscoverer
|
||||
.computeCallbackInvokerFunction(callback, callbackMethod, args);
|
||||
|
||||
deferredCallbackChain = deferredCallbackChain
|
||||
@@ -111,7 +111,7 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
|
||||
|
||||
try {
|
||||
|
||||
Object value = callbackInvokerFunction.apply(callback, entity);
|
||||
var value = callbackInvokerFunction.apply(callback, entity);
|
||||
|
||||
if (value != null) {
|
||||
return value instanceof Publisher ? Mono.from((Publisher<T>) value) : Mono.just((T) value);
|
||||
@@ -121,12 +121,12 @@ class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
|
||||
String.format("Callback invocation on %s returned null value for %s", callback.getClass(), entity));
|
||||
} catch (ClassCastException ex) {
|
||||
|
||||
String msg = ex.getMessage();
|
||||
var msg = ex.getMessage();
|
||||
if (msg == null || EntityCallbackInvoker.matchesClassCastMessage(msg, entity.getClass())) {
|
||||
|
||||
// Possibly a lambda-defined listener which we could not resolve the generic event type for
|
||||
// -> let's suppress the exception and just log a debug message.
|
||||
Log logger = LogFactory.getLog(getClass());
|
||||
var logger = LogFactory.getLog(getClass());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Non-matching callback type for entity callback: " + callback, ex);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class EntityCallbackDiscoverer {
|
||||
|
||||
// Explicitly remove target for a proxy, if registered already,
|
||||
// in order to avoid double invocations of the same callback.
|
||||
Object singletonTarget = AopProxyUtils.getSingletonTarget(callback);
|
||||
var singletonTarget = AopProxyUtils.getSingletonTarget(callback);
|
||||
if (singletonTarget instanceof EntityCallback) {
|
||||
this.defaultRetriever.entityCallbacks.remove(singletonTarget);
|
||||
}
|
||||
@@ -134,10 +134,10 @@ class EntityCallbackDiscoverer {
|
||||
<T extends S, S> Collection<EntityCallback<S>> getEntityCallbacks(Class<T> entity, ResolvableType callbackType) {
|
||||
|
||||
Class<?> sourceType = entity;
|
||||
CallbackCacheKey cacheKey = new CallbackCacheKey(callbackType, sourceType);
|
||||
var cacheKey = new CallbackCacheKey(callbackType, sourceType);
|
||||
|
||||
// Quick check for existing entry on ConcurrentHashMap...
|
||||
CallbackRetriever retriever = this.retrieverCache.get(cacheKey);
|
||||
var retriever = this.retrieverCache.get(cacheKey);
|
||||
if (retriever != null) {
|
||||
return (Collection<EntityCallback<S>>) (Collection) retriever.getEntityCallbacks();
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class EntityCallbackDiscoverer {
|
||||
return (Collection<EntityCallback<S>>) (Collection) retriever.getEntityCallbacks();
|
||||
}
|
||||
retriever = new CallbackRetriever(true);
|
||||
Collection<EntityCallback<?>> callbacks = retrieveEntityCallbacks(ResolvableType.forClass(sourceType),
|
||||
var callbacks = retrieveEntityCallbacks(ResolvableType.forClass(sourceType),
|
||||
callbackType, retriever);
|
||||
this.retrieverCache.put(cacheKey, retriever);
|
||||
return (Collection<EntityCallback<S>>) (Collection) callbacks;
|
||||
@@ -166,7 +166,7 @@ class EntityCallbackDiscoverer {
|
||||
@Nullable
|
||||
ResolvableType resolveDeclaredEntityType(Class<?> callbackType) {
|
||||
|
||||
ResolvableType eventType = entityTypeCache.get(callbackType);
|
||||
var eventType = entityTypeCache.get(callbackType);
|
||||
|
||||
if (eventType == null) {
|
||||
eventType = ResolvableType.forClass(callbackType).as(EntityCallback.class).getGeneric();
|
||||
@@ -196,7 +196,7 @@ class EntityCallbackDiscoverer {
|
||||
callbackBeans = new LinkedHashSet<>(this.defaultRetriever.entityCallbackBeans);
|
||||
}
|
||||
|
||||
for (EntityCallback<?> callback : callbacks) {
|
||||
for (var callback : callbacks) {
|
||||
if (supportsEvent(callback, entityType, callbackType)) {
|
||||
if (retriever != null) {
|
||||
retriever.getEntityCallbacks().add(callback);
|
||||
@@ -206,10 +206,10 @@ class EntityCallbackDiscoverer {
|
||||
}
|
||||
|
||||
if (!callbackBeans.isEmpty()) {
|
||||
BeanFactory beanFactory = getRequiredBeanFactory();
|
||||
for (String callbackBeanName : callbackBeans) {
|
||||
var beanFactory = getRequiredBeanFactory();
|
||||
for (var callbackBeanName : callbackBeans) {
|
||||
try {
|
||||
Class<?> callbackImplType = beanFactory.getType(callbackBeanName);
|
||||
var callbackImplType = beanFactory.getType(callbackBeanName);
|
||||
if (callbackImplType == null || supportsEvent(callbackImplType, entityType)) {
|
||||
EntityCallback<?> callback = beanFactory.getBean(callbackBeanName, EntityCallback.class);
|
||||
if (!allCallbacks.contains(callback) && supportsEvent(callback, entityType, callbackType)) {
|
||||
@@ -253,7 +253,7 @@ class EntityCallbackDiscoverer {
|
||||
*/
|
||||
protected boolean supportsEvent(Class<?> callback, ResolvableType entityType) {
|
||||
|
||||
ResolvableType declaredEventType = resolveDeclaredEntityType(callback);
|
||||
var declaredEventType = resolveDeclaredEntityType(callback);
|
||||
return (declaredEventType == null || declaredEventType.isAssignableFrom(entityType));
|
||||
}
|
||||
|
||||
@@ -291,8 +291,7 @@ class EntityCallbackDiscoverer {
|
||||
|
||||
this.beanFactory = beanFactory;
|
||||
|
||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
||||
ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;
|
||||
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||
if (this.beanClassLoader == null) {
|
||||
this.beanClassLoader = cbf.getBeanClassLoader();
|
||||
}
|
||||
@@ -332,7 +331,7 @@ class EntityCallbackDiscoverer {
|
||||
|
||||
return (entityCallback, entity) -> {
|
||||
|
||||
Object[] invocationArgs = new Object[args.length + 1];
|
||||
var invocationArgs = new Object[args.length + 1];
|
||||
invocationArgs[0] = entity;
|
||||
if (args.length > 0) {
|
||||
System.arraycopy(args, 0, invocationArgs, 1, args.length);
|
||||
@@ -372,8 +371,8 @@ class EntityCallbackDiscoverer {
|
||||
allCallbacks.addAll(this.entityCallbacks);
|
||||
|
||||
if (!this.entityCallbackBeans.isEmpty()) {
|
||||
BeanFactory beanFactory = getRequiredBeanFactory();
|
||||
for (String callbackBeanName : this.entityCallbackBeans) {
|
||||
var beanFactory = getRequiredBeanFactory();
|
||||
for (var callbackBeanName : this.entityCallbackBeans) {
|
||||
try {
|
||||
EntityCallback<?> callback = beanFactory.getBean(callbackBeanName, EntityCallback.class);
|
||||
if (this.preFiltered || !allCallbacks.contains(callback)) {
|
||||
@@ -427,7 +426,7 @@ class EntityCallbackDiscoverer {
|
||||
return true;
|
||||
}
|
||||
|
||||
CallbackCacheKey otherKey = (CallbackCacheKey) other;
|
||||
var otherKey = (CallbackCacheKey) other;
|
||||
|
||||
return (this.callbackType.equals(otherKey.callbackType)
|
||||
&& ObjectUtils.nullSafeEquals(this.entityType, otherKey.entityType));
|
||||
|
||||
@@ -48,7 +48,7 @@ interface EntityCallbackInvoker {
|
||||
}
|
||||
|
||||
// On Java 9, the message used to contain the module name: "java.base/java.lang.String cannot be cast..."
|
||||
int moduleSeparatorIndex = classCastMessage.indexOf('/');
|
||||
var moduleSeparatorIndex = classCastMessage.indexOf('/');
|
||||
if (moduleSeparatorIndex != -1 && classCastMessage.startsWith(eventClass.getName(), moduleSeparatorIndex + 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ public interface EntityCallbacks {
|
||||
*/
|
||||
static EntityCallbacks create(EntityCallback<?>... callbacks) {
|
||||
|
||||
EntityCallbacks entityCallbacks = create();
|
||||
for (EntityCallback<?> callback : callbacks) {
|
||||
var entityCallbacks = create();
|
||||
for (var callback : callbacks) {
|
||||
entityCallbacks.addEntityCallback(callback);
|
||||
}
|
||||
return entityCallbacks;
|
||||
|
||||
@@ -58,8 +58,8 @@ public interface ReactiveEntityCallbacks {
|
||||
*/
|
||||
static ReactiveEntityCallbacks create(EntityCallback<?>... callbacks) {
|
||||
|
||||
ReactiveEntityCallbacks entityCallbacks = create();
|
||||
for (EntityCallback<?> callback : callbacks) {
|
||||
var entityCallbacks = create();
|
||||
for (var callback : callbacks) {
|
||||
entityCallbacks.addEntityCallback(callback);
|
||||
}
|
||||
return entityCallbacks;
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.mapping.context;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -33,7 +32,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -114,8 +112,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
|
||||
|
||||
EntityInstantiators instantiators = new EntityInstantiators();
|
||||
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage()
|
||||
var instantiators = new EntityInstantiators();
|
||||
var accessorFactory = NativeDetector.inNativeImage()
|
||||
? BeanWrapperPropertyAccessorFactory.INSTANCE
|
||||
: new ClassGeneratingPropertyAccessorFactory();
|
||||
|
||||
@@ -218,7 +216,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
Optional<E> entity = persistentEntities.get(ClassTypeInformation.from(type));
|
||||
var entity = persistentEntities.get(ClassTypeInformation.from(type));
|
||||
|
||||
return entity == null ? false : entity.isPresent();
|
||||
}
|
||||
@@ -237,7 +235,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
read.lock();
|
||||
|
||||
Optional<E> entity = persistentEntities.get(type);
|
||||
var entity = persistentEntities.get(type);
|
||||
|
||||
if (entity != null) {
|
||||
return entity.orElse(null);
|
||||
@@ -280,7 +278,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
return null;
|
||||
}
|
||||
|
||||
TypeInformation<?> typeInfo = persistentProperty.getTypeInformation();
|
||||
var typeInfo = persistentProperty.getTypeInformation();
|
||||
return getPersistentEntity(typeInfo.getRequiredActualType());
|
||||
}
|
||||
|
||||
@@ -355,7 +353,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
read.lock();
|
||||
|
||||
Optional<E> persistentEntity = persistentEntities.get(typeInformation);
|
||||
var persistentEntity = persistentEntities.get(typeInformation);
|
||||
|
||||
if (persistentEntity != null) {
|
||||
return persistentEntity;
|
||||
@@ -400,9 +398,9 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
try {
|
||||
|
||||
Class<?> type = userTypeInformation.getType();
|
||||
var type = userTypeInformation.getType();
|
||||
|
||||
E entity = createPersistentEntity(userTypeInformation);
|
||||
var entity = createPersistentEntity(userTypeInformation);
|
||||
entity.setEvaluationContextProvider(evaluationContextProvider);
|
||||
|
||||
// Eagerly cache the entity as we might have to find it during recursive lookups.
|
||||
@@ -413,14 +411,14 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
persistentEntities.put(typeInformation, Optional.of(entity));
|
||||
}
|
||||
|
||||
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
|
||||
var pds = BeanUtils.getPropertyDescriptors(type);
|
||||
Map<String, PropertyDescriptor> descriptors = new HashMap<>();
|
||||
|
||||
for (PropertyDescriptor descriptor : pds) {
|
||||
for (var descriptor : pds) {
|
||||
descriptors.put(descriptor.getName(), descriptor);
|
||||
}
|
||||
|
||||
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
|
||||
var persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
|
||||
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
|
||||
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
|
||||
|
||||
@@ -544,12 +542,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
*/
|
||||
public void doWith(Field field) {
|
||||
|
||||
String fieldName = field.getName();
|
||||
TypeInformation<?> type = entity.getTypeInformation();
|
||||
var fieldName = field.getName();
|
||||
var type = entity.getTypeInformation();
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
Property property = Optional.ofNullable(descriptors.get(fieldName))//
|
||||
var property = Optional.ofNullable(descriptors.get(fieldName))//
|
||||
.map(it -> Property.of(type, field, it))//
|
||||
.orElseGet(() -> Property.of(type, field));
|
||||
|
||||
@@ -575,7 +573,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
private void createAndRegisterProperty(Property input) {
|
||||
|
||||
P property = createPersistentProperty(input, entity, simpleTypeHolder);
|
||||
var property = createPersistentProperty(input, entity, simpleTypeHolder);
|
||||
|
||||
if (property.isTransient()) {
|
||||
return;
|
||||
@@ -609,17 +607,17 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
protected boolean shouldSkipOverrideProperty(P property) {
|
||||
|
||||
P existingProperty = entity.getPersistentProperty(property.getName());
|
||||
var existingProperty = entity.getPersistentProperty(property.getName());
|
||||
|
||||
if (existingProperty == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?> declaringClass = getDeclaringClass(property);
|
||||
Class<?> existingDeclaringClass = getDeclaringClass(existingProperty);
|
||||
var declaringClass = getDeclaringClass(property);
|
||||
var existingDeclaringClass = getDeclaringClass(existingProperty);
|
||||
|
||||
Class<?> propertyType = getPropertyType(property);
|
||||
Class<?> existingPropertyType = getPropertyType(existingProperty);
|
||||
var propertyType = getPropertyType(property);
|
||||
var existingPropertyType = getPropertyType(existingProperty);
|
||||
|
||||
if (!propertyType.isAssignableFrom(existingPropertyType)) {
|
||||
|
||||
@@ -638,12 +636,12 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
private Class<?> getDeclaringClass(PersistentProperty<?> persistentProperty) {
|
||||
|
||||
Field field = persistentProperty.getField();
|
||||
var field = persistentProperty.getField();
|
||||
if (field != null) {
|
||||
return field.getDeclaringClass();
|
||||
}
|
||||
|
||||
Method accessor = persistentProperty.getGetter();
|
||||
var accessor = persistentProperty.getGetter();
|
||||
|
||||
if (accessor == null) {
|
||||
accessor = persistentProperty.getSetter();
|
||||
@@ -662,22 +660,22 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
private Class<?> getPropertyType(PersistentProperty<?> persistentProperty) {
|
||||
|
||||
Field field = persistentProperty.getField();
|
||||
var field = persistentProperty.getField();
|
||||
if (field != null) {
|
||||
return field.getType();
|
||||
}
|
||||
|
||||
Method getter = persistentProperty.getGetter();
|
||||
var getter = persistentProperty.getGetter();
|
||||
if (getter != null) {
|
||||
return getter.getReturnType();
|
||||
}
|
||||
|
||||
Method setter = persistentProperty.getSetter();
|
||||
var setter = persistentProperty.getSetter();
|
||||
if (setter != null) {
|
||||
return setter.getParameterTypes()[0];
|
||||
}
|
||||
|
||||
Method wither = persistentProperty.getWither();
|
||||
var wither = persistentProperty.getWither();
|
||||
if (wither != null) {
|
||||
return wither.getParameterTypes()[0];
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
|
||||
}
|
||||
|
||||
@SuppressWarnings("null")
|
||||
Class<?> leafPropertyType = getLeafProperty().getActualType();
|
||||
var leafPropertyType = getLeafProperty().getActualType();
|
||||
|
||||
Assert.isTrue(property.getOwner().getType().equals(leafPropertyType),
|
||||
() -> String.format("Cannot append property %s to type %s!", property.getName(), leafPropertyType.getName()));
|
||||
@@ -128,7 +128,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
|
||||
Assert.hasText(delimiter, "Delimiter must not be null or empty!");
|
||||
Assert.notNull(converter, "Converter must not be null!");
|
||||
|
||||
String result = properties.stream() //
|
||||
var result = properties.stream() //
|
||||
.map(converter::convert) //
|
||||
.filter(StringUtils::hasText) //
|
||||
.collect(Collectors.joining(delimiter));
|
||||
@@ -162,15 +162,15 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
|
||||
|
||||
Assert.notNull(path, "PersistentPropertyPath must not be null!");
|
||||
|
||||
Iterator<P> iterator = path.iterator();
|
||||
var iterator = path.iterator();
|
||||
|
||||
for (P property : this) {
|
||||
for (var property : this) {
|
||||
|
||||
if (!iterator.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
P reference = iterator.next();
|
||||
var reference = iterator.next();
|
||||
|
||||
if (!property.equals(reference)) {
|
||||
return false;
|
||||
@@ -191,9 +191,9 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
|
||||
}
|
||||
|
||||
List<P> result = new ArrayList<>();
|
||||
Iterator<P> iterator = iterator();
|
||||
var iterator = iterator();
|
||||
|
||||
for (int i = 0; i < base.getLength(); i++) {
|
||||
for (var i = 0; i < base.getLength(); i++) {
|
||||
iterator.next();
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
|
||||
*/
|
||||
public PersistentPropertyPath<P> getParentPath() {
|
||||
|
||||
int size = properties.size();
|
||||
var size = properties.size();
|
||||
|
||||
return size == 0 ? this : new DefaultPersistentPropertyPath<>(properties.subList(0, size - 1));
|
||||
}
|
||||
@@ -256,11 +256,10 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof DefaultPersistentPropertyPath)) {
|
||||
if (!(o instanceof DefaultPersistentPropertyPath<?> that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DefaultPersistentPropertyPath<?> that = (DefaultPersistentPropertyPath<?>) o;
|
||||
return ObjectUtils.nullSafeEquals(properties, that.properties);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,14 +109,14 @@ public class InvalidPersistentPropertyPath extends MappingException {
|
||||
return "";
|
||||
}
|
||||
|
||||
String dotPath = path.toDotPath();
|
||||
var dotPath = path.toDotPath();
|
||||
|
||||
return dotPath == null ? "" : dotPath;
|
||||
}
|
||||
|
||||
private static String createMessage(TypeInformation<?> type, String unresolvableSegment) {
|
||||
|
||||
Set<String> potentialMatches = detectPotentialMatches(unresolvableSegment, type.getType());
|
||||
var potentialMatches = detectPotentialMatches(unresolvableSegment, type.getType());
|
||||
Object match = StringUtils.collectionToCommaDelimitedString(potentialMatches);
|
||||
|
||||
return String.format(DEFAULT_MESSAGE, unresolvableSegment, type.getType(), match);
|
||||
|
||||
@@ -70,7 +70,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
|
||||
*/
|
||||
default E getRequiredPersistentEntity(Class<?> type) throws MappingException {
|
||||
|
||||
E entity = getPersistentEntity(type);
|
||||
var entity = getPersistentEntity(type);
|
||||
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
@@ -110,7 +110,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
|
||||
*/
|
||||
default E getRequiredPersistentEntity(TypeInformation<?> type) throws MappingException {
|
||||
|
||||
E entity = getPersistentEntity(type);
|
||||
var entity = getPersistentEntity(type);
|
||||
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
@@ -143,7 +143,7 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
|
||||
*/
|
||||
default E getRequiredPersistentEntity(P persistentProperty) throws MappingException {
|
||||
|
||||
E entity = getPersistentEntity(persistentProperty);
|
||||
var entity = getPersistentEntity(persistentProperty);
|
||||
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
|
||||
@@ -196,13 +196,13 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
|
||||
@Nullable
|
||||
public PersistentEntity<?, ?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property) {
|
||||
|
||||
TypeInformation<?> propertyType = property.getTypeInformation().getActualType();
|
||||
var propertyType = property.getTypeInformation().getActualType();
|
||||
|
||||
if (propertyType == null || !property.isAssociation()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class<?> associationTargetType = property.getAssociationTargetType();
|
||||
var associationTargetType = property.getAssociationTargetType();
|
||||
|
||||
return associationTargetType == null //
|
||||
? getEntityIdentifiedBy(propertyType) //
|
||||
@@ -220,7 +220,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
|
||||
|
||||
Assert.notNull(property, "PersistentProperty must not be null!");
|
||||
|
||||
PersistentEntity<?, ?> entity = getEntityUltimatelyReferredToBy(property);
|
||||
var entity = getEntityUltimatelyReferredToBy(property);
|
||||
|
||||
return entity == null //
|
||||
? property.getTypeInformation().getRequiredActualType() //
|
||||
@@ -238,16 +238,24 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
|
||||
@Nullable
|
||||
private PersistentEntity<?, ?> getEntityIdentifiedBy(TypeInformation<?> type) {
|
||||
|
||||
Collection<PersistentEntity<?, ?>> entities = contexts.stream() //
|
||||
.flatMap(it -> it.getPersistentEntities().stream()) //
|
||||
.map(PersistentEntity::getIdProperty) //
|
||||
.filter(it -> it != null && type.equals(it.getTypeInformation().getActualType())) //
|
||||
.map(PersistentProperty::getOwner) //
|
||||
.collect(Collectors.toList());
|
||||
Collection<PersistentEntity<?, ?>> entities = new ArrayList<>();
|
||||
for (MappingContext<?, ? extends PersistentProperty<?>> context : contexts) {
|
||||
|
||||
for (PersistentEntity<?, ? extends PersistentProperty<?>> persistentProperties : context
|
||||
.getPersistentEntities()) {
|
||||
|
||||
var idProperty = persistentProperties.getIdProperty();
|
||||
|
||||
if (idProperty != null && type.equals(idProperty.getTypeInformation().getActualType())) {
|
||||
var owner = idProperty.getOwner();
|
||||
entities.add(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entities.size() > 1) {
|
||||
|
||||
String message = "Found multiple entities identified by " + type.getType() + ": ";
|
||||
var message = "Found multiple entities identified by " + type.getType() + ": ";
|
||||
message += entities.stream().map(it -> it.getType().getName()).collect(Collectors.joining(", "));
|
||||
message += "! Introduce dedicated unique identifier types or explicitly define the target type in @Reference!";
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -181,26 +180,26 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
*/
|
||||
private PersistentPropertyPath<P> createPersistentPropertyPath(String propertyPath, TypeInformation<?> type) {
|
||||
|
||||
String trimmedPath = propertyPath.trim();
|
||||
var trimmedPath = propertyPath.trim();
|
||||
|
||||
List<String> parts = trimmedPath.isEmpty() //
|
||||
? Collections.emptyList() //
|
||||
: Arrays.asList(trimmedPath.split("\\."));
|
||||
|
||||
DefaultPersistentPropertyPath<P> path = DefaultPersistentPropertyPath.empty();
|
||||
Iterator<String> iterator = parts.iterator();
|
||||
E current = context.getRequiredPersistentEntity(type);
|
||||
var iterator = parts.iterator();
|
||||
var current = context.getRequiredPersistentEntity(type);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
String segment = iterator.next();
|
||||
final DefaultPersistentPropertyPath<P> currentPath = path;
|
||||
var segment = iterator.next();
|
||||
final var currentPath = path;
|
||||
|
||||
Pair<DefaultPersistentPropertyPath<P>, E> pair = getPair(path, iterator, segment, current);
|
||||
var pair = getPair(path, iterator, segment, current);
|
||||
|
||||
if (pair == null) {
|
||||
|
||||
String source = StringUtils.collectionToDelimitedString(parts, ".");
|
||||
var source = StringUtils.collectionToDelimitedString(parts, ".");
|
||||
|
||||
throw new InvalidPersistentPropertyPath(source, type, segment, currentPath);
|
||||
}
|
||||
@@ -216,7 +215,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
private Pair<DefaultPersistentPropertyPath<P>, E> getPair(DefaultPersistentPropertyPath<P> path,
|
||||
Iterator<String> iterator, String segment, E entity) {
|
||||
|
||||
P property = entity.getPersistentProperty(segment);
|
||||
var property = entity.getPersistentProperty(segment);
|
||||
|
||||
if (property == null) {
|
||||
return null;
|
||||
@@ -228,13 +227,13 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
private <T> Collection<PersistentPropertyPath<P>> from(TypeInformation<T> type, Predicate<? super P> filter,
|
||||
Predicate<P> traversalGuard, DefaultPersistentPropertyPath<P> basePath) {
|
||||
|
||||
TypeInformation<?> actualType = type.getActualType();
|
||||
var actualType = type.getActualType();
|
||||
|
||||
if (actualType == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
E entity = context.getRequiredPersistentEntity(actualType);
|
||||
var entity = context.getRequiredPersistentEntity(actualType);
|
||||
return from(entity, filter, traversalGuard, basePath);
|
||||
}
|
||||
|
||||
@@ -243,16 +242,16 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
|
||||
Set<PersistentPropertyPath<P>> properties = new HashSet<>();
|
||||
|
||||
PropertyHandler<P> propertyTester = persistentProperty -> {
|
||||
var propertyTester = (PropertyHandler<P>) persistentProperty -> {
|
||||
|
||||
TypeInformation<?> typeInformation = persistentProperty.getTypeInformation();
|
||||
TypeInformation<?> actualPropertyType = typeInformation.getActualType();
|
||||
var typeInformation = persistentProperty.getTypeInformation();
|
||||
var actualPropertyType = typeInformation.getActualType();
|
||||
|
||||
if (basePath.containsPropertyOfType(actualPropertyType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultPersistentPropertyPath<P> currentPath = basePath.append(persistentProperty);
|
||||
var currentPath = basePath.append(persistentProperty);
|
||||
|
||||
if (filter.test(persistentProperty)) {
|
||||
properties.add(currentPath);
|
||||
@@ -265,7 +264,8 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
|
||||
entity.doWithProperties(propertyTester);
|
||||
|
||||
AssociationHandler<P> handler = association -> propertyTester.doWithPersistentProperty(association.getInverse());
|
||||
var handler = (AssociationHandler<P>) association -> propertyTester
|
||||
.doWithPersistentProperty(association.getInverse());
|
||||
entity.doWithAssociations(handler);
|
||||
|
||||
return properties;
|
||||
@@ -304,12 +304,10 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof TypeAndPath)) {
|
||||
if (!(o instanceof TypeAndPath that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeAndPath that = (TypeAndPath) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(type, that.type)) {
|
||||
return false;
|
||||
}
|
||||
@@ -323,7 +321,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(type);
|
||||
var result = ObjectUtils.nullSafeHashCode(type);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(path);
|
||||
return result;
|
||||
}
|
||||
@@ -364,7 +362,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
|
||||
List<PersistentPropertyPath<P>> sorted = new ArrayList<>(paths);
|
||||
|
||||
Collections.sort(sorted, SHORTEST_PATH.thenComparing(ShortestSegmentFirst.INSTANCE));
|
||||
sorted.sort(SHORTEST_PATH.thenComparing(ShortestSegmentFirst.INSTANCE));
|
||||
|
||||
return new DefaultPersistentPropertyPaths<>(type, sorted);
|
||||
}
|
||||
@@ -400,7 +398,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
return false;
|
||||
}
|
||||
|
||||
String dotPath = path.toDotPath();
|
||||
var dotPath = path.toDotPath();
|
||||
|
||||
return stream().anyMatch(it -> dotPath.equals(it.toDotPath()));
|
||||
}
|
||||
@@ -423,7 +421,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null!");
|
||||
|
||||
List<PersistentPropertyPath<P>> paths = this.stream() //
|
||||
var paths = this.stream() //
|
||||
.filter(it -> !it.stream().anyMatch(predicate)) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -456,10 +454,10 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
|
||||
@SuppressWarnings("null")
|
||||
public int compare(PersistentPropertyPath<?> left, PersistentPropertyPath<?> right) {
|
||||
|
||||
Function<PersistentProperty<?>, Integer> mapper = it -> it.getName().length();
|
||||
var mapper = (Function<PersistentProperty<?>, Integer>) it -> it.getName().length();
|
||||
|
||||
Stream<Integer> leftNames = left.stream().map(mapper);
|
||||
Stream<Integer> rightNames = right.stream().map(mapper);
|
||||
var leftNames = left.stream().map(mapper);
|
||||
var rightNames = right.stream().map(mapper);
|
||||
|
||||
return StreamUtils.zip(leftNames, rightNames, (l, r) -> l - r) //
|
||||
.filter(it -> it != 0) //
|
||||
|
||||
@@ -279,7 +279,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
@Override
|
||||
public Class<?> getAssociationTargetType() {
|
||||
|
||||
TypeInformation<?> result = getAssociationTargetTypeInformation();
|
||||
var result = getAssociationTargetTypeInformation();
|
||||
|
||||
return result != null ? result.getType() : null;
|
||||
}
|
||||
@@ -350,7 +350,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
|
||||
if (isMap()) {
|
||||
|
||||
TypeInformation<?> mapValueType = information.getMapValueType();
|
||||
var mapValueType = information.getMapValueType();
|
||||
|
||||
if (mapValueType != null) {
|
||||
return mapValueType.getType();
|
||||
@@ -383,7 +383,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
|
||||
protected TypeInformation<?> getActualTypeInformation() {
|
||||
|
||||
TypeInformation<?> targetType = associationTargetType.getNullable();
|
||||
var targetType = associationTargetType.getNullable();
|
||||
return targetType == null ? information.getRequiredActualType() : targetType;
|
||||
}
|
||||
|
||||
@@ -398,12 +398,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof AbstractPersistentProperty)) {
|
||||
if (!(obj instanceof AbstractPersistentProperty<?> that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractPersistentProperty<?> that = (AbstractPersistentProperty<?>) obj;
|
||||
|
||||
return this.property.equals(that.property);
|
||||
}
|
||||
|
||||
@@ -427,10 +425,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
|
||||
private Set<TypeInformation<?>> detectEntityTypes(SimpleTypeHolder simpleTypes) {
|
||||
|
||||
TypeInformation<?> typeToStartWith = getAssociationTargetTypeInformation();
|
||||
var typeToStartWith = getAssociationTargetTypeInformation();
|
||||
typeToStartWith = typeToStartWith == null ? information : typeToStartWith;
|
||||
|
||||
Set<TypeInformation<?>> result = detectEntityTypes(typeToStartWith);
|
||||
var result = detectEntityTypes(typeToStartWith);
|
||||
|
||||
return result.stream()
|
||||
.filter(it -> !simpleTypes.isSimpleType(it.getType()))
|
||||
@@ -450,7 +448,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
result.addAll(detectEntityTypes(source.getComponentType()));
|
||||
}
|
||||
|
||||
TypeInformation<?> actualType = source.getActualType();
|
||||
var actualType = source.getActualType();
|
||||
|
||||
if (source.equals(actualType)) {
|
||||
result.add(source);
|
||||
|
||||
@@ -64,7 +64,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
|
||||
private final Lazy<Boolean> usePropertyAccess = Lazy.of(() -> {
|
||||
|
||||
AccessType accessType = findPropertyOrOwnerAnnotation(AccessType.class);
|
||||
var accessType = findPropertyOrOwnerAnnotation(AccessType.class);
|
||||
|
||||
return accessType != null && Type.PROPERTY.equals(accessType.value()) || super.usePropertyAccess();
|
||||
});
|
||||
@@ -105,7 +105,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
|
||||
populateAnnotationCache(property);
|
||||
|
||||
Value value = findAnnotation(Value.class);
|
||||
var value = findAnnotation(Value.class);
|
||||
|
||||
this.value = value == null ? null : value.value();
|
||||
}
|
||||
@@ -121,11 +121,11 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
|
||||
Optionals.toStream(property.getGetter(), property.getSetter()).forEach(it -> {
|
||||
|
||||
for (Annotation annotation : it.getAnnotations()) {
|
||||
for (var annotation : it.getAnnotations()) {
|
||||
|
||||
Class<? extends Annotation> annotationType = annotation.annotationType();
|
||||
var annotationType = annotation.annotationType();
|
||||
|
||||
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
|
||||
var mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
|
||||
|
||||
validateAnnotation(mergedAnnotation,
|
||||
"Ambiguous mapping! Annotation %s configured "
|
||||
@@ -139,10 +139,10 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
|
||||
property.getField().ifPresent(it -> {
|
||||
|
||||
for (Annotation annotation : it.getAnnotations()) {
|
||||
for (var annotation : it.getAnnotations()) {
|
||||
|
||||
Class<? extends Annotation> annotationType = annotation.annotationType();
|
||||
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
|
||||
var annotationType = annotation.annotationType();
|
||||
var mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType);
|
||||
|
||||
validateAnnotation(mergedAnnotation,
|
||||
"Ambiguous mapping! Annotation %s configured " + "on field %s and one of its accessor methods in class %s!",
|
||||
@@ -164,7 +164,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
*/
|
||||
private void validateAnnotation(Annotation candidate, String message, Object... arguments) {
|
||||
|
||||
Class<? extends Annotation> annotationType = candidate.annotationType();
|
||||
var annotationType = candidate.annotationType();
|
||||
|
||||
if (!annotationType.getName().startsWith(SPRING_DATA_PACKAGE)) {
|
||||
return;
|
||||
@@ -251,7 +251,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
@SuppressWarnings("unchecked")
|
||||
private <A extends Annotation> Optional<A> doFindAnnotation(Class<A> annotationType) {
|
||||
|
||||
Optional<? extends Annotation> annotation = annotationCache.get(annotationType);
|
||||
var annotation = annotationCache.get(annotationType);
|
||||
|
||||
if (annotation != null) {
|
||||
return (Optional<A>) annotation;
|
||||
@@ -274,7 +274,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
@Override
|
||||
public <A extends Annotation> A findPropertyOrOwnerAnnotation(Class<A> annotationType) {
|
||||
|
||||
A annotation = findAnnotation(annotationType);
|
||||
var annotation = findAnnotation(annotationType);
|
||||
|
||||
return annotation != null ? annotation : getOwner().findAnnotation(annotationType);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
populateAnnotationCache(getProperty());
|
||||
}
|
||||
|
||||
String builder = annotationCache.values().stream() //
|
||||
var builder = annotationCache.values().stream() //
|
||||
.flatMap(Optionals::toStream) //
|
||||
.map(Object::toString) //
|
||||
.collect(Collectors.joining(" "));
|
||||
|
||||
@@ -222,7 +222,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
propertyCache.computeIfAbsent(property.getName(), key -> property);
|
||||
|
||||
P candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property);
|
||||
var candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property);
|
||||
|
||||
if (candidate != null) {
|
||||
this.idProperty = candidate;
|
||||
@@ -230,7 +230,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
if (property.isVersionProperty()) {
|
||||
|
||||
P versionProperty = this.versionProperty;
|
||||
var versionProperty = this.versionProperty;
|
||||
|
||||
if (versionProperty != null) {
|
||||
|
||||
@@ -267,7 +267,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
return null;
|
||||
}
|
||||
|
||||
P idProperty = this.idProperty;
|
||||
var idProperty = this.idProperty;
|
||||
|
||||
if (idProperty != null) {
|
||||
throw new MappingException(String.format("Attempt to add id property %s but already have property %s registered "
|
||||
@@ -311,7 +311,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
private List<P> doFindPersistentProperty(Class<? extends Annotation> annotationType) {
|
||||
|
||||
List<P> annotatedProperties = properties.stream() //
|
||||
var annotatedProperties = properties.stream() //
|
||||
.filter(it -> it.isAnnotationPresent(annotationType)) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -356,7 +356,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
Assert.notNull(handler, "PropertyHandler must not be null!");
|
||||
|
||||
for (P property : persistentPropertiesCache) {
|
||||
for (var property : persistentPropertiesCache) {
|
||||
handler.doWithPersistentProperty(property);
|
||||
}
|
||||
}
|
||||
@@ -383,7 +383,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
Assert.notNull(handler, "Handler must not be null!");
|
||||
|
||||
for (Association<P> association : associations) {
|
||||
for (var association : associations) {
|
||||
handler.doWithAssociation(association);
|
||||
}
|
||||
}
|
||||
@@ -522,7 +522,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
@Override
|
||||
public Iterator<P> iterator() {
|
||||
|
||||
Iterator<P> iterator = properties.iterator();
|
||||
var iterator = properties.iterator();
|
||||
|
||||
return new Iterator<P>() {
|
||||
|
||||
@@ -593,12 +593,13 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
*/
|
||||
private static Alias getAliasFromAnnotation(Class<?> type) {
|
||||
|
||||
Optional<String> typeAliasValue = Optional
|
||||
.ofNullable(AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class))//
|
||||
.map(TypeAlias::value)//
|
||||
.filter(StringUtils::hasText);
|
||||
var typeAlias = AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class);
|
||||
|
||||
return Alias.ofNullable(typeAliasValue.orElse(null));
|
||||
if (typeAlias != null && StringUtils.hasText(typeAlias.value())) {
|
||||
return Alias.of(typeAlias.value());
|
||||
}
|
||||
|
||||
return Alias.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,10 +19,7 @@ import kotlin.reflect.KCallable;
|
||||
import kotlin.reflect.KParameter;
|
||||
import kotlin.reflect.KParameter.Kind;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
@@ -68,7 +65,7 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
|
||||
|
||||
if (property.isImmutable()) {
|
||||
|
||||
Method wither = property.getWither();
|
||||
var wither = property.getWither();
|
||||
|
||||
if (wither != null) {
|
||||
|
||||
@@ -89,14 +86,14 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
|
||||
|
||||
if (!property.usePropertyAccess()) {
|
||||
|
||||
Field field = property.getRequiredField();
|
||||
var field = property.getRequiredField();
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
ReflectionUtils.setField(field, bean, value);
|
||||
return;
|
||||
}
|
||||
|
||||
Method setter = property.getRequiredSetter();
|
||||
var setter = property.getRequiredSetter();
|
||||
|
||||
ReflectionUtils.makeAccessible(setter);
|
||||
ReflectionUtils.invokeMethod(setter, bean, value);
|
||||
@@ -133,13 +130,13 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
|
||||
|
||||
if (!property.usePropertyAccess()) {
|
||||
|
||||
Field field = property.getRequiredField();
|
||||
var field = property.getRequiredField();
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
return ReflectionUtils.getField(field, bean);
|
||||
}
|
||||
|
||||
Method getter = property.getRequiredGetter();
|
||||
var getter = property.getRequiredGetter();
|
||||
|
||||
ReflectionUtils.makeAccessible(getter);
|
||||
return ReflectionUtils.invokeMethod(getter, bean);
|
||||
@@ -175,8 +172,8 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
|
||||
*/
|
||||
static <T> Object setProperty(PersistentProperty<?> property, T bean, @Nullable Object value) {
|
||||
|
||||
Class<?> type = property.getOwner().getType();
|
||||
KCallable<?> copy = copyMethodCache.computeIfAbsent(type, it -> getCopyMethod(it, property));
|
||||
var type = property.getOwner().getType();
|
||||
var copy = copyMethodCache.computeIfAbsent(type, it -> getCopyMethod(it, property));
|
||||
|
||||
if (copy == null) {
|
||||
throw new UnsupportedOperationException(String.format(
|
||||
@@ -191,9 +188,9 @@ class BeanWrapper<T> implements PersistentPropertyAccessor<T> {
|
||||
|
||||
Map<KParameter, Object> args = new LinkedHashMap<>(2, 1);
|
||||
|
||||
List<KParameter> parameters = callable.getParameters();
|
||||
var parameters = callable.getParameters();
|
||||
|
||||
for (KParameter parameter : parameters) {
|
||||
for (var parameter : parameters) {
|
||||
|
||||
if (parameter.getKind() == Kind.INSTANCE) {
|
||||
args.put(parameter, bean);
|
||||
|
||||
@@ -52,12 +52,12 @@ public class CamelCaseSplittingFieldNamingStrategy implements FieldNamingStrateg
|
||||
@Override
|
||||
public String getFieldName(PersistentProperty<?> property) {
|
||||
|
||||
List<String> parts = ParsingUtils.splitCamelCaseToLower(property.getName());
|
||||
var parts = ParsingUtils.splitCamelCaseToLower(property.getName());
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
for (String part : parts) {
|
||||
for (var part : parts) {
|
||||
|
||||
String candidate = preparePart(part);
|
||||
var candidate = preparePart(part);
|
||||
|
||||
if (StringUtils.hasText(candidate)) {
|
||||
result.add(candidate);
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.mapping.model;
|
||||
|
||||
import static org.springframework.asm.Opcodes.*;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -80,7 +79,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
|
||||
ParameterValueProvider<P> provider) {
|
||||
|
||||
EntityInstantiator instantiator = this.entityInstantiators.get(entity.getTypeInformation());
|
||||
var instantiator = this.entityInstantiators.get(entity.getTypeInformation());
|
||||
|
||||
if (instantiator == null) {
|
||||
instantiator = potentiallyCreateAndRegisterEntityInstantiator(entity);
|
||||
@@ -96,8 +95,8 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
private synchronized EntityInstantiator potentiallyCreateAndRegisterEntityInstantiator(
|
||||
PersistentEntity<?, ?> entity) {
|
||||
|
||||
Map<TypeInformation<?>, EntityInstantiator> map = this.entityInstantiators;
|
||||
EntityInstantiator instantiator = map.get(entity.getTypeInformation());
|
||||
var map = this.entityInstantiators;
|
||||
var instantiator = map.get(entity.getTypeInformation());
|
||||
|
||||
if (instantiator != null) {
|
||||
return instantiator;
|
||||
@@ -164,7 +163,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
return true;
|
||||
}
|
||||
|
||||
Class<?> type = entity.getType();
|
||||
var type = entity.getType();
|
||||
|
||||
if (type.isInterface() //
|
||||
|| type.isArray() //
|
||||
@@ -174,7 +173,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
return true;
|
||||
}
|
||||
|
||||
PreferredConstructor<?, ?> persistenceConstructor = entity.getPersistenceConstructor();
|
||||
var persistenceConstructor = entity.getPersistenceConstructor();
|
||||
if (persistenceConstructor == null || Modifier.isPrivate(persistenceConstructor.getConstructor().getModifiers())) {
|
||||
return true;
|
||||
}
|
||||
@@ -245,7 +244,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
|
||||
ParameterValueProvider<P> provider) {
|
||||
|
||||
Object[] params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
|
||||
var params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
|
||||
|
||||
try {
|
||||
return (T) instantiator.newInstance(params);
|
||||
@@ -269,9 +268,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
return allocateArguments(0);
|
||||
}
|
||||
|
||||
Object[] params = allocateArguments(constructor.getConstructor().getParameterCount());
|
||||
var params = allocateArguments(constructor.getConstructor().getParameterCount());
|
||||
|
||||
int index = 0;
|
||||
var index = 0;
|
||||
for (Parameter<?, P> parameter : constructor.getParameters()) {
|
||||
params[index++] = provider.getParameterValue(parameter);
|
||||
}
|
||||
@@ -316,7 +315,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
|
||||
ParameterValueProvider<P> provider) {
|
||||
|
||||
Object[] params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
|
||||
var params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
|
||||
|
||||
throw new MappingInstantiationException(entity, Arrays.asList(params),
|
||||
new BeanInstantiationException(typeToCreate, "Class is abstract"));
|
||||
@@ -382,9 +381,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
public Class<?> generateCustomInstantiatorClass(PersistentEntity<?, ?> entity,
|
||||
@Nullable PreferredConstructor<?, ?> constructor) {
|
||||
|
||||
String className = generateClassName(entity);
|
||||
Class<?> type = entity.getType();
|
||||
ClassLoader classLoader = type.getClassLoader();
|
||||
var className = generateClassName(entity);
|
||||
var type = entity.getType();
|
||||
var classLoader = type.getClassLoader();
|
||||
|
||||
if (ClassUtils.isPresent(className, classLoader)) {
|
||||
|
||||
@@ -395,7 +394,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] bytecode = generateBytecode(className, entity, constructor);
|
||||
var bytecode = generateBytecode(className, entity, constructor);
|
||||
|
||||
try {
|
||||
return ReflectUtils.defineClass(className, bytecode, classLoader, type.getProtectionDomain(), type);
|
||||
@@ -423,7 +422,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
public byte[] generateBytecode(String internalClassName, PersistentEntity<?, ?> entity,
|
||||
@Nullable PreferredConstructor<?, ?> constructor) {
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
cw.visit(Opcodes.V1_6, ACC_PUBLIC + ACC_SUPER, internalClassName.replace('.', '/'), null, JAVA_LANG_OBJECT,
|
||||
IMPLEMENTED_INTERFACES);
|
||||
@@ -439,7 +438,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
|
||||
private void visitDefaultConstructor(ClassWriter cw) {
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
|
||||
var mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false);
|
||||
@@ -458,9 +457,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
private void visitCreateMethod(ClassWriter cw, PersistentEntity<?, ?> entity,
|
||||
@Nullable PreferredConstructor<?, ?> constructor) {
|
||||
|
||||
String entityTypeResourcePath = Type.getInternalName(entity.getType());
|
||||
var entityTypeResourcePath = Type.getInternalName(entity.getType());
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
|
||||
var mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
|
||||
"([Ljava/lang/Object;)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitTypeInsn(NEW, entityTypeResourcePath);
|
||||
@@ -468,11 +467,11 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
|
||||
if (constructor != null) {
|
||||
|
||||
Constructor<?> ctor = constructor.getConstructor();
|
||||
Class<?>[] parameterTypes = ctor.getParameterTypes();
|
||||
var ctor = constructor.getConstructor();
|
||||
var parameterTypes = ctor.getParameterTypes();
|
||||
List<? extends Parameter<Object, ?>> parameters = constructor.getParameters();
|
||||
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
for (var i = 0; i < parameterTypes.length; i++) {
|
||||
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
|
||||
@@ -483,7 +482,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
if (parameterTypes[i].isPrimitive()) {
|
||||
|
||||
mv.visitInsn(DUP);
|
||||
String parameterName = parameters.size() > i ? parameters.get(i).getName() : null;
|
||||
var parameterName = parameters.size() > i ? parameters.get(i).getName() : null;
|
||||
|
||||
insertAssertNotNull(mv, parameterName == null ? String.format("at index %d", i) : parameterName);
|
||||
insertUnboxInsns(mv, Type.getType(parameterTypes[i]).toString().charAt(0), "");
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.SimpleAssociationHandler;
|
||||
import org.springframework.data.mapping.SimplePropertyHandler;
|
||||
import org.springframework.data.mapping.model.KotlinCopyMethod.KotlinCopyByProperty;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -83,11 +82,11 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
@Override
|
||||
public <T> PersistentPropertyAccessor<T> getPropertyAccessor(PersistentEntity<?, ?> entity, T bean) {
|
||||
|
||||
Constructor<?> constructor = constructorMap.get(entity);
|
||||
var constructor = constructorMap.get(entity);
|
||||
|
||||
if (constructor == null) {
|
||||
|
||||
Class<PersistentPropertyAccessor<?>> accessorClass = potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
|
||||
var accessorClass = potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
|
||||
entity);
|
||||
constructor = accessorClass.getConstructors()[0];
|
||||
|
||||
@@ -96,7 +95,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
this.constructorMap = constructorMap;
|
||||
}
|
||||
|
||||
Object[] args = argumentCache.get();
|
||||
var args = argumentCache.get();
|
||||
args[0] = bean;
|
||||
|
||||
try {
|
||||
@@ -136,7 +135,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
private static boolean isTypeInjectable(PersistentEntity<?, ?> entity) {
|
||||
|
||||
Class<?> type = entity.getType();
|
||||
var type = entity.getType();
|
||||
return type.getClassLoader() != null
|
||||
&& (type.getPackage() == null || !type.getPackage().getName().startsWith("java"))
|
||||
&& ClassUtils.isPresent(PersistentPropertyAccessor.class.getName(), type.getClassLoader())
|
||||
@@ -146,7 +145,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private boolean hasUniquePropertyHashCodes(PersistentEntity<?, ?> entity) {
|
||||
|
||||
Set<Integer> hashCodes = new HashSet<>();
|
||||
AtomicInteger propertyCount = new AtomicInteger();
|
||||
var propertyCount = new AtomicInteger();
|
||||
|
||||
entity.doWithProperties((SimplePropertyHandler) property -> {
|
||||
|
||||
@@ -172,8 +171,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private synchronized Class<PersistentPropertyAccessor<?>> potentiallyCreateAndRegisterPersistentPropertyAccessorClass(
|
||||
PersistentEntity<?, ?> entity) {
|
||||
|
||||
Map<TypeInformation<?>, Class<PersistentPropertyAccessor<?>>> map = this.propertyAccessorClasses;
|
||||
Class<PersistentPropertyAccessor<?>> propertyAccessorClass = map.get(entity.getTypeInformation());
|
||||
var map = this.propertyAccessorClasses;
|
||||
var propertyAccessorClass = map.get(entity.getTypeInformation());
|
||||
|
||||
if (propertyAccessorClass != null) {
|
||||
return propertyAccessorClass;
|
||||
@@ -314,9 +313,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
*/
|
||||
static Class<?> generateCustomAccessorClass(PersistentEntity<?, ?> entity) {
|
||||
|
||||
String className = generateClassName(entity);
|
||||
Class<?> type = entity.getType();
|
||||
ClassLoader classLoader = type.getClassLoader();
|
||||
var className = generateClassName(entity);
|
||||
var type = entity.getType();
|
||||
var classLoader = type.getClassLoader();
|
||||
|
||||
if (ClassUtils.isPresent(className, classLoader)) {
|
||||
|
||||
@@ -327,7 +326,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
}
|
||||
}
|
||||
|
||||
byte[] bytecode = generateBytecode(className.replace('.', '/'), entity);
|
||||
var bytecode = generateBytecode(className.replace('.', '/'), entity);
|
||||
|
||||
try {
|
||||
|
||||
@@ -343,10 +342,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
*/
|
||||
static byte[] generateBytecode(String internalClassName, PersistentEntity<?, ?> entity) {
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
cw.visit(Opcodes.V1_6, ACC_PUBLIC + ACC_SUPER, internalClassName, null, JAVA_LANG_OBJECT, IMPLEMENTED_INTERFACES);
|
||||
|
||||
List<PersistentProperty<?>> persistentProperties = getPersistentProperties(entity);
|
||||
var persistentProperties = getPersistentProperties(entity);
|
||||
|
||||
visitFields(entity, persistentProperties, cw);
|
||||
visitDefaultConstructor(entity, internalClassName, cw);
|
||||
@@ -393,7 +392,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
cw.visitField(ACC_PRIVATE, BEAN_FIELD, getAccessibleTypeReferenceName(entity), null, null).visitEnd();
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
for (var property : persistentProperties) {
|
||||
|
||||
if (property.isImmutable()) {
|
||||
if (generateMethodHandle(entity, property.getWither())) {
|
||||
@@ -443,7 +442,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv = cw.visitMethod(ACC_PUBLIC, INIT, String.format("(%s)V", getAccessibleTypeReferenceName(entity)), null, null);
|
||||
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
var l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false);
|
||||
@@ -461,7 +460,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitFieldInsn(PUTFIELD, internalClassName, BEAN_FIELD, getAccessibleTypeReferenceName(entity));
|
||||
|
||||
mv.visitInsn(RETURN);
|
||||
Label l3 = new Label();
|
||||
var l3 = new Label();
|
||||
mv.visitLabel(l3);
|
||||
mv.visitLocalVariable(THIS_REF, referenceName(internalClassName), null, l0, l3, 0);
|
||||
mv.visitLocalVariable(BEAN_FIELD, getAccessibleTypeReferenceName(entity), null, l0, l3, 1);
|
||||
@@ -490,10 +489,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitStaticInitializer(PersistentEntity<?, ?> entity,
|
||||
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
|
||||
var mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
Label l1 = new Label();
|
||||
var l0 = new Label();
|
||||
var l1 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
|
||||
// lookup = MethodHandles.lookup()
|
||||
@@ -501,9 +500,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
String.format("()%s", referenceName(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP)), false);
|
||||
mv.visitVarInsn(ASTORE, 0);
|
||||
|
||||
List<Class<?>> entityClasses = getPropertyDeclaratingClasses(persistentProperties);
|
||||
var entityClasses = getPropertyDeclaratingClasses(persistentProperties);
|
||||
|
||||
for (Class<?> entityClass : entityClasses) {
|
||||
for (var entityClass : entityClasses) {
|
||||
|
||||
mv.visitLdcInsn(entityClass.getName());
|
||||
mv.visitMethodInsn(INVOKESTATIC, JAVA_LANG_CLASS, "forName",
|
||||
@@ -511,7 +510,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitVarInsn(ASTORE, classVariableIndex5(entityClasses, entityClass));
|
||||
}
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
for (var property : persistentProperties) {
|
||||
|
||||
if (property.usePropertyAccess()) {
|
||||
|
||||
@@ -544,9 +543,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitLocalVariable("getter", referenceName(JAVA_LANG_REFLECT_METHOD), null, l0, l1, 3);
|
||||
mv.visitLocalVariable("wither", referenceName(JAVA_LANG_REFLECT_METHOD), null, l0, l1, 4);
|
||||
|
||||
for (Class<?> entityClass : entityClasses) {
|
||||
for (var entityClass : entityClasses) {
|
||||
|
||||
int index = classVariableIndex5(entityClasses, entityClass);
|
||||
var index = classVariableIndex5(entityClasses, entityClass);
|
||||
mv.visitLocalVariable(String.format("class_%d", index), referenceName(JAVA_LANG_CLASS), null, l0, l1, index);
|
||||
}
|
||||
|
||||
@@ -582,7 +581,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
List<Class<?>> entityClasses, String internalClassName) {
|
||||
|
||||
// getter = <entity>.class.getDeclaredMethod()
|
||||
Method getter = property.getGetter();
|
||||
var getter = property.getGetter();
|
||||
|
||||
if (getter != null) {
|
||||
|
||||
@@ -634,7 +633,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitInsn(DUP);
|
||||
mv.visitInsn(ICONST_0);
|
||||
|
||||
Class<?> parameterType = method.getParameterTypes()[0];
|
||||
var parameterType = method.getParameterTypes()[0];
|
||||
|
||||
if (parameterType.isPrimitive()) {
|
||||
mv.visitFieldInsn(GETSTATIC, Type.getInternalName(autoboxType(method.getParameterTypes()[0])), "TYPE",
|
||||
@@ -677,7 +676,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
// field = <entity>.class.getDeclaredField()
|
||||
|
||||
Field field = property.getField();
|
||||
var field = property.getField();
|
||||
if (field != null) {
|
||||
|
||||
mv.visitVarInsn(ALOAD, classVariableIndex5(entityClasses, field.getDeclaringClass()));
|
||||
@@ -715,10 +714,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitBeanGetter(PersistentEntity<?, ?> entity, String internalClassName, ClassWriter cw) {
|
||||
|
||||
// public Object getBean()
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)),
|
||||
var mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)),
|
||||
null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
var l0 = new Label();
|
||||
|
||||
// return this.bean
|
||||
mv.visitLabel(l0);
|
||||
@@ -728,7 +727,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
mv.visitInsn(ARETURN);
|
||||
|
||||
Label l1 = new Label();
|
||||
var l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable(THIS_REF, referenceName(internalClassName), null, l0, l1, 0);
|
||||
mv.visitMaxs(1, 1);
|
||||
@@ -759,13 +758,13 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitGetProperty(PersistentEntity<?, ?> entity,
|
||||
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getProperty",
|
||||
var mv = cw.visitMethod(ACC_PUBLIC, "getProperty",
|
||||
"(Lorg/springframework/data/mapping/PersistentProperty;)Ljava/lang/Object;",
|
||||
"(Lorg/springframework/data/mapping/PersistentProperty<*>;)Ljava/lang/Object;", null);
|
||||
mv.visitCode();
|
||||
|
||||
Label l0 = new Label();
|
||||
Label l1 = new Label();
|
||||
var l0 = new Label();
|
||||
var l1 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
|
||||
// Assert.notNull(property)
|
||||
@@ -798,21 +797,21 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitGetPropertySwitch(PersistentEntity<?, ?> entity,
|
||||
List<PersistentProperty<?>> persistentProperties, String internalClassName, MethodVisitor mv) {
|
||||
|
||||
Map<String, PropertyStackAddress> propertyStackMap = createPropertyStackMap(persistentProperties);
|
||||
var propertyStackMap = createPropertyStackMap(persistentProperties);
|
||||
|
||||
int[] hashes = new int[propertyStackMap.size()];
|
||||
Label[] switchJumpLabels = new Label[propertyStackMap.size()];
|
||||
var hashes = new int[propertyStackMap.size()];
|
||||
var switchJumpLabels = new Label[propertyStackMap.size()];
|
||||
List<PropertyStackAddress> stackmap = new ArrayList<>(propertyStackMap.values());
|
||||
Collections.sort(stackmap);
|
||||
|
||||
for (int i = 0; i < stackmap.size(); i++) {
|
||||
for (var i = 0; i < stackmap.size(); i++) {
|
||||
|
||||
PropertyStackAddress propertyStackAddress = stackmap.get(i);
|
||||
var propertyStackAddress = stackmap.get(i);
|
||||
hashes[i] = propertyStackAddress.hash;
|
||||
switchJumpLabels[i] = propertyStackAddress.label;
|
||||
}
|
||||
|
||||
Label dfltLabel = new Label();
|
||||
var dfltLabel = new Label();
|
||||
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, PERSISTENT_PROPERTY, "getName",
|
||||
@@ -820,7 +819,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_STRING, "hashCode", "()I", false);
|
||||
mv.visitLookupSwitchInsn(dfltLabel, hashes, switchJumpLabels);
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
for (var property : persistentProperties) {
|
||||
|
||||
mv.visitLabel(propertyStackMap.get(property.getName()).label);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
@@ -844,7 +843,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitGetProperty0(PersistentEntity<?, ?> entity, PersistentProperty<?> property,
|
||||
MethodVisitor mv, String internalClassName) {
|
||||
|
||||
Method getter = property.getGetter();
|
||||
var getter = property.getGetter();
|
||||
if (property.usePropertyAccess() && getter != null) {
|
||||
|
||||
if (generateMethodHandle(entity, getter)) {
|
||||
@@ -858,9 +857,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
// bean.get…
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
|
||||
int invokeOpCode = INVOKEVIRTUAL;
|
||||
Class<?> declaringClass = getter.getDeclaringClass();
|
||||
boolean interfaceDefinition = declaringClass.isInterface();
|
||||
var invokeOpCode = INVOKEVIRTUAL;
|
||||
var declaringClass = getter.getDeclaringClass();
|
||||
var interfaceDefinition = declaringClass.isInterface();
|
||||
|
||||
if (interfaceDefinition) {
|
||||
invokeOpCode = INVOKEINTERFACE;
|
||||
@@ -872,7 +871,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
}
|
||||
} else {
|
||||
|
||||
Field field = property.getRequiredField();
|
||||
var field = property.getRequiredField();
|
||||
|
||||
if (generateMethodHandle(entity, field)) {
|
||||
// $fieldGetter.invoke(bean)
|
||||
@@ -922,12 +921,12 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitSetProperty(PersistentEntity<?, ?> entity,
|
||||
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) {
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "setProperty",
|
||||
var mv = cw.visitMethod(ACC_PUBLIC, "setProperty",
|
||||
"(Lorg/springframework/data/mapping/PersistentProperty;Ljava/lang/Object;)V",
|
||||
"(Lorg/springframework/data/mapping/PersistentProperty<*>;Ljava/lang/Object;)V", null);
|
||||
mv.visitCode();
|
||||
|
||||
Label l0 = new Label();
|
||||
var l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
|
||||
visitAssertNotNull(mv);
|
||||
@@ -940,7 +939,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
visitSetPropertySwitch(entity, persistentProperties, internalClassName, mv);
|
||||
|
||||
Label l1 = new Label();
|
||||
var l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
|
||||
visitThrowUnsupportedOperationException(mv, "No accessor to set property %s!");
|
||||
@@ -962,20 +961,20 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitSetPropertySwitch(PersistentEntity<?, ?> entity,
|
||||
List<PersistentProperty<?>> persistentProperties, String internalClassName, MethodVisitor mv) {
|
||||
|
||||
Map<String, PropertyStackAddress> propertyStackMap = createPropertyStackMap(persistentProperties);
|
||||
var propertyStackMap = createPropertyStackMap(persistentProperties);
|
||||
|
||||
int[] hashes = new int[propertyStackMap.size()];
|
||||
Label[] switchJumpLabels = new Label[propertyStackMap.size()];
|
||||
var hashes = new int[propertyStackMap.size()];
|
||||
var switchJumpLabels = new Label[propertyStackMap.size()];
|
||||
List<PropertyStackAddress> stackmap = new ArrayList<>(propertyStackMap.values());
|
||||
Collections.sort(stackmap);
|
||||
|
||||
for (int i = 0; i < stackmap.size(); i++) {
|
||||
PropertyStackAddress propertyStackAddress = stackmap.get(i);
|
||||
for (var i = 0; i < stackmap.size(); i++) {
|
||||
var propertyStackAddress = stackmap.get(i);
|
||||
hashes[i] = propertyStackAddress.hash;
|
||||
switchJumpLabels[i] = propertyStackAddress.label;
|
||||
}
|
||||
|
||||
Label dfltLabel = new Label();
|
||||
var dfltLabel = new Label();
|
||||
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, PERSISTENT_PROPERTY, "getName",
|
||||
@@ -983,7 +982,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_STRING, "hashCode", "()I", false);
|
||||
mv.visitLookupSwitchInsn(dfltLabel, hashes, switchJumpLabels);
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
for (var property : persistentProperties) {
|
||||
mv.visitLabel(propertyStackMap.get(property.getName()).label);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
|
||||
@@ -1006,8 +1005,8 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitSetProperty0(PersistentEntity<?, ?> entity, PersistentProperty<?> property,
|
||||
MethodVisitor mv, String internalClassName) {
|
||||
|
||||
Method setter = property.getSetter();
|
||||
Method wither = property.getWither();
|
||||
var setter = property.getSetter();
|
||||
var wither = property.getWither();
|
||||
|
||||
if (property.isImmutable()) {
|
||||
|
||||
@@ -1085,7 +1084,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitKotlinCopy(PersistentEntity<?, ?> entity, PersistentProperty<?> property, MethodVisitor mv,
|
||||
String internalClassName) {
|
||||
|
||||
KotlinCopyMethod kotlinCopyMethod = KotlinCopyMethod.findCopyMethod(entity.getType())
|
||||
var kotlinCopyMethod = KotlinCopyMethod.findCopyMethod(entity.getType())
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
String.format("No usable .copy(…) method found in entity %s", entity.getType().getName())));
|
||||
|
||||
@@ -1101,17 +1100,17 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
visitInvokeMethodSingleArg(mv, kotlinCopyMethod.getPublicCopyMethod());
|
||||
} else {
|
||||
|
||||
Method copy = kotlinCopyMethod.getSyntheticCopyMethod();
|
||||
Class<?>[] parameterTypes = copy.getParameterTypes();
|
||||
var copy = kotlinCopyMethod.getSyntheticCopyMethod();
|
||||
var parameterTypes = copy.getParameterTypes();
|
||||
|
||||
// PersonWithId.copy$default..(bean, object, MASK, null)
|
||||
mv.visitVarInsn(ALOAD, 3);
|
||||
|
||||
KotlinCopyByProperty copyByProperty = kotlinCopyMethod.forProperty(property)
|
||||
var copyByProperty = kotlinCopyMethod.forProperty(property)
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
String.format("No usable .copy(…) method found for property %s", property)));
|
||||
|
||||
for (int i = 1; i < kotlinCopyMethod.getParameterCount(); i++) {
|
||||
for (var i = 1; i < kotlinCopyMethod.getParameterCount(); i++) {
|
||||
|
||||
if (copyByProperty.getParameterPosition() == i) {
|
||||
|
||||
@@ -1130,7 +1129,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
mv.visitInsn(Opcodes.ACONST_NULL);
|
||||
|
||||
int invokeOpCode = getInvokeOp(copy, false);
|
||||
var invokeOpCode = getInvokeOp(copy, false);
|
||||
|
||||
mv.visitMethodInsn(invokeOpCode, Type.getInternalName(copy.getDeclaringClass()), copy.getName(),
|
||||
getArgumentSignature(copy), false);
|
||||
@@ -1190,7 +1189,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static void visitSetField(PersistentEntity<?, ?> entity, PersistentProperty<?> property, MethodVisitor mv,
|
||||
String internalClassName) {
|
||||
|
||||
Field field = property.getField();
|
||||
var field = property.getField();
|
||||
if (field != null) {
|
||||
if (generateSetterMethodHandle(entity, field)) {
|
||||
// $fieldSetter.invoke(bean, object)
|
||||
@@ -1205,7 +1204,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
mv.visitVarInsn(ALOAD, 3);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
|
||||
Class<?> fieldType = field.getType();
|
||||
var fieldType = field.getType();
|
||||
|
||||
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(autoboxType(fieldType)));
|
||||
autoboxIfNeeded(autoboxType(fieldType), fieldType, mv);
|
||||
@@ -1225,10 +1224,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
*/
|
||||
private static String getArgumentSignature(Method method) {
|
||||
|
||||
StringBuilder result = new StringBuilder("(");
|
||||
var result = new StringBuilder("(");
|
||||
List<String> argumentTypes = new ArrayList<>();
|
||||
|
||||
for (Class<?> parameterType : method.getParameterTypes()) {
|
||||
for (var parameterType : method.getParameterTypes()) {
|
||||
|
||||
result.append("%s");
|
||||
argumentTypes.add(signatureTypeName(parameterType));
|
||||
@@ -1324,7 +1323,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
if (isAccessible(entity)) {
|
||||
|
||||
if (Modifier.isProtected(member.getModifiers()) || isDefault(member.getModifiers())) {
|
||||
Package declaringPackage = member.getDeclaringClass().getPackage();
|
||||
var declaringPackage = member.getDeclaringClass().getPackage();
|
||||
|
||||
if (declaringPackage != null && !declaringPackage.equals(entity.getType().getPackage())) {
|
||||
return true;
|
||||
@@ -1353,15 +1352,15 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
private static void visitInvokeMethodSingleArg(MethodVisitor mv, Method method) {
|
||||
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
Class<?> parameterType = parameterTypes[0];
|
||||
Class<?> declaringClass = method.getDeclaringClass();
|
||||
boolean interfaceDefinition = declaringClass.isInterface();
|
||||
var parameterTypes = method.getParameterTypes();
|
||||
var parameterType = parameterTypes[0];
|
||||
var declaringClass = method.getDeclaringClass();
|
||||
var interfaceDefinition = declaringClass.isInterface();
|
||||
|
||||
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(autoboxType(parameterType)));
|
||||
autoboxIfNeeded(autoboxType(parameterType), parameterType, mv);
|
||||
|
||||
int invokeOpCode = getInvokeOp(method, interfaceDefinition);
|
||||
var invokeOpCode = getInvokeOp(method, interfaceDefinition);
|
||||
|
||||
mv.visitMethodInsn(invokeOpCode, Type.getInternalName(method.getDeclaringClass()), method.getName(),
|
||||
String.format("(%s)%s", signatureTypeName(parameterType), signatureTypeName(method.getReturnType())),
|
||||
@@ -1370,7 +1369,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
private static int getInvokeOp(Method method, boolean interfaceDefinition) {
|
||||
|
||||
int invokeOpCode = Modifier.isStatic(method.getModifiers()) ? INVOKESTATIC : INVOKEVIRTUAL;
|
||||
var invokeOpCode = Modifier.isStatic(method.getModifiers()) ? INVOKESTATIC : INVOKEVIRTUAL;
|
||||
|
||||
if (interfaceDefinition) {
|
||||
invokeOpCode = INVOKEINTERFACE;
|
||||
@@ -1383,7 +1382,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
Map<String, PropertyStackAddress> stackmap = new HashMap<>();
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
for (var property : persistentProperties) {
|
||||
stackmap.put(property.getName(), new PropertyStackAddress(new Label(), property.getName().hashCode()));
|
||||
}
|
||||
return stackmap;
|
||||
@@ -1444,7 +1443,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
*/
|
||||
private static boolean hasKotlinCopyMethod(PersistentProperty<?> property) {
|
||||
|
||||
Class<?> type = property.getOwner().getType();
|
||||
var type = property.getOwner().getType();
|
||||
|
||||
if (isAccessible(type) && KotlinDetector.isKotlinType(type)) {
|
||||
return KotlinCopyMethod.findCopyMethod(type).filter(it -> it.supportsProperty(property)).isPresent();
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ConvertingPropertyAccessor<T> extends SimplePersistentPropertyPathA
|
||||
@Override
|
||||
public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value) {
|
||||
|
||||
Object converted = convertIfNecessary(value, path.getRequiredLeafProperty().getType());
|
||||
var converted = convertIfNecessary(value, path.getRequiredLeafProperty().getType());
|
||||
|
||||
super.setProperty(path, converted);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.mapping.model;
|
||||
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -51,7 +50,7 @@ public class DefaultSpELExpressionEvaluator implements SpELExpressionEvaluator {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T evaluate(String expression) {
|
||||
|
||||
Expression parseExpression = factory.getParser().parseExpression(expression);
|
||||
var parseExpression = factory.getParser().parseExpression(expression);
|
||||
return (T) parseExpression.getValue(factory.getEvaluationContext(source));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,13 +87,13 @@ public class EntityInstantiators {
|
||||
public EntityInstantiator getInstantiatorFor(PersistentEntity<?, ?> entity) {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
Class<?> type = entity.getType();
|
||||
var type = entity.getType();
|
||||
|
||||
if (!customInstantiators.containsKey(type)) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
EntityInstantiator instantiator = customInstantiators.get(entity.getType());
|
||||
var instantiator = customInstantiators.get(entity.getType());
|
||||
return instantiator == null ? fallback : instantiator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ import java.util.function.Function;
|
||||
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -76,8 +74,8 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
|
||||
@Override
|
||||
public void setProperty(PersistentProperty<?> property, @Nullable Object value) {
|
||||
|
||||
PersistentEntity<?, ?> owner = property.getOwner();
|
||||
PersistentPropertyAccessor<T> delegate = delegateFunction.apply(this.bean);
|
||||
var owner = property.getOwner();
|
||||
var delegate = delegateFunction.apply(this.bean);
|
||||
|
||||
if (!property.isImmutable() || property.getWither() != null || KotlinDetector.isKotlinType(owner.getType())) {
|
||||
|
||||
@@ -87,7 +85,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
|
||||
return;
|
||||
}
|
||||
|
||||
PreferredConstructor<?, ?> constructor = owner.getPersistenceConstructor();
|
||||
var constructor = owner.getPersistenceConstructor();
|
||||
|
||||
if (constructor == null) {
|
||||
throw new IllegalStateException(String.format(NO_SETTER_OR_CONSTRUCTOR, property.getName(), owner.getType()));
|
||||
@@ -106,7 +104,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
|
||||
}
|
||||
});
|
||||
|
||||
EntityInstantiator instantiator = instantiators.getInstantiatorFor(owner);
|
||||
var instantiator = instantiators.getInstantiatorFor(owner);
|
||||
|
||||
this.bean = (T) instantiator.createInstance(owner, new ParameterValueProvider() {
|
||||
|
||||
|
||||
@@ -49,16 +49,16 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
@Override
|
||||
protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> entity) {
|
||||
|
||||
PreferredConstructor<?, ?> constructor = entity.getPersistenceConstructor();
|
||||
var constructor = entity.getPersistenceConstructor();
|
||||
|
||||
if (KotlinReflectionUtils.isSupportedKotlinClass(entity.getType()) && constructor != null) {
|
||||
|
||||
PreferredConstructor<?, ?> defaultConstructor = new DefaultingKotlinConstructorResolver(entity)
|
||||
var defaultConstructor = new DefaultingKotlinConstructorResolver(entity)
|
||||
.getDefaultConstructor();
|
||||
|
||||
if (defaultConstructor != null) {
|
||||
|
||||
ObjectInstantiator instantiator = createObjectInstantiator(entity, defaultConstructor);
|
||||
var instantiator = createObjectInstantiator(entity, defaultConstructor);
|
||||
|
||||
return new DefaultingKotlinClassInstantiatorAdapter(instantiator, constructor);
|
||||
}
|
||||
@@ -81,8 +81,8 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
@SuppressWarnings("unchecked")
|
||||
DefaultingKotlinConstructorResolver(PersistentEntity<?, ?> entity) {
|
||||
|
||||
Constructor<?> hit = resolveDefaultConstructor(entity);
|
||||
PreferredConstructor<?, ?> persistenceConstructor = entity.getPersistenceConstructor();
|
||||
var hit = resolveDefaultConstructor(entity);
|
||||
var persistenceConstructor = entity.getPersistenceConstructor();
|
||||
|
||||
if (hit != null && persistenceConstructor != null) {
|
||||
this.defaultConstructor = new PreferredConstructor<>(hit,
|
||||
@@ -95,16 +95,16 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
@Nullable
|
||||
private static Constructor<?> resolveDefaultConstructor(PersistentEntity<?, ?> entity) {
|
||||
|
||||
PreferredConstructor<?, ?> persistenceConstructor = entity.getPersistenceConstructor();
|
||||
var persistenceConstructor = entity.getPersistenceConstructor();
|
||||
|
||||
if (persistenceConstructor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Constructor<?> hit = null;
|
||||
Constructor<?> constructor = persistenceConstructor.getConstructor();
|
||||
var constructor = persistenceConstructor.getConstructor();
|
||||
|
||||
for (Constructor<?> candidate : entity.getType().getDeclaredConstructors()) {
|
||||
for (var candidate : entity.getType().getDeclaredConstructors()) {
|
||||
|
||||
// use only synthetic constructors
|
||||
if (!candidate.isSynthetic()) {
|
||||
@@ -113,15 +113,15 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
|
||||
// candidates must contain at least two additional parameters (int, DefaultConstructorMarker).
|
||||
// Number of defaulting masks derives from the original constructor arg count
|
||||
int syntheticParameters = KotlinDefaultMask.getMaskCount(constructor.getParameterCount())
|
||||
var syntheticParameters = KotlinDefaultMask.getMaskCount(constructor.getParameterCount())
|
||||
+ /* DefaultConstructorMarker */ 1;
|
||||
|
||||
if (constructor.getParameterCount() + syntheticParameters != candidate.getParameterCount()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
java.lang.reflect.Parameter[] constructorParameters = constructor.getParameters();
|
||||
java.lang.reflect.Parameter[] candidateParameters = candidate.getParameters();
|
||||
var constructorParameters = constructor.getParameters();
|
||||
var candidateParameters = candidate.getParameters();
|
||||
|
||||
if (!candidateParameters[candidateParameters.length - 1].getType().getName()
|
||||
.equals("kotlin.jvm.internal.DefaultConstructorMarker")) {
|
||||
@@ -177,7 +177,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
|
||||
DefaultingKotlinClassInstantiatorAdapter(ObjectInstantiator instantiator, PreferredConstructor<?, ?> constructor) {
|
||||
|
||||
KFunction<?> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(constructor.getConstructor());
|
||||
var kotlinConstructor = ReflectJvmMapping.getKotlinFunction(constructor.getConstructor());
|
||||
|
||||
if (kotlinConstructor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -199,7 +199,7 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
|
||||
ParameterValueProvider<P> provider) {
|
||||
|
||||
Object[] params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
|
||||
var params = extractInvocationArguments(entity.getPersistenceConstructor(), provider);
|
||||
|
||||
try {
|
||||
return (T) instantiator.newInstance(params);
|
||||
@@ -215,25 +215,25 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
throw new IllegalArgumentException("PreferredConstructor must not be null!");
|
||||
}
|
||||
|
||||
Object[] params = allocateArguments(synthetic.getParameterCount()
|
||||
var params = allocateArguments(synthetic.getParameterCount()
|
||||
+ KotlinDefaultMask.getMaskCount(synthetic.getParameterCount()) + /* DefaultConstructorMarker */1);
|
||||
int userParameterCount = kParameters.size();
|
||||
var userParameterCount = kParameters.size();
|
||||
|
||||
List<Parameter<Object, P>> parameters = preferredConstructor.getParameters();
|
||||
var parameters = preferredConstructor.getParameters();
|
||||
|
||||
// Prepare user-space arguments
|
||||
for (int i = 0; i < userParameterCount; i++) {
|
||||
for (var i = 0; i < userParameterCount; i++) {
|
||||
|
||||
Parameter<Object, P> parameter = parameters.get(i);
|
||||
var parameter = parameters.get(i);
|
||||
params[i] = provider.getParameterValue(parameter);
|
||||
}
|
||||
|
||||
KotlinDefaultMask defaultMask = KotlinDefaultMask.from(constructor, it -> {
|
||||
var defaultMask = KotlinDefaultMask.from(constructor, it -> {
|
||||
|
||||
int index = kParameters.indexOf(it);
|
||||
var index = kParameters.indexOf(it);
|
||||
|
||||
Parameter<Object, P> parameter = parameters.get(index);
|
||||
Class<Object> type = parameter.getType().getType();
|
||||
var parameter = parameters.get(index);
|
||||
var type = parameter.getType().getType();
|
||||
|
||||
if (it.isOptional() && params[index] == null) {
|
||||
if (type.isPrimitive()) {
|
||||
@@ -247,9 +247,9 @@ class KotlinClassGeneratingEntityInstantiator extends ClassGeneratingEntityInsta
|
||||
return true;
|
||||
});
|
||||
|
||||
int[] defaulting = defaultMask.getDefaulting();
|
||||
var defaulting = defaultMask.getDefaulting();
|
||||
// append nullability masks to creation arguments
|
||||
for (int i = 0; i < defaulting.length; i++) {
|
||||
for (var i = 0; i < defaulting.length; i++) {
|
||||
params[userParameterCount + i] = defaulting[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import kotlin.jvm.JvmClassMappingKt;
|
||||
import kotlin.reflect.KClass;
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.KParameter;
|
||||
import kotlin.reflect.KParameter.Kind;
|
||||
@@ -26,7 +25,6 @@ import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -78,13 +76,13 @@ class KotlinCopyMethod {
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
Optional<Method> syntheticCopyMethod = findSyntheticCopyMethod(type);
|
||||
var syntheticCopyMethod = findSyntheticCopyMethod(type);
|
||||
|
||||
if (!syntheticCopyMethod.isPresent()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Optional<Method> publicCopyMethod = syntheticCopyMethod.flatMap(KotlinCopyMethod::findPublicCopyMethod);
|
||||
var publicCopyMethod = syntheticCopyMethod.flatMap(KotlinCopyMethod::findPublicCopyMethod);
|
||||
|
||||
return publicCopyMethod.map(method -> new KotlinCopyMethod(method, syntheticCopyMethod.get()));
|
||||
}
|
||||
@@ -123,7 +121,7 @@ class KotlinCopyMethod {
|
||||
*/
|
||||
Optional<KotlinCopyByProperty> forProperty(PersistentProperty<?> property) {
|
||||
|
||||
int index = KotlinCopyByProperty.findIndex(copyFunction, property.getName());
|
||||
var index = KotlinCopyByProperty.findIndex(copyFunction, property.getName());
|
||||
|
||||
if (index == -1) {
|
||||
return Optional.empty();
|
||||
@@ -149,9 +147,9 @@ class KotlinCopyMethod {
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?>[] parameterTypes = publicCopyMethod.getParameterTypes();
|
||||
var parameterTypes = publicCopyMethod.getParameterTypes();
|
||||
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
for (var i = 0; i < parameterTypes.length; i++) {
|
||||
if (!parameterTypes[i].equals(persistentProperties.get(i).getType())) {
|
||||
return false;
|
||||
}
|
||||
@@ -162,16 +160,16 @@ class KotlinCopyMethod {
|
||||
|
||||
private static Optional<Method> findPublicCopyMethod(Method defaultKotlinMethod) {
|
||||
|
||||
Class<?> type = defaultKotlinMethod.getDeclaringClass();
|
||||
KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(type);
|
||||
var type = defaultKotlinMethod.getDeclaringClass();
|
||||
var kotlinClass = JvmClassMappingKt.getKotlinClass(type);
|
||||
|
||||
KFunction<?> primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
|
||||
var primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
|
||||
|
||||
if (primaryConstructor == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
List<KParameter> constructorArguments = getComponentArguments(primaryConstructor);
|
||||
var constructorArguments = getComponentArguments(primaryConstructor);
|
||||
|
||||
return Arrays.stream(type.getDeclaredMethods()).filter(it -> it.getName().equals("copy") //
|
||||
&& !it.isSynthetic() //
|
||||
@@ -180,7 +178,7 @@ class KotlinCopyMethod {
|
||||
&& it.getParameterCount() == constructorArguments.size()) //
|
||||
.filter(it -> {
|
||||
|
||||
KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(it);
|
||||
var kotlinFunction = ReflectJvmMapping.getKotlinFunction(it);
|
||||
|
||||
if (kotlinFunction == null) {
|
||||
return false;
|
||||
@@ -192,10 +190,10 @@ class KotlinCopyMethod {
|
||||
|
||||
private static boolean parameterMatches(List<KParameter> constructorArguments, KFunction<?> kotlinFunction) {
|
||||
|
||||
boolean foundInstance = false;
|
||||
int constructorArgIndex = 0;
|
||||
var foundInstance = false;
|
||||
var constructorArgIndex = 0;
|
||||
|
||||
for (KParameter parameter : kotlinFunction.getParameters()) {
|
||||
for (var parameter : kotlinFunction.getParameters()) {
|
||||
|
||||
if (parameter.getKind() == Kind.INSTANCE) {
|
||||
foundInstance = true;
|
||||
@@ -206,7 +204,7 @@ class KotlinCopyMethod {
|
||||
return false;
|
||||
}
|
||||
|
||||
KParameter constructorParameter = constructorArguments.get(constructorArgIndex);
|
||||
var constructorParameter = constructorArguments.get(constructorArgIndex);
|
||||
|
||||
if (constructorParameter.getName() == null || !constructorParameter.getName().equals(parameter.getName())
|
||||
|| !constructorParameter.getType().equals(parameter.getType())) {
|
||||
@@ -221,8 +219,8 @@ class KotlinCopyMethod {
|
||||
|
||||
private static Optional<Method> findSyntheticCopyMethod(Class<?> type) {
|
||||
|
||||
KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(type);
|
||||
KFunction<?> primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
|
||||
var kotlinClass = JvmClassMappingKt.getKotlinClass(type);
|
||||
var primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
|
||||
|
||||
if (primaryConstructor == null) {
|
||||
return Optional.empty();
|
||||
@@ -242,9 +240,9 @@ class KotlinCopyMethod {
|
||||
*/
|
||||
private static boolean matchesPrimaryConstructor(Class<?>[] parameterTypes, KFunction<?> primaryConstructor) {
|
||||
|
||||
List<KParameter> constructorArguments = getComponentArguments(primaryConstructor);
|
||||
var constructorArguments = getComponentArguments(primaryConstructor);
|
||||
|
||||
int defaultingArgs = KotlinDefaultMask.from(primaryConstructor, kParameter -> false).getDefaulting().length;
|
||||
var defaultingArgs = KotlinDefaultMask.from(primaryConstructor, kParameter -> false).getDefaulting().length;
|
||||
|
||||
if (parameterTypes.length != 1 /* $this */ + constructorArguments.size() + defaultingArgs + 1 /* object marker */) {
|
||||
return false;
|
||||
@@ -255,9 +253,9 @@ class KotlinCopyMethod {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < constructorArguments.size(); i++) {
|
||||
for (var i = 0; i < constructorArguments.size(); i++) {
|
||||
|
||||
KParameter kParameter = constructorArguments.get(i);
|
||||
var kParameter = constructorArguments.get(i);
|
||||
|
||||
if (!isAssignableFrom(parameterTypes[i + 1], kParameter.getType())) {
|
||||
return false;
|
||||
@@ -276,9 +274,9 @@ class KotlinCopyMethod {
|
||||
|
||||
private static boolean isAssignableFrom(Class<?> target, KType source) {
|
||||
|
||||
Type parameterType = ReflectJvmMapping.getJavaType(source);
|
||||
var parameterType = ReflectJvmMapping.getJavaType(source);
|
||||
|
||||
Class<?> rawClass = ResolvableType.forType(parameterType).getRawClass();
|
||||
var rawClass = ResolvableType.forType(parameterType).getRawClass();
|
||||
return rawClass == null || target.isAssignableFrom(rawClass);
|
||||
}
|
||||
|
||||
@@ -302,7 +300,7 @@ class KotlinCopyMethod {
|
||||
|
||||
static int findIndex(KFunction<?> function, String parameterName) {
|
||||
|
||||
for (KParameter parameter : function.getParameters()) {
|
||||
for (var parameter : function.getParameters()) {
|
||||
if (parameterName.equals(parameter.getName())) {
|
||||
return parameter.getIndex();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class KotlinDefaultMask {
|
||||
*/
|
||||
public void forEach(IntConsumer maskCallback) {
|
||||
|
||||
for (int i : defaulting) {
|
||||
for (var i : defaulting) {
|
||||
maskCallback.accept(i);
|
||||
}
|
||||
}
|
||||
@@ -71,12 +71,12 @@ public class KotlinDefaultMask {
|
||||
public static KotlinDefaultMask from(KFunction<?> function, Predicate<KParameter> isPresent) {
|
||||
|
||||
List<Integer> masks = new ArrayList<>();
|
||||
int index = 0;
|
||||
int mask = 0;
|
||||
var index = 0;
|
||||
var mask = 0;
|
||||
|
||||
List<KParameter> parameters = function.getParameters();
|
||||
var parameters = function.getParameters();
|
||||
|
||||
for (KParameter parameter : parameters) {
|
||||
for (var parameter : parameters) {
|
||||
|
||||
if (index != 0 && index % Integer.SIZE == 0) {
|
||||
masks.add(mask);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -87,7 +86,7 @@ public class MappingInstantiationException extends RuntimeException {
|
||||
Optional<? extends PreferredConstructor<?, ?>> constructor = Optional.ofNullable(it.getPersistenceConstructor());
|
||||
List<String> toStringArgs = new ArrayList<>(arguments.size());
|
||||
|
||||
for (Object o : arguments) {
|
||||
for (var o : arguments) {
|
||||
toStringArgs.add(ObjectUtils.nullSafeToString(o));
|
||||
}
|
||||
|
||||
@@ -100,11 +99,11 @@ public class MappingInstantiationException extends RuntimeException {
|
||||
|
||||
private static String toString(PreferredConstructor<?, ?> preferredConstructor) {
|
||||
|
||||
Constructor<?> constructor = preferredConstructor.getConstructor();
|
||||
var constructor = preferredConstructor.getConstructor();
|
||||
|
||||
if (KotlinReflectionUtils.isSupportedKotlinClass(constructor.getDeclaringClass())) {
|
||||
|
||||
KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(constructor);
|
||||
var kotlinFunction = ReflectJvmMapping.getKotlinFunction(constructor);
|
||||
|
||||
if (kotlinFunction != null) {
|
||||
return kotlinFunction.toString();
|
||||
|
||||
@@ -53,7 +53,7 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy {
|
||||
? entity.getRequiredVersionProperty().getType() //
|
||||
: entity.hasIdProperty() ? entity.getRequiredIdProperty().getType() : null;
|
||||
|
||||
Class<?> type = valueType;
|
||||
var type = valueType;
|
||||
|
||||
if (type != null && type.isPrimitive()) {
|
||||
|
||||
@@ -93,7 +93,7 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy {
|
||||
@Override
|
||||
public boolean isNew(Object entity) {
|
||||
|
||||
Object value = valueLookup.apply(entity);
|
||||
var value = valueLookup.apply(entity);
|
||||
|
||||
if (value == null) {
|
||||
return true;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.mapping.model;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -52,19 +51,19 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getParameterValue(Parameter<T, P> parameter) {
|
||||
|
||||
PreferredConstructor<?, P> constructor = entity.getPersistenceConstructor();
|
||||
var constructor = entity.getPersistenceConstructor();
|
||||
|
||||
if (constructor != null && constructor.isEnclosingClassParameter(parameter)) {
|
||||
return (T) parent;
|
||||
}
|
||||
|
||||
String name = parameter.getName();
|
||||
var name = parameter.getName();
|
||||
|
||||
if (name == null) {
|
||||
throw new MappingException(String.format("Parameter %s does not have a name!", parameter));
|
||||
}
|
||||
|
||||
P property = entity.getPersistentProperty(name);
|
||||
var property = entity.getPersistentProperty(name);
|
||||
|
||||
if (property == null) {
|
||||
throw new MappingException(
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import kotlin.jvm.JvmClassMappingKt;
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.full.KClasses;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -113,7 +111,7 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
|
||||
|
||||
List<Constructor<?>> candidates = new ArrayList<>();
|
||||
Constructor<?> noArg = null;
|
||||
for (Constructor<?> candidate : rawOwningType.getDeclaredConstructors()) {
|
||||
for (var candidate : rawOwningType.getDeclaredConstructors()) {
|
||||
|
||||
// Synthetic constructors should not be considered
|
||||
if (candidate.isSynthetic()) {
|
||||
@@ -164,14 +162,14 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
|
||||
.findFirst() //
|
||||
.orElseGet(() -> {
|
||||
|
||||
KFunction<T> primaryConstructor = KClasses
|
||||
var primaryConstructor = KClasses
|
||||
.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(type.getType()));
|
||||
|
||||
if (primaryConstructor == null) {
|
||||
return DEFAULT.discover(type, entity);
|
||||
}
|
||||
|
||||
Constructor<T> javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
|
||||
var javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
|
||||
|
||||
return javaConstructor != null ? buildPreferredConstructor(javaConstructor, type, entity) : null;
|
||||
});
|
||||
@@ -209,17 +207,17 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
|
||||
return new PreferredConstructor<>((Constructor<T>) constructor);
|
||||
}
|
||||
|
||||
List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor);
|
||||
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
|
||||
var parameterTypes = typeInformation.getParameterTypes(constructor);
|
||||
var parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
|
||||
|
||||
Parameter<Object, P>[] parameters = new Parameter[parameterTypes.size()];
|
||||
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
|
||||
var parameterAnnotations = constructor.getParameterAnnotations();
|
||||
|
||||
for (int i = 0; i < parameterTypes.size(); i++) {
|
||||
for (var i = 0; i < parameterTypes.size(); i++) {
|
||||
|
||||
String name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
|
||||
TypeInformation<?> type = parameterTypes.get(i);
|
||||
Annotation[] annotations = parameterAnnotations[i];
|
||||
var name = parameterNames == null || parameterNames.length <= i ? null : parameterNames[i];
|
||||
var type = parameterTypes.get(i);
|
||||
var annotations = parameterAnnotations[i];
|
||||
|
||||
parameters[i] = new Parameter(name, type, annotations, entity);
|
||||
}
|
||||
|
||||
@@ -223,12 +223,10 @@ public class Property {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof Property)) {
|
||||
if (!(obj instanceof Property that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Property that = (Property) obj;
|
||||
|
||||
return this.field.isPresent() ? this.field.equals(that.field) : this.descriptor.equals(that.descriptor);
|
||||
}
|
||||
|
||||
@@ -278,8 +276,8 @@ public class Property {
|
||||
|
||||
private static Optional<Method> findWither(TypeInformation<?> owner, String propertyName, Class<?> rawType) {
|
||||
|
||||
AtomicReference<Method> resultHolder = new AtomicReference<>();
|
||||
String methodName = String.format("with%s", StringUtils.capitalize(propertyName));
|
||||
var resultHolder = new AtomicReference<Method>();
|
||||
var methodName = String.format("with%s", StringUtils.capitalize(propertyName));
|
||||
|
||||
ReflectionUtils.doWithMethods(owner.getType(), it -> {
|
||||
|
||||
@@ -288,7 +286,7 @@ public class Property {
|
||||
}
|
||||
}, it -> isMethodWithSingleParameterOfType(it, methodName, rawType));
|
||||
|
||||
Method method = resultHolder.get();
|
||||
var method = resultHolder.get();
|
||||
return method != null ? Optional.of(method) : Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,15 +44,15 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
|
||||
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty<P>> T createInstance(E entity,
|
||||
ParameterValueProvider<P> provider) {
|
||||
|
||||
PreferredConstructor<? extends T, P> constructor = entity.getPersistenceConstructor();
|
||||
var constructor = entity.getPersistenceConstructor();
|
||||
|
||||
if (constructor == null) {
|
||||
|
||||
try {
|
||||
Class<?> clazz = entity.getType();
|
||||
if (clazz.isArray()) {
|
||||
Class<?> ctype = clazz;
|
||||
int dims = 0;
|
||||
var ctype = clazz;
|
||||
var dims = 0;
|
||||
while (ctype.isArray()) {
|
||||
ctype = ctype.getComponentType();
|
||||
dims++;
|
||||
@@ -65,10 +65,10 @@ enum ReflectionEntityInstantiator implements EntityInstantiator {
|
||||
throw new MappingInstantiationException(entity, Collections.emptyList(), e);
|
||||
}
|
||||
}
|
||||
int parameterCount = constructor.getConstructor().getParameterCount();
|
||||
var parameterCount = constructor.getConstructor().getParameterCount();
|
||||
|
||||
Object[] params = parameterCount == 0 ? EMPTY_ARGS : new Object[parameterCount];
|
||||
int i = 0;
|
||||
var params = parameterCount == 0 ? EMPTY_ARGS : new Object[parameterCount];
|
||||
var i = 0;
|
||||
for (Parameter<?, P> parameter : constructor.getParameters()) {
|
||||
params[i++] = provider.getParameterValue(parameter);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.data.mapping.AccessOptions;
|
||||
import org.springframework.data.mapping.AccessOptions.GetOptions;
|
||||
@@ -31,7 +32,6 @@ import org.springframework.data.mapping.AccessOptions.GetOptions.GetNulls;
|
||||
import org.springframework.data.mapping.AccessOptions.SetOptions;
|
||||
import org.springframework.data.mapping.AccessOptions.SetOptions.SetNulls;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
@@ -97,7 +97,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, GetOptions options) {
|
||||
|
||||
Object bean = getBean();
|
||||
Object current = bean;
|
||||
var current = bean;
|
||||
|
||||
if (path.isEmpty()) {
|
||||
return bean;
|
||||
@@ -109,8 +109,8 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
return handleNull(path, options.getNullValues().toNullHandling());
|
||||
}
|
||||
|
||||
PersistentEntity<?, ? extends PersistentProperty<?>> entity = property.getOwner();
|
||||
PersistentPropertyAccessor<Object> accessor = entity.getPropertyAccessor(current);
|
||||
var entity = property.getOwner();
|
||||
var accessor = entity.getPropertyAccessor(current);
|
||||
|
||||
current = accessor.getProperty(property);
|
||||
}
|
||||
@@ -148,18 +148,18 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
Assert.notNull(path, "PersistentPropertyPath must not be null!");
|
||||
Assert.isTrue(!path.isEmpty(), "PersistentPropertyPath must not be empty!");
|
||||
|
||||
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
|
||||
PersistentProperty<?> leafProperty = path.getRequiredLeafProperty();
|
||||
var parentPath = path.getParentPath();
|
||||
var leafProperty = path.getRequiredLeafProperty();
|
||||
|
||||
if (!options.propagate(parentPath.getLeafProperty())) {
|
||||
return;
|
||||
}
|
||||
|
||||
GetOptions lookupOptions = options.getNullHandling() != REJECT
|
||||
var lookupOptions = options.getNullHandling() != REJECT
|
||||
? DEFAULT_GET_OPTIONS.withNullValues(GetNulls.EARLY_RETURN)
|
||||
: DEFAULT_GET_OPTIONS;
|
||||
|
||||
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
|
||||
var parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
|
||||
|
||||
if (parent == null) {
|
||||
handleNull(path, options.getNullHandling());
|
||||
@@ -172,7 +172,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
return;
|
||||
}
|
||||
|
||||
PersistentProperty<?> parentProperty = parentPath.getRequiredLeafProperty();
|
||||
var parentProperty = parentPath.getRequiredLeafProperty();
|
||||
|
||||
Object newValue;
|
||||
|
||||
@@ -196,7 +196,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Object, Object> result = CollectionFactory.createApproximateMap(source, source.size());
|
||||
var result = CollectionFactory.createApproximateMap(source, source.size());
|
||||
|
||||
for (Entry<?, Object> entry : source.entrySet()) {
|
||||
result.put(entry.getKey(), setValue(entry.getValue(), leafProperty, value));
|
||||
@@ -225,14 +225,14 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
return null;
|
||||
}
|
||||
|
||||
String nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
|
||||
var nullIntermediateMessage = "Cannot lookup property %s on null intermediate! Original path was: %s on %s.";
|
||||
|
||||
if (SetNulls.SKIP_AND_LOG.equals(handling)) {
|
||||
logger.info(nullIntermediateMessage);
|
||||
return null;
|
||||
}
|
||||
|
||||
PersistentPropertyPath<? extends PersistentProperty<?>> parentPath = path.getParentPath();
|
||||
var parentPath = path.getParentPath();
|
||||
|
||||
throw new MappingException(String.format(nullIntermediateMessage, parentPath.getLeafProperty(), path.toDotPath(),
|
||||
getBean().getClass().getName()));
|
||||
@@ -249,7 +249,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
*/
|
||||
private static Object setValue(Object parent, PersistentProperty<?> property, @Nullable Object newValue) {
|
||||
|
||||
PersistentPropertyAccessor<Object> accessor = property.getAccessorForOwner(parent);
|
||||
var accessor = property.getAccessorForOwner(parent);
|
||||
accessor.setProperty(property, newValue);
|
||||
return accessor.getBean();
|
||||
}
|
||||
@@ -269,7 +269,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
Assert.notNull(property, "Property must not be null!");
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
Object value = getProperty(property);
|
||||
var value = getProperty(property);
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@@ -123,7 +122,7 @@ public class SimpleTypeHolder {
|
||||
|
||||
private void registerCachePositives(Map<Class<?>, Boolean> source) {
|
||||
|
||||
for (Entry<Class<?>, Boolean> entry : source.entrySet()) {
|
||||
for (var entry : source.entrySet()) {
|
||||
|
||||
if (!entry.getValue()) {
|
||||
continue;
|
||||
@@ -143,8 +142,8 @@ public class SimpleTypeHolder {
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
Map<Class<?>, Boolean> localSimpleTypes = this.simpleTypes;
|
||||
Boolean isSimpleType = localSimpleTypes.get(type);
|
||||
var localSimpleTypes = this.simpleTypes;
|
||||
var isSimpleType = localSimpleTypes.get(type);
|
||||
|
||||
if (Object.class.equals(type) || Enum.class.isAssignableFrom(type)) {
|
||||
return true;
|
||||
@@ -154,13 +153,13 @@ public class SimpleTypeHolder {
|
||||
return isSimpleType;
|
||||
}
|
||||
|
||||
String typeName = type.getName();
|
||||
var typeName = type.getName();
|
||||
|
||||
if (typeName.startsWith("java.lang") || type.getName().startsWith("java.time") || typeName.equals("kotlin.Unit")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Class<?> simpleType : localSimpleTypes.keySet()) {
|
||||
for (var simpleType : localSimpleTypes.keySet()) {
|
||||
|
||||
if (simpleType.isAssignableFrom(type)) {
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public class SpELContext {
|
||||
*/
|
||||
public EvaluationContext getEvaluationContext(Object source) {
|
||||
|
||||
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(source);
|
||||
var evaluationContext = new StandardEvaluationContext(source);
|
||||
evaluationContext.addPropertyAccessor(accessor);
|
||||
|
||||
if (factory != null) {
|
||||
|
||||
@@ -53,7 +53,7 @@ public class SpELExpressionParameterValueProvider<P extends PersistentProperty<P
|
||||
return delegate == null ? null : delegate.getParameterValue(parameter);
|
||||
}
|
||||
|
||||
Object object = evaluator.evaluate(parameter.getSpelExpression());
|
||||
var object = evaluator.evaluate(parameter.getSpelExpression());
|
||||
return object == null ? null : potentiallyConvertSpelValue(object, parameter);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user