Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove object wrappers in Kotlin extensions
This commit also improve significantly Kotlin extensions documentation. Issue: SPR-15127
- Loading branch information
Showing
23 changed files
with
535 additions
and
466 deletions.
There are no files selected for viewing
47 changes: 0 additions & 47 deletions
47
spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtension.kt
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
75 changes: 0 additions & 75 deletions
75
...g-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtension.kt
This file was deleted.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
...-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
14 changes: 0 additions & 14 deletions
14
...lin/org/springframework/context/annotation/AnnotationConfigApplicationContextExtension.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...in/org/springframework/context/annotation/AnnotationConfigApplicationContextExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
65 changes: 0 additions & 65 deletions
65
...src/main/kotlin/org/springframework/context/support/GenericApplicationContextExtension.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.