Skip to content

Commit

Permalink
Remove object wrappers in Kotlin extensions
Browse files Browse the repository at this point in the history
This commit also improve significantly Kotlin extensions
documentation.

Issue: SPR-15127
  • Loading branch information
sdeleuze committed Jan 11, 2017
1 parent 4f1fe74 commit 0a988fd
Show file tree
Hide file tree
Showing 23 changed files with 535 additions and 466 deletions.

This file was deleted.

@@ -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)

This file was deleted.

@@ -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)

This file was deleted.

@@ -0,0 +1,11 @@
package org.springframework.context.annotation

/**
* Extension for [AnnotationConfigApplicationContext] allowing
* `AnnotationConfigApplicationContext { ... }` style initialization.
*
* @author Sebastien Deleuze
* @since 5.0
*/
fun AnnotationConfigApplicationContext(configure: AnnotationConfigApplicationContext.()->Unit) =
AnnotationConfigApplicationContext().apply(configure)

This file was deleted.

0 comments on commit 0a988fd

Please sign in to comment.