Polish Kotlin source code style

This commit is contained in:
sdeleuze
2017-11-21 15:14:01 +01:00
parent 5843173567
commit 9f1d8517ba
27 changed files with 130 additions and 91 deletions

View File

@@ -71,11 +71,13 @@ fun beans(init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
* Class implementing functional bean definition Kotlin DSL.
*
* @constructor Create a new bean definition DSL.
* @param condition the predicate to fulfill in order to take in account the inner bean definition block
* @param condition the predicate to fulfill in order to take in account the inner
* bean definition block
* @author Sebastien Deleuze
* @since 5.0
*/
open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) -> Boolean = { true }) : ApplicationContextInitializer<GenericApplicationContext> {
open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) -> Boolean = { true })
: ApplicationContextInitializer<GenericApplicationContext> {
@PublishedApi
internal val registrations = arrayListOf<(GenericApplicationContext) -> Unit>()
@@ -131,7 +133,8 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
/**
* Provide read access to some application context facilities.
* @constructor Create a new bean definition context.
* @param context the `ApplicationContext` instance to use for retrieving bean references, `Environment`, etc.
* @param context the `ApplicationContext` instance to use for retrieving bean
* references, `Environment`, etc.
*/
inner class BeanDefinitionContext(@PublishedApi internal val context: GenericApplicationContext) {
@@ -163,7 +166,8 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
* @param isLazyInit Set whether this bean should be lazily initialized.
* @param isPrimary Set whether this bean is a primary autowire candidate.
* @param autowireMode Set the autowire mode, `Autowire.CONSTRUCTOR` by default
* @param isAutowireCandidate Set whether this bean is a candidate for getting autowired into some other bean.
* @param isAutowireCandidate Set whether this bean is a candidate for getting
* autowired into some other bean.
* @see GenericApplicationContext.registerBean
* @see org.springframework.beans.factory.config.BeanDefinition
*/
@@ -200,7 +204,8 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
* @param isLazyInit Set whether this bean should be lazily initialized.
* @param isPrimary Set whether this bean is a primary autowire candidate.
* @param autowireMode Set the autowire mode, `Autowire.NO` by default
* @param isAutowireCandidate Set whether this bean is a candidate for getting autowired into some other bean.
* @param isAutowireCandidate Set whether this bean is a candidate for getting
* autowired into some other bean.
* @param function the bean supplier function
* @see GenericApplicationContext.registerBean
* @see org.springframework.beans.factory.config.BeanDefinition
@@ -226,8 +231,10 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
registrations.add {
val beanContext = BeanDefinitionContext(it)
when (name) {
null -> it.registerBean(T::class.java, Supplier { function.invoke(beanContext) }, customizer)
else -> it.registerBean(name, T::class.java, Supplier { function.invoke(beanContext) }, customizer)
null -> it.registerBean(T::class.java,
Supplier { function.invoke(beanContext) }, customizer)
else -> it.registerBean(name, T::class.java,
Supplier { function.invoke(beanContext) }, customizer)
}
}
}
@@ -246,9 +253,11 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
/**
* Take in account bean definitions enclosed in the provided lambda only when the
* specified environment-based predicate is true.
* @param condition the predicate to fulfill in order to take in account the inner bean definition block
* @param condition the predicate to fulfill in order to take in account the inner
* bean definition block
*/
fun environment(condition: ConfigurableEnvironment.() -> Boolean, init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
fun environment(condition: ConfigurableEnvironment.() -> Boolean,
init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
val beans = BeanDefinitionDsl(condition::invoke)
beans.init()
children.add(beans)

View File

@@ -20,9 +20,9 @@ import org.springframework.beans.factory.config.BeanDefinitionCustomizer
import org.springframework.context.ApplicationContext
import java.util.function.Supplier
/**
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean<Foo>()` variant.
* Extension for [GenericApplicationContext.registerBean] providing a
* `registerBean<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
@@ -32,12 +32,14 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(vararg custo
}
/**
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean<Foo>("foo")` variant.
* Extension for [GenericApplicationContext.registerBean] providing a
* `registerBean<Foo>("foo")` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> GenericApplicationContext.registerBean(beanName: String, vararg customizers: BeanDefinitionCustomizer) {
inline fun <reified T : Any> GenericApplicationContext.registerBean(beanName: String,
vararg customizers: BeanDefinitionCustomizer) {
registerBean(beanName, T::class.java, *customizers)
}
@@ -53,7 +55,8 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(
}
/**
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean("foo") { Foo() }` variant.
* Extension for [GenericApplicationContext.registerBean] providing a
* `registerBean("foo") { Foo() }` variant.
*
* @author Sebastien Deleuze
* @since 5.0
@@ -64,10 +67,12 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(name: String
}
/**
* Extension for [GenericApplicationContext] allowing `GenericApplicationContext { ... }` style initialization.
* Extension for [GenericApplicationContext] allowing `GenericApplicationContext { ... }`
* style initialization.
*
* @author Sebastien Deleuze
* @since 5.0
*/
fun GenericApplicationContext(configure: GenericApplicationContext.() -> Unit) = GenericApplicationContext().apply(configure)
fun GenericApplicationContext(configure: GenericApplicationContext.() -> Unit) =
GenericApplicationContext().apply(configure)

View File

@@ -22,7 +22,7 @@ import org.springframework.beans.factory.getBean
import org.springframework.context.support.registerBean
/**
* Tests for [AnnotationConfigApplicationContext] Kotlin extensions
* Tests for [AnnotationConfigApplicationContext] Kotlin extensions.
*
* @author Sebastien Deleuze
*/

View File

@@ -20,9 +20,8 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* Tests for [Model] Kotlin extensions
* Tests for [Model] Kotlin extensions.
*
* @author Sebastien Deleuze
*/

View File

@@ -20,9 +20,8 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* Tests for [ModelMap] Kotlin extensions
* Tests for [ModelMap] Kotlin extensions.
*
* @author Sebastien Deleuze
*/