Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Use consistently domain type instead of introducing a new terminology to repository infrastructure.

Rename Kotlin variant of ParameterUnitTests to KParameterUnitTests to avoid duplicate classes.

See #2770
Original pull request: #2771
  • Loading branch information
mp911de committed Feb 14, 2023
1 parent b775b6d commit b9fa290
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public final class DefaultParameters extends Parameters<DefaultParameters, Param
* Creates a new {@link DefaultParameters} instance from the given {@link Method}.
*
* @param method must not be {@literal null}.
* @deprecated since 3.1, use {@link #DefaultParameters(Method, TypeInformation)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
public DefaultParameters(Method method) {
super(method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,26 @@ public class Parameter {
* Creates a new {@link Parameter} for the given {@link MethodParameter}.
*
* @param parameter must not be {@literal null}.
* @deprecated since 3.1, use {@link #Parameter(MethodParameter, TypeInformation)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
protected Parameter(MethodParameter parameter) {
this(parameter, TypeInformation.of(Parameter.class));
}

/**
* Creates a new {@link Parameter} for the given {@link MethodParameter} and aggregate {@link TypeInformation}.
* Creates a new {@link Parameter} for the given {@link MethodParameter} and domain {@link TypeInformation}.
*
* @param parameter must not be {@literal null}.
* @param aggregateType must not be {@literal null}.
* @param domainType must not be {@literal null}.
* @since 3.0.2
*/
protected Parameter(MethodParameter parameter, TypeInformation<?> aggregateType) {
protected Parameter(MethodParameter parameter, TypeInformation<?> domainType) {

Assert.notNull(parameter, "MethodParameter must not be null");
Assert.notNull(aggregateType, "TypeInformation must not be null!");
Assert.notNull(domainType, "TypeInformation must not be null!");

this.parameter = parameter;
this.parameterType = potentiallyUnwrapParameterType(parameter);
this.isDynamicProjectionParameter = isDynamicProjectionParameter(parameter, aggregateType);
this.isDynamicProjectionParameter = isDynamicProjectionParameter(parameter, domainType);
this.name = isSpecialParameterType(parameter.getParameterType()) ? Lazy.of(Optional.empty()) : Lazy.of(() -> {
Param annotation = parameter.getParameterAnnotation(Param.class);
return Optional.ofNullable(annotation == null ? parameter.getParameterName() : annotation.value());
Expand Down Expand Up @@ -218,10 +217,10 @@ boolean isSort() {
* </code>
*
* @param parameter must not be {@literal null}.
* @param aggregateType the reference aggregate type, must not be {@literal null}.
* @param domainType the reference domain type, must not be {@literal null}.
* @return
*/
private static boolean isDynamicProjectionParameter(MethodParameter parameter, TypeInformation<?> aggregateType) {
private static boolean isDynamicProjectionParameter(MethodParameter parameter, TypeInformation<?> domainType) {

if (!parameter.getParameterType().equals(Class.class)) {
return false;
Expand All @@ -241,7 +240,7 @@ private static boolean isDynamicProjectionParameter(MethodParameter parameter, T
var unwrapped = QueryExecutionConverters.unwrapWrapperTypes(returnType);
var reactiveUnwrapped = ReactiveWrapperConverters.unwrapWrapperTypes(unwrapped);

if (aggregateType.isAssignableFrom(reactiveUnwrapped)) {
if (domainType.isAssignableFrom(reactiveUnwrapped)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
* Creates a new instance of {@link Parameters}.
*
* @param method must not be {@literal null}.
* @deprecated since 3.1, use {@link #Parameters(Method, Function)} instead.
*/
@SuppressWarnings("null")
@Deprecated(since = "3.1", forRemoval = true)
public Parameters(Method method) {
this(method, null);
}
Expand All @@ -77,6 +75,7 @@ public Parameters(Method method) {
*
* @param method must not be {@literal null}.
* @param parameterFactory must not be {@literal null}.
* @since 3.0.2
*/
protected Parameters(Method method, Function<MethodParameter, T> parameterFactory) {

Expand Down Expand Up @@ -176,10 +175,8 @@ private S getBindable() {
*
* @param parameter will never be {@literal null}.
* @return
* @deprecated since 3.1, in your extension, call {@link #Parameters(Method, ParameterFactory)} instead.
*/
@SuppressWarnings("unchecked")
@Deprecated(since = "3.1", forRemoval = true)
protected T createParameter(MethodParameter parameter) {
return (T) new Parameter(parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
Assert.notNull(metadata, "Repository metadata must not be null");
Assert.notNull(factory, "ProjectionFactory must not be null");

Parameters.TYPES.stream()
.filter(type -> getNumberOfOccurrences(method, type) > 1)
.findFirst().ifPresent(type -> {
throw new IllegalStateException(
String.format("Method must have only one argument of type %s; Offending method: %s",
type.getSimpleName(), method));
Parameters.TYPES.stream() //
.filter(type -> getNumberOfOccurrences(method, type) > 1).findFirst().ifPresent(type -> {
throw new IllegalStateException(String.format(
"Method must have only one argument of type %s; Offending method: %s", type.getSimpleName(), method));
});

this.method = method;
Expand Down Expand Up @@ -121,9 +119,7 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
*
* @param method must not be {@literal null}.
* @return must not return {@literal null}.
* @deprecated since 3.1, call or override {@link #createParameters(Method, TypeInformation)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
protected Parameters<?, ?> createParameters(Method method) {
return createParameters(method, metadata.getDomainTypeInformation());
}
Expand All @@ -132,11 +128,12 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
* Creates a {@link Parameters} instance.
*
* @param method must not be {@literal null}.
* @param aggregateType must not be {@literal null}.
* @param domainType must not be {@literal null}.
* @return must not return {@literal null}.
* @since 3.0.2
*/
protected Parameters<?, ?> createParameters(Method method, TypeInformation<?> aggregateType) {
return new DefaultParameters(method, aggregateType);
protected Parameters<?, ?> createParameters(Method method, TypeInformation<?> domainType) {
return new DefaultParameters(method, domainType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;

import org.jetbrains.annotations.NotNull;
Expand All @@ -34,6 +35,7 @@
* Unit tests for {@link Parameter}.
*
* @author Jens Schauder
* @author Oliver Drotbohm
*/
class ParameterUnitTests {

Expand Down Expand Up @@ -69,9 +71,9 @@ Stream<DynamicTest> doesNotConsiderClassParametersDynamicProjectionOnes() {
"staticReturnNonDynamicBindWildcard", //
"staticReturnNonDynamicBindWildcardExtends");

return DynamicTest.stream(methods, it -> it, it -> {
assertThat(new Parameter(getMethodParameter(it), TypeInformation.of(User.class))
.isDynamicProjectionParameter()).isFalse();
return DynamicTest.stream(methods, Function.identity(), it -> {
Parameter parameter = new Parameter(getMethodParameter(it), TypeInformation.of(User.class));
assertThat(parameter.isDynamicProjectionParameter()).isFalse();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import kotlin.reflect.jvm.javaMethod
*
* @author Mark Paluch
*/
class ParameterUnitTests {
class KParameterUnitTests {

@Test // DATACMNS-1508
fun `should consider Continuation a special parameter`() {
@Test // DATACMNS-1508
fun `should consider Continuation a special parameter`() {

val methodParameter =
MethodParameter(MyCoroutineRepository::hello.javaMethod!!, 0)
methodParameter.initParameterNameDiscovery(DefaultParameterNameDiscoverer())
val parameter = Parameter(methodParameter)
val methodParameter =
MethodParameter(MyCoroutineRepository::hello.javaMethod!!, 0)
methodParameter.initParameterNameDiscovery(DefaultParameterNameDiscoverer())
val parameter = Parameter(methodParameter)

assertThat(parameter.name).isEmpty()
assertThat(parameter.name).isEmpty()
assertThat(parameter.isBindable).isFalse()
}

Expand Down

0 comments on commit b9fa290

Please sign in to comment.