Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.springframework.data.mapping.InstanceCreatorMetadata;
Expand All @@ -40,12 +42,14 @@
* constructor argument extraction.
*
* @author Mark Paluch
* @author Yohan Lee
* @since 3.1
*/
class KotlinInstantiationDelegate {

private final KFunction<?> constructor;
private final List<KParameter> kParameters;
private final Map<KParameter, Integer> indexByKParameter;
private final List<Function<Object, Object>> wrappers = new ArrayList<>();
private final Constructor<?> constructorToInvoke;
private final boolean hasDefaultConstructorMarker;
Expand All @@ -62,6 +66,8 @@ public KotlinInstantiationDelegate(PreferredConstructor<?, ?> preferredConstruct

this.constructor = kotlinConstructor;
this.kParameters = kotlinConstructor.getParameters();
this.indexByKParameter = IntStream.range(0, kParameters.size()).boxed()
.collect(Collectors.toMap(kParameters::get, Function.identity()));
this.constructorToInvoke = constructorToInvoke;
this.hasDefaultConstructorMarker = hasDefaultConstructorMarker(constructorToInvoke.getParameters());

Expand Down Expand Up @@ -118,7 +124,7 @@ public <P extends PersistentProperty<P>> Object[] extractInvocationArguments(Obj

KotlinDefaultMask defaultMask = KotlinDefaultMask.forConstructor(constructor, it -> {

int index = kParameters.indexOf(it);
int index = indexByKParameter.get(it);

Parameter<Object, P> parameter = parameters.get(index);
Class<Object> type = parameter.getType().getType();
Expand Down