DATAMONGO-2086 - Fix Fluent API Kotlin extension generics to allow projections.

We now fixed Kotlin extension generics to properly use projections by ignoring the source type of the Fluent API object. Previously, the source and target type were linked which prevented the use of a different result type.

Original Pull Request: #609
This commit is contained in:
Mark Paluch
2018-09-13 21:18:02 +02:00
committed by Christoph Strobl
parent a79142931f
commit 2191ab3bba
4 changed files with 26 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,6 @@ fun <T : Any> ExecutableFindOperation.query(entityClass: KClass<T>): ExecutableF
inline fun <reified T : Any> ExecutableFindOperation.query(): ExecutableFindOperation.ExecutableFind<T> =
query(T::class.java)
/**
* Extension for [ExecutableFindOperation.FindWithProjection. as] providing a [KClass] based variant.
*
@@ -45,7 +44,7 @@ inline fun <reified T : Any> ExecutableFindOperation.query(): ExecutableFindOper
* @author Mark Paluch
* @since 2.0
*/
fun <T : Any> ExecutableFindOperation.FindWithProjection<T>.asType(resultType: KClass<T>): ExecutableFindOperation.FindWithQuery<T> =
fun <T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(resultType: KClass<T>): ExecutableFindOperation.FindWithQuery<T> =
`as`(resultType.java)
/**
@@ -55,7 +54,7 @@ fun <T : Any> ExecutableFindOperation.FindWithProjection<T>.asType(resultType: K
* @author Mark Paluch
* @since 2.0
*/
inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<T>.asType(): ExecutableFindOperation.FindWithQuery<T> =
inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(): ExecutableFindOperation.FindWithQuery<T> =
`as`(T::class.java)
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ inline fun <reified T : Any> ReactiveFindOperation.query(): ReactiveFindOperatio
* @author Mark Paluch
* @since 2.0
*/
fun <T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(resultType: KClass<T>): ReactiveFindOperation.FindWithQuery<T> =
fun <T : Any> ReactiveFindOperation.FindWithProjection<*>.asType(resultType: KClass<T>): ReactiveFindOperation.FindWithQuery<T> =
`as`(resultType.java)
/**
@@ -50,7 +50,7 @@ fun <T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(resultType: KCl
* @author Mark Paluch
* @since 2.0
*/
inline fun <reified T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(): ReactiveFindOperation.FindWithQuery<T> =
inline fun <reified T : Any> ReactiveFindOperation.FindWithProjection<*>.asType(): ReactiveFindOperation.FindWithQuery<T> =
`as`(T::class.java)
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,24 +53,24 @@ class ExecutableFindOperationExtensionsTests {
verify(operation).query(First::class.java)
}
@Test // DATAMONGO-1689
@Test // DATAMONGO-1689, DATAMONGO-2086
fun `ExecutableFindOperation#FindOperationWithProjection#asType(KClass) extension should call its Java counterpart`() {
operationWithProjection.asType(First::class)
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType(User::class)
verify(operationWithProjection).`as`(User::class.java)
}
@Test // DATAMONGO-1689
@Test // DATAMONGO-1689, DATAMONGO-2086
fun `ExecutableFindOperation#FindOperationWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {
operationWithProjection.asType()
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType<User>()
verify(operationWithProjection).`as`(User::class.java)
}
@Test // DATAMONGO-1761
@Test // DATAMONGO-1761, DATAMONGO-2086
fun `ExecutableFindOperation#DistinctWithProjection#asType(KClass) extension should call its Java counterpart`() {
distinctWithProjection.asType(First::class)
verify(distinctWithProjection).`as`(First::class.java)
distinctWithProjection.asType(User::class)
verify(distinctWithProjection).`as`(User::class.java)
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,24 +52,24 @@ class ReactiveFindOperationExtensionsTests {
verify(operation).query(First::class.java)
}
@Test // DATAMONGO-1719
@Test // DATAMONGO-1719, DATAMONGO-2086
fun `ReactiveFind#FindOperatorWithProjection#asType(KClass) extension should call its Java counterpart`() {
operationWithProjection.asType(First::class)
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType(User::class)
verify(operationWithProjection).`as`(User::class.java)
}
@Test // DATAMONGO-1719
@Test // DATAMONGO-1719, DATAMONGO-2086
fun `ReactiveFind#FindOperatorWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {
operationWithProjection.asType()
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType<User>()
verify(operationWithProjection).`as`(User::class.java)
}
@Test // DATAMONGO-1761
@Test // DATAMONGO-1761, DATAMONGO-2086
fun `ReactiveFind#DistinctWithProjection#asType(KClass) extension should call its Java counterpart`() {
distinctWithProjection.asType(First::class)
verify(distinctWithProjection).`as`(First::class.java)
distinctWithProjection.asType(User::class)
verify(distinctWithProjection).`as`(User::class.java)
}
}