Remove object wrappers in Kotlin extensions
This commit also improve significantly Kotlin extensions documentation. Issue: SPR-15127
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
package org.springframework.beans.factory
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory] providing [KClass] based API.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
object BeanFactoryExtension {
|
||||
|
||||
/**
|
||||
* @see BeanFactory.getBean(Class<T>)
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(requiredType: KClass<T>) = getBean(requiredType.java)
|
||||
|
||||
/**
|
||||
* @see BeanFactory.getBean(Class<T>)
|
||||
*/
|
||||
inline fun <reified T : Any> BeanFactory.getBean() = getBean(T::class.java)
|
||||
|
||||
/**
|
||||
* @see BeanFactory.getBean(String, Class<T>)
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(name: String, requiredType: KClass<T>) =
|
||||
getBean(name, requiredType.java)
|
||||
|
||||
/**
|
||||
* @see BeanFactory.getBean(String, Class<T>)
|
||||
*/
|
||||
inline fun <reified T : Any> BeanFactory.getBean(name: String) =
|
||||
getBean(name, T::class.java)
|
||||
|
||||
/**
|
||||
* @see BeanFactory.getBean(Class<T>, Object...)
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(requiredType: KClass<T>, vararg args:Any) =
|
||||
getBean(requiredType.java, *args)
|
||||
|
||||
/**
|
||||
* @see BeanFactory.getBean(Class<T>, Object...)
|
||||
*/
|
||||
inline fun <reified T : Any> BeanFactory.getBean(vararg args:Any) =
|
||||
getBean(T::class.java, *args)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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>) = getBean(requiredType.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> BeanFactory.getBean() = getBean(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @see BeanFactory.getBean(String, Class<T>)
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(name: String, requiredType: KClass<T>) =
|
||||
getBean(name, requiredType.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>("foo")` variant.
|
||||
*
|
||||
* @see BeanFactory.getBean(String, Class<T>)
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> BeanFactory.getBean(name: String) =
|
||||
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) =
|
||||
getBean(requiredType.java, *args)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>(arg1, arg2)` variant.
|
||||
*
|
||||
* @see BeanFactory.getBean(Class<T>, Object...)
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> BeanFactory.getBean(vararg args:Any) =
|
||||
getBean(T::class.java, *args)
|
||||
@@ -1,75 +0,0 @@
|
||||
package org.springframework.beans.factory
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory] providing [KClass] based API.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
object ListableBeanFactoryExtension {
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeanNamesForType(Class<?>, boolean, boolean)
|
||||
*/
|
||||
fun <T : Any> ListableBeanFactory.getBeanNamesForType(type: KClass<T>,
|
||||
includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true) =
|
||||
getBeanNamesForType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeanNamesForType(Class<?>, boolean, boolean)
|
||||
*/
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true) =
|
||||
getBeanNamesForType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeansOfType(Class<T>, boolean, boolean)
|
||||
*/
|
||||
fun <T : Any> ListableBeanFactory.getBeansOfType(type: KClass<T>,
|
||||
includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true) =
|
||||
getBeansOfType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeansOfType(Class<T>, boolean, boolean)
|
||||
*/
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true) =
|
||||
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeanNamesForAnnotation
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(type: KClass<T>) =
|
||||
getBeanNamesForAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeanNamesForAnnotation
|
||||
*/
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation() =
|
||||
getBeanNamesForAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeansWithAnnotation
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.getBeansWithAnnotation(type: KClass<T>) =
|
||||
getBeansWithAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactory.getBeansWithAnnotation
|
||||
*/
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation() =
|
||||
getBeansWithAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactoryExtension.findAnnotationOnBean
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String, type: KClass<T>) =
|
||||
findAnnotationOnBean(beanName, type.java)
|
||||
|
||||
/**
|
||||
* @see ListableBeanFactoryExtension.findAnnotationOnBean
|
||||
*/
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String) =
|
||||
findAnnotationOnBean(beanName, T::class.java)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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) =
|
||||
getBeanNamesForType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a `getBeanNamesForType<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true) =
|
||||
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) =
|
||||
getBeansOfType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansOfType] providing a `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true) =
|
||||
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>) =
|
||||
getBeanNamesForAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation() =
|
||||
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>) =
|
||||
getBeansWithAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a `getBeansWithAnnotation<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation() =
|
||||
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>) =
|
||||
findAnnotationOnBean(beanName, type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a `findAnnotationOnBean<Foo>("foo")` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String) =
|
||||
findAnnotationOnBean(beanName, T::class.java)
|
||||
|
||||
Reference in New Issue
Block a user