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.
This commit is contained in:
committed by
Christoph Strobl
parent
f79d98ce23
commit
3a895588c8
@@ -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.
|
||||
@@ -25,7 +25,7 @@ import kotlin.reflect.KClass
|
||||
* @since 2.0
|
||||
*/
|
||||
fun <T : Any> ExecutableFindOperation.query(entityClass: KClass<T>): ExecutableFindOperation.ExecutableFind<T> =
|
||||
query(entityClass.java)
|
||||
query(entityClass.java)
|
||||
|
||||
/**
|
||||
* Extension for [ExecutableFindOperation.query] leveraging reified type parameters.
|
||||
@@ -35,8 +35,7 @@ fun <T : Any> ExecutableFindOperation.query(entityClass: KClass<T>): ExecutableF
|
||||
* @since 2.0
|
||||
*/
|
||||
inline fun <reified T : Any> ExecutableFindOperation.query(): ExecutableFindOperation.ExecutableFind<T> =
|
||||
query(T::class.java)
|
||||
|
||||
query(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ExecutableFindOperation.FindWithProjection. as] providing a [KClass] based variant.
|
||||
@@ -45,8 +44,8 @@ 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> =
|
||||
`as`(resultType.java)
|
||||
fun <T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(resultType: KClass<T>): ExecutableFindOperation.FindWithQuery<T> =
|
||||
`as`(resultType.java)
|
||||
|
||||
/**
|
||||
* Extension for [ExecutableFindOperation.FindWithProjection. as] leveraging reified type parameters.
|
||||
@@ -55,7 +54,5 @@ 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> =
|
||||
`as`(T::class.java)
|
||||
|
||||
|
||||
inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(): ExecutableFindOperation.FindWithQuery<T> =
|
||||
`as`(T::class.java)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -50,18 +50,17 @@ 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -49,17 +49,17 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user