DATACMNS-1710 - Polishing.

Reformat code. Skip parameter inspection if constructor has no parameters.

Original pull request: #440.
This commit is contained in:
Mark Paluch
2020-04-27 15:20:19 +02:00
parent 03832c36a4
commit d2d07fbec5

View File

@@ -115,22 +115,23 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
continue;
}
if(candidate.isAnnotationPresent(PersistenceConstructor.class)) {
if (candidate.isAnnotationPresent(PersistenceConstructor.class)) {
return buildPreferredConstructor(candidate, type, entity);
}
if(candidate.getParameterCount() == 0) {
if (candidate.getParameterCount() == 0) {
noArg = candidate;
} else {
candidates.add(candidate);
}
}
if(noArg != null) {
if (noArg != null) {
return buildPreferredConstructor(noArg, type, entity);
}
return candidates.size() > 1 || candidates.isEmpty() ? null : buildPreferredConstructor(candidates.iterator().next(), type, entity);
return candidates.size() > 1 || candidates.isEmpty() ? null
: buildPreferredConstructor(candidates.iterator().next(), type, entity);
}
},
@@ -152,7 +153,8 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
return Arrays.stream(rawOwningType.getDeclaredConstructors()) //
.filter(it -> !it.isSynthetic()) // Synthetic constructors should not be considered
.filter(it -> it.isAnnotationPresent(PersistenceConstructor.class)) // Explicitly defined constructor trumps all
.filter(it -> it.isAnnotationPresent(PersistenceConstructor.class)) // Explicitly defined constructor trumps
// all
.map(it -> buildPreferredConstructor(it, type, entity)) //
.findFirst() //
.orElseGet(() -> {
@@ -198,12 +200,11 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
private static <T, P extends PersistentProperty<P>> PreferredConstructor<T, P> buildPreferredConstructor(
Constructor<?> constructor, TypeInformation<T> typeInformation, @Nullable PersistentEntity<T, P> entity) {
List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor);
if (parameterTypes.isEmpty()) {
if (constructor.getParameterCount() == 0) {
return new PreferredConstructor<>((Constructor<T>) constructor);
}
List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor);
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor);
Parameter<Object, P>[] parameters = new Parameter[parameterTypes.size()];