Remove KClass based Kotlin extensions
Issue: SPR-15660
This commit is contained in:
@@ -1,15 +1,5 @@
|
||||
package org.springframework.beans.factory
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(requiredType: KClass<T>): T = getBean(requiredType.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>()` variant.
|
||||
@@ -30,16 +20,6 @@ inline fun <reified T : Any> BeanFactory.getBean(): T = getBean(T::class.java)
|
||||
inline fun <reified T : Any> BeanFactory.getBean(name: String): T =
|
||||
getBean(name, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @see BeanFactory.getBean(Class<T>, Object...)
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(requiredType: KClass<T>, vararg args:Any): T =
|
||||
getBean(requiredType.java, *args)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>(arg1, arg2)` variant.
|
||||
*
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
package org.springframework.beans.factory
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ListableBeanFactory.getBeanNamesForType(type: KClass<T>,
|
||||
includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Array<out String> =
|
||||
getBeanNamesForType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a `getBeanNamesForType<Foo>()` variant.
|
||||
*
|
||||
@@ -22,15 +9,6 @@ fun <T : Any> ListableBeanFactory.getBeanNamesForType(type: KClass<T>,
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Array<out String> =
|
||||
getBeanNamesForType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansOfType] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ListableBeanFactory.getBeansOfType(type: KClass<T>, includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Map<String, Any> =
|
||||
getBeansOfType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansOfType] providing a `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
@@ -40,15 +18,6 @@ fun <T : Any> ListableBeanFactory.getBeansOfType(type: KClass<T>, includeNonSing
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Map<String, Any> =
|
||||
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(type: KClass<T>): Array<out String> =
|
||||
getBeanNamesForAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
@@ -58,15 +27,6 @@ fun <T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(type: KClass<
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(): Array<out String> =
|
||||
getBeanNamesForAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.getBeansWithAnnotation(type: KClass<T>): MutableMap<String, Any> =
|
||||
getBeansWithAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a `getBeansWithAnnotation<Foo>()` variant.
|
||||
*
|
||||
@@ -76,15 +36,6 @@ fun <T : Annotation> ListableBeanFactory.getBeansWithAnnotation(type: KClass<T>)
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation(): MutableMap<String, Any> =
|
||||
getBeansWithAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String, type: KClass<T>): Annotation? =
|
||||
findAnnotationOnBean(beanName, type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a `findAnnotationOnBean<Foo>("foo")` variant.
|
||||
*
|
||||
|
||||
@@ -18,12 +18,6 @@ class BeanFactoryExtensionsTests {
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bf: BeanFactory
|
||||
|
||||
@Test
|
||||
fun `getBean with KClass`() {
|
||||
bf.getBean(Foo::class)
|
||||
verify(bf, times(1)).getBean(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters`() {
|
||||
bf.getBean<Foo>()
|
||||
@@ -37,14 +31,6 @@ class BeanFactoryExtensionsTests {
|
||||
verify(bf, times(1)).getBean(name, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with KClass and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
val arg2 = "arg2"
|
||||
bf.getBean(Foo::class, arg1, arg2)
|
||||
verify(bf, times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
|
||||
@@ -18,24 +18,6 @@ class ListableBeanFactoryExtensionsTests {
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var lbf: ListableBeanFactory
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass`() {
|
||||
lbf.getBeanNamesForType(Foo::class)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters`() {
|
||||
lbf.getBeanNamesForType<Foo>()
|
||||
@@ -54,24 +36,6 @@ class ListableBeanFactoryExtensionsTests {
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass`() {
|
||||
lbf.getBeansOfType(Foo::class)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters`() {
|
||||
lbf.getBeansOfType<Foo>()
|
||||
@@ -90,37 +54,18 @@ class ListableBeanFactoryExtensionsTests {
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with KClass`() {
|
||||
lbf.getBeanNamesForAnnotation(Bar::class)
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with reified type parameters`() {
|
||||
lbf.getBeanNamesForAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with KClass`() {
|
||||
lbf.getBeansWithAnnotation(Bar::class)
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with reified type parameters`() {
|
||||
lbf.getBeansWithAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and KClass`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean(name, Bar::class)
|
||||
verify(lbf, times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and reified type parameters`() {
|
||||
val name = "bar"
|
||||
|
||||
Reference in New Issue
Block a user