Browse Source

Polish Kotlin source code style

pull/1598/merge
sdeleuze 7 years ago
parent
commit
9f1d8517ba
  1. 1
      spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtensions.kt
  2. 22
      spring-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensions.kt
  3. 2
      spring-beans/src/test/kotlin/org/springframework/beans/BeanUtilsKotlinTests.kt
  4. 2
      spring-beans/src/test/kotlin/org/springframework/beans/factory/BeanFactoryExtensionsTests.kt
  5. 6
      spring-beans/src/test/kotlin/org/springframework/beans/factory/annotation/KotlinAutowiredTests.kt
  6. 27
      spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt
  7. 19
      spring-context/src/main/kotlin/org/springframework/context/support/GenericApplicationContextExtensions.kt
  8. 2
      spring-context/src/test/kotlin/org/springframework/context/annotation/AnnotationConfigApplicationContextExtensionsTests.kt
  9. 3
      spring-context/src/test/kotlin/org/springframework/ui/ModelExtensionsTests.kt
  10. 3
      spring-context/src/test/kotlin/org/springframework/ui/ModelMapExtensionsTests.kt
  11. 2
      spring-core/src/test/kotlin/org/springframework/core/env/PropertyResolverExtensionsTests.kt
  12. 38
      spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt
  13. 4
      spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceExtensions.kt
  14. 1
      spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt
  15. 2
      spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceExtensionsTests.kt
  16. 17
      spring-test/src/main/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensions.kt
  17. 1
      spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt
  18. 16
      spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt
  19. 14
      spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt
  20. 1
      spring-web/src/test/kotlin/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverKotlinTests.kt
  21. 1
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt
  22. 5
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt
  23. 19
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt
  24. 1
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt
  25. 2
      spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensionsTests.kt
  26. 8
      spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt
  27. 2
      spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt

1
spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtensions.kt

@ -16,7 +16,6 @@
package org.springframework.beans.factory package org.springframework.beans.factory
/** /**
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>()` variant. * Extension for [BeanFactory.getBean] providing a `getBean<Foo>()` variant.
* *

22
spring-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensions.kt

@ -17,13 +17,15 @@
package org.springframework.beans.factory package org.springframework.beans.factory
/** /**
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a `getBeanNamesForType<Foo>()` variant. * Extension for [ListableBeanFactory.getBeanNamesForType] providing a
* `getBeanNamesForType<Foo>()` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Array<out String> = inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true,
getBeanNamesForType(T::class.java, includeNonSingletons, allowEagerInit) allowEagerInit: Boolean = true): Array<out String> =
getBeanNamesForType(T::class.java, includeNonSingletons, allowEagerInit)
/** /**
* Extension for [ListableBeanFactory.getBeansOfType] providing a `getBeansOfType<Foo>()` variant. * Extension for [ListableBeanFactory.getBeansOfType] providing a `getBeansOfType<Foo>()` variant.
@ -31,11 +33,13 @@ inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonS
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Map<String, T> = inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true,
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit) allowEagerInit: Boolean = true): Map<String, T> =
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit)
/** /**
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a `getBeansOfType<Foo>()` variant. * Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a
* `getBeansOfType<Foo>()` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
@ -44,7 +48,8 @@ inline fun <reified T : Annotation> ListableBeanFactory.getBeanNamesForAnnotatio
getBeanNamesForAnnotation(T::class.java) getBeanNamesForAnnotation(T::class.java)
/** /**
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a `getBeansWithAnnotation<Foo>()` variant. * Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a
* `getBeansWithAnnotation<Foo>()` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
@ -53,7 +58,8 @@ inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation()
getBeansWithAnnotation(T::class.java) getBeansWithAnnotation(T::class.java)
/** /**
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a `findAnnotationOnBean<Foo>("foo")` variant. * Extension for [ListableBeanFactory.findAnnotationOnBean] providing a
* `findAnnotationOnBean<Foo>("foo")` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0

2
spring-beans/src/test/kotlin/org/springframework/beans/BeanUtilsKotlinTests.kt

@ -20,7 +20,7 @@ import org.junit.Assert.*
import org.junit.Test import org.junit.Test
/** /**
* Kotlin tests for {@link BeanUtils} * Kotlin tests for {@link BeanUtils}.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */

2
spring-beans/src/test/kotlin/org/springframework/beans/factory/BeanFactoryExtensionsTests.kt

@ -24,7 +24,7 @@ import org.mockito.Mockito.*
import org.mockito.junit.MockitoJUnitRunner import org.mockito.junit.MockitoJUnitRunner
/** /**
* Mock object based tests for BeanFactory Kotlin extensions * Mock object based tests for BeanFactory Kotlin extensions.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */

6
spring-beans/src/test/kotlin/org/springframework/beans/factory/annotation/KotlinAutowiredTests.kt

@ -231,7 +231,8 @@ class KotlinAutowiredTests {
val optional: String = "foo", val optional: String = "foo",
val injectedFromConstructor: TestBean val injectedFromConstructor: TestBean
) { ) {
@Autowired constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean, optional: String = "bar") : this(optional, injectedFromConstructor) { @Autowired constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean,
optional: String = "bar") : this(optional, injectedFromConstructor) {
this.injectedFromSecondaryConstructor = injectedFromSecondaryConstructor this.injectedFromSecondaryConstructor = injectedFromSecondaryConstructor
} }
@ -247,7 +248,8 @@ class KotlinAutowiredTests {
val optional: String = "foo", val optional: String = "foo",
val injectedFromConstructor: TestBean val injectedFromConstructor: TestBean
) { ) {
constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean, optional: String = "bar") : this(optional, injectedFromConstructor) { constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean,
optional: String = "bar") : this(optional, injectedFromConstructor) {
this.injectedFromSecondaryConstructor = injectedFromSecondaryConstructor this.injectedFromSecondaryConstructor = injectedFromSecondaryConstructor
} }

27
spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt

@ -71,11 +71,13 @@ fun beans(init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
* Class implementing functional bean definition Kotlin DSL. * Class implementing functional bean definition Kotlin DSL.
* *
* @constructor Create a new bean definition 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 * @author Sebastien Deleuze
* @since 5.0 * @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 @PublishedApi
internal val registrations = arrayListOf<(GenericApplicationContext) -> Unit>() 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. * Provide read access to some application context facilities.
* @constructor Create a new bean definition context. * @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) { 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 isLazyInit Set whether this bean should be lazily initialized.
* @param isPrimary Set whether this bean is a primary autowire candidate. * @param isPrimary Set whether this bean is a primary autowire candidate.
* @param autowireMode Set the autowire mode, `Autowire.CONSTRUCTOR` by default * @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 GenericApplicationContext.registerBean
* @see org.springframework.beans.factory.config.BeanDefinition * @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 isLazyInit Set whether this bean should be lazily initialized.
* @param isPrimary Set whether this bean is a primary autowire candidate. * @param isPrimary Set whether this bean is a primary autowire candidate.
* @param autowireMode Set the autowire mode, `Autowire.NO` by default * @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 * @param function the bean supplier function
* @see GenericApplicationContext.registerBean * @see GenericApplicationContext.registerBean
* @see org.springframework.beans.factory.config.BeanDefinition * @see org.springframework.beans.factory.config.BeanDefinition
@ -226,8 +231,10 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
registrations.add { registrations.add {
val beanContext = BeanDefinitionContext(it) val beanContext = BeanDefinitionContext(it)
when (name) { when (name) {
null -> it.registerBean(T::class.java, Supplier { function.invoke(beanContext) }, customizer) null -> it.registerBean(T::class.java,
else -> it.registerBean(name, T::class.java, Supplier { function.invoke(beanContext) }, customizer) 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 * Take in account bean definitions enclosed in the provided lambda only when the
* specified environment-based predicate is true. * 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) val beans = BeanDefinitionDsl(condition::invoke)
beans.init() beans.init()
children.add(beans) children.add(beans)

19
spring-context/src/main/kotlin/org/springframework/context/support/GenericApplicationContextExtensions.kt

@ -20,9 +20,9 @@ import org.springframework.beans.factory.config.BeanDefinitionCustomizer
import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContext
import java.util.function.Supplier 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 * @author Sebastien Deleuze
* @since 5.0 * @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 * @author Sebastien Deleuze
* @since 5.0 * @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) 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 * @author Sebastien Deleuze
* @since 5.0 * @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 * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
fun GenericApplicationContext(configure: GenericApplicationContext.() -> Unit) = GenericApplicationContext().apply(configure) fun GenericApplicationContext(configure: GenericApplicationContext.() -> Unit) =
GenericApplicationContext().apply(configure)

2
spring-context/src/test/kotlin/org/springframework/context/annotation/AnnotationConfigApplicationContextExtensionsTests.kt

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

3
spring-context/src/test/kotlin/org/springframework/ui/ModelExtensionsTests.kt

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

3
spring-context/src/test/kotlin/org/springframework/ui/ModelMapExtensionsTests.kt

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

2
spring-core/src/test/kotlin/org/springframework/core/env/PropertyResolverExtensionsTests.kt vendored

@ -24,7 +24,7 @@ import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner import org.mockito.junit.MockitoJUnitRunner
/** /**
* Mock object based tests for PropertyResolver Kotlin extensions * Mock object based tests for PropertyResolver Kotlin extensions.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */

38
spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt

@ -18,17 +18,18 @@ package org.springframework.jdbc.core
import java.sql.ResultSet import java.sql.ResultSet
/** /**
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...")` variant * Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...")` variant.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
*/ */
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String): T? = queryForObject(sql, T::class.java) inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String): T? =
queryForObject(sql, T::class.java)
/** /**
* Extensions for [JdbcOperations.queryForObject] providing a RowMapper-like function variant: `queryForObject("...", arg1, argN){ rs, i -> }`. * Extensions for [JdbcOperations.queryForObject] providing a RowMapper-like function
* variant: `queryForObject("...", arg1, argN){ rs, i -> }`.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
@ -37,7 +38,8 @@ fun <T : Any> JdbcOperations.queryForObject(sql: String, vararg args: Any, funct
queryForObject(sql, RowMapper { resultSet, i -> function(resultSet, i) }, *args) queryForObject(sql, RowMapper { resultSet, i -> function(resultSet, i) }, *args)
/** /**
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant * Extension for [JdbcOperations.queryForObject] providing a
* `queryForObject<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
@ -46,7 +48,8 @@ inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Ar
queryForObject(sql, args, argTypes, T::class.java) queryForObject(sql, args, argTypes, T::class.java)
/** /**
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...", arrayOf(arg1, argN))` variant * Extension for [JdbcOperations.queryForObject] providing a
* `queryForObject<Foo>("...", arrayOf(arg1, argN))` variant.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
@ -54,7 +57,6 @@ inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Ar
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? = inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? =
queryForObject(sql, args, T::class.java) queryForObject(sql, args, T::class.java)
/** /**
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant. * Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
* *
@ -66,17 +68,20 @@ inline fun <reified T : Any> JdbcOperations.queryForList(sql: String): List<T> =
queryForList(sql, T::class.java) queryForList(sql, T::class.java)
/** /**
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant * Extension for [JdbcOperations.queryForList] providing a
* `queryForList<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>, argTypes: IntArray): List<T> = inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>,
argTypes: IntArray): List<T> =
queryForList(sql, args, argTypes, T::class.java) queryForList(sql, args, argTypes, T::class.java)
/** /**
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...", arrayOf(arg1, argN))` variant * Extension for [JdbcOperations.queryForList] providing a
* `queryForList<Foo>("...", arrayOf(arg1, argN))` variant.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
@ -84,18 +89,20 @@ inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Arra
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> = inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> =
queryForList(sql, args, T::class.java) queryForList(sql, args, T::class.java)
/** /**
* Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function variant: `query<Foo>("...", arg1, argN){ rs -> }` * Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function
* variant: `query<Foo>("...", arg1, argN){ rs -> }`.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
*/ */
inline fun <reified T : Any> JdbcOperations.query(sql: String, vararg args: Any, crossinline function: (ResultSet) -> T): T? = inline fun <reified T : Any> JdbcOperations.query(sql: String, vararg args: Any,
crossinline function: (ResultSet) -> T): T? =
query(sql, ResultSetExtractor { function(it) }, *args) query(sql, ResultSetExtractor { function(it) }, *args)
/** /**
* Extension for [JdbcOperations.query] providing a RowCallbackHandler-like function variant: `query("...", arg1, argN){ rs -> }` * Extension for [JdbcOperations.query] providing a RowCallbackHandler-like function
* variant: `query("...", arg1, argN){ rs -> }`.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0
@ -104,7 +111,8 @@ fun JdbcOperations.query(sql: String, vararg args: Any, function: (ResultSet) ->
query(sql, RowCallbackHandler { function(it) }, *args) query(sql, RowCallbackHandler { function(it) }, *args)
/** /**
* Extensions for [JdbcOperations.query] providing a RowMapper-like function variant: `query("...", arg1, argN){ rs, i -> }`. * Extensions for [JdbcOperations.query] providing a RowMapper-like function variant:
* `query("...", arg1, argN){ rs, i -> }`.
* *
* @author Mario Arias * @author Mario Arias
* @since 5.0 * @since 5.0

4
spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceExtensions.kt

@ -17,7 +17,7 @@
package org.springframework.jdbc.core.namedparam package org.springframework.jdbc.core.namedparam
/** /**
* Extension for [MapSqlParameterSource.addValue] providing Array like setter * Extension for [MapSqlParameterSource.addValue] providing Array like setter.
* *
* ```kotlin * ```kotlin
* source["age"] = 3 * source["age"] = 3
@ -31,7 +31,7 @@ operator fun MapSqlParameterSource.set(paramName: String, value: Any) {
} }
/** /**
* Extension for [MapSqlParameterSource.addValue] providing Array like setter * Extension for [MapSqlParameterSource.addValue] providing Array like setter.
* *
* ```kotlin * ```kotlin
* source["age", JDBCType.INTEGER.vendorTypeNumber] = 3 * source["age", JDBCType.INTEGER.vendorTypeNumber] = 3

1
spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt

@ -16,7 +16,6 @@
package org.springframework.jdbc.core package org.springframework.jdbc.core
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith

2
spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceExtensionsTests.kt

@ -21,7 +21,7 @@ import org.junit.Test
import java.sql.JDBCType import java.sql.JDBCType
/** /**
* Tests for [MapSqlParameterSource] Kotlin extensions * Tests for [MapSqlParameterSource] Kotlin extensions.
* *
* @author Mario Arias * @author Mario Arias
*/ */

17
spring-test/src/main/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensions.kt

@ -17,42 +17,43 @@
package org.springframework.test.web.reactive.server package org.springframework.test.web.reactive.server
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.springframework.test.web.reactive.server.WebTestClient.*
/** /**
* Extension for [WebTestClient.RequestBodySpec.body] providing a variant without explicit class * Extension for [RequestBodySpec.body] providing a variant without explicit class
* parameter thanks to Kotlin reified type parameters. * parameter thanks to Kotlin reified type parameters.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
inline fun <reified T : Any, S : Publisher<T>> WebTestClient.RequestBodySpec.body(publisher: S): WebTestClient.RequestHeadersSpec<*> inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*>
= body(publisher, T::class.java) = body(publisher, T::class.java)
/** /**
* Extension for [WebTestClient.ResponseSpec.expectBody] providing a `expectBody<Foo>()` variant. * Extension for [ResponseSpec.expectBody] providing a `expectBody<Foo>()` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified B : Any> WebTestClient.ResponseSpec.expectBody(): WebTestClient.BodySpec<B, *> = inline fun <reified B : Any> ResponseSpec.expectBody(): BodySpec<B, *> =
expectBody(B::class.java) expectBody(B::class.java)
/** /**
* Extension for [WebTestClient.ResponseSpec.expectBodyList] providing a `expectBodyList<Foo>()` variant. * Extension for [ResponseSpec.expectBodyList] providing a `expectBodyList<Foo>()` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
inline fun <reified E : Any> WebTestClient.ResponseSpec.expectBodyList(): WebTestClient.ListBodySpec<E> = inline fun <reified E : Any> ResponseSpec.expectBodyList(): ListBodySpec<E> =
expectBodyList(E::class.java) expectBodyList(E::class.java)
/** /**
* Extension for [WebTestClient.ResponseSpec.returnResult] providing a `returnResult<Foo>()` variant. * Extension for [ResponseSpec.returnResult] providing a `returnResult<Foo>()` variant.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any> WebTestClient.ResponseSpec.returnResult(): FluxExchangeResult<T> = inline fun <reified T : Any> ResponseSpec.returnResult(): FluxExchangeResult<T> =
returnResult(T::class.java) returnResult(T::class.java)

1
spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt

@ -26,7 +26,6 @@ import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner import org.mockito.junit.MockitoJUnitRunner
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
/** /**
* Mock object based tests for [WebTestClient] Kotlin extensions * Mock object based tests for [WebTestClient] Kotlin extensions
* *

16
spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt

@ -23,7 +23,6 @@ import org.springframework.http.RequestEntity
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import java.net.URI import java.net.URI
/** /**
* Extension for [RestOperations.getForObject] avoiding specifying the type * Extension for [RestOperations.getForObject] avoiding specifying the type
* parameter thanks to Kotlin reified type parameters. * parameter thanks to Kotlin reified type parameters.
@ -117,7 +116,8 @@ inline fun <reified T: Any> RestOperations.postForObject(url: URI, request: Any)
* @since 5.0 * @since 5.0
*/ */
@Throws(RestClientException::class) @Throws(RestClientException::class)
inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any, vararg uriVariables: Any): ResponseEntity<T> = inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any,
vararg uriVariables: Any): ResponseEntity<T> =
postForEntity(url, request, T::class.java, *uriVariables) postForEntity(url, request, T::class.java, *uriVariables)
/** /**
@ -129,7 +129,8 @@ inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: A
* @since 5.0 * @since 5.0
*/ */
@Throws(RestClientException::class) @Throws(RestClientException::class)
inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any, uriVariables: Map<String, *>): ResponseEntity<T> = inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any,
uriVariables: Map<String, *>): ResponseEntity<T> =
postForEntity(url, request, T::class.java, uriVariables) postForEntity(url, request, T::class.java, uriVariables)
/** /**
@ -153,7 +154,8 @@ inline fun <reified T: Any> RestOperations.postForEntity(url: URI, request: Any)
* @since 5.0 * @since 5.0
*/ */
@Throws(RestClientException::class) @Throws(RestClientException::class)
inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>, vararg uriVariables: Any): ResponseEntity<T> = inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod,
requestEntity: HttpEntity<*>, vararg uriVariables: Any): ResponseEntity<T> =
exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}, *uriVariables) exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}, *uriVariables)
/** /**
@ -165,7 +167,8 @@ inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMet
* @since 5.0 * @since 5.0
*/ */
@Throws(RestClientException::class) @Throws(RestClientException::class)
inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>, uriVariables: Map<String, *>): ResponseEntity<T> = inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod,
requestEntity: HttpEntity<*>, uriVariables: Map<String, *>): ResponseEntity<T> =
exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}, uriVariables) exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}, uriVariables)
/** /**
@ -177,7 +180,8 @@ inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMet
* @since 5.0 * @since 5.0
*/ */
@Throws(RestClientException::class) @Throws(RestClientException::class)
inline fun <reified T: Any> RestOperations.exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>): ResponseEntity<T> = inline fun <reified T: Any> RestOperations.exchange(url: URI, method: HttpMethod,
requestEntity: HttpEntity<*>): ResponseEntity<T> =
exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}) exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {})
/** /**

14
spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt

@ -30,7 +30,7 @@ import org.springframework.http.RequestEntity
import java.net.URI import java.net.URI
/** /**
* Mock object based tests for [RestOperations] Kotlin extensions * Mock object based tests for [RestOperations] Kotlin extensions.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
@ -135,7 +135,8 @@ class RestOperationsExtensionsTests {
val var1 = "var1" val var1 = "var1"
val var2 = "var2" val var2 = "var2"
template.exchange<List<Foo>>(url, method, entity, var1, var2) template.exchange<List<Foo>>(url, method, entity, var1, var2)
verify(template, times(1)).exchange(url, method, entity, object : ParameterizedTypeReference<List<Foo>>() {}, var1, var2) verify(template, times(1)).exchange(url, method, entity,
object : ParameterizedTypeReference<List<Foo>>() {}, var1, var2)
} }
@Test @Test
@ -145,7 +146,8 @@ class RestOperationsExtensionsTests {
val entity = mock<HttpEntity<Foo>>() val entity = mock<HttpEntity<Foo>>()
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
template.exchange<List<Foo>>(url, method, entity, vars) template.exchange<List<Foo>>(url, method, entity, vars)
verify(template, times(1)).exchange(url, method, entity, object : ParameterizedTypeReference<List<Foo>>() {}, vars) verify(template, times(1)).exchange(url, method, entity,
object : ParameterizedTypeReference<List<Foo>>() {}, vars)
} }
@Test @Test
@ -154,14 +156,16 @@ class RestOperationsExtensionsTests {
val method = HttpMethod.GET val method = HttpMethod.GET
val entity = mock<HttpEntity<Foo>>() val entity = mock<HttpEntity<Foo>>()
template.exchange<List<Foo>>(url, method, entity) template.exchange<List<Foo>>(url, method, entity)
verify(template, times(1)).exchange(url, method, entity, object : ParameterizedTypeReference<List<Foo>>() {}) verify(template, times(1)).exchange(url, method, entity,
object : ParameterizedTypeReference<List<Foo>>() {})
} }
@Test @Test
fun `exchange with reified type parameters, String, HttpEntity`() { fun `exchange with reified type parameters, String, HttpEntity`() {
val entity = mock<RequestEntity<Foo>>() val entity = mock<RequestEntity<Foo>>()
template.exchange<List<Foo>>(entity) template.exchange<List<Foo>>(entity)
verify(template, times(1)).exchange(entity, object : ParameterizedTypeReference<List<Foo>>() {}) verify(template, times(1)).exchange(entity,
object : ParameterizedTypeReference<List<Foo>>() {})
} }
class Foo class Foo

1
spring-web/src/test/kotlin/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverKotlinTests.kt

@ -16,7 +16,6 @@
package org.springframework.web.method.annotation package org.springframework.web.method.annotation
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Before import org.junit.Before

1
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt

@ -21,7 +21,6 @@ import org.springframework.http.ResponseEntity
import reactor.core.publisher.Flux import reactor.core.publisher.Flux
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
/** /**
* Extension for [ClientResponse.bodyToMono] providing a `bodyToMono<Foo>()` variant * Extension for [ClientResponse.bodyToMono] providing a `bodyToMono<Foo>()` variant
* leveraging Kotlin reified type parameters. * leveraging Kotlin reified type parameters.

5
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt

@ -18,10 +18,11 @@ package org.springframework.web.reactive.function.client
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec
import reactor.core.publisher.Flux import reactor.core.publisher.Flux
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
/** /**
* Extension for [WebClient.RequestBodySpec.body] providing a `body<Foo>()` variant * Extension for [WebClient.RequestBodySpec.body] providing a `body<Foo>()` variant
* leveraging Kotlin reified type parameters. * leveraging Kotlin reified type parameters.
@ -30,7 +31,7 @@ import reactor.core.publisher.Mono
* @since 5.0 * @since 5.0
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any, S : Publisher<T>> WebClient.RequestBodySpec.body(publisher: S): WebClient.RequestHeadersSpec<*> = inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*> =
body(publisher, object : ParameterizedTypeReference<T>() {}) body(publisher, object : ParameterizedTypeReference<T>() {})
/** /**

19
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt

@ -21,10 +21,10 @@ import org.springframework.http.HttpMethod
import org.springframework.http.MediaType import org.springframework.http.MediaType
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
/** /**
* Allow to create easily a `RouterFunction<ServerResponse>` from a Kotlin router DSL based * Allow to create easily a `RouterFunction<ServerResponse>` from a Kotlin router DSL based
* on the same building blocks than the Java one ([RouterFunction], [RequestPredicate], [HandlerFunction]). * on the same building blocks than the Java one ([RouterFunction], [RequestPredicate],
* [HandlerFunction]).
* *
* Example: * Example:
* *
@ -126,9 +126,9 @@ open class RouterFunctionDsl {
operator fun RequestPredicate.not(): RequestPredicate = this.negate() operator fun RequestPredicate.not(): RequestPredicate = this.negate()
/** /**
* Route to the given router function if the given request predicate applies. This method can be * Route to the given router function if the given request predicate applies. This
* used to create *nested routes*, where a group of routes share a common path (prefix), * method can be used to create *nested routes*, where a group of routes share a
* header, or other request predicate. * common path (prefix), header, or other request predicate.
* @see RouterFunctions.nest * @see RouterFunctions.nest
*/ */
fun RequestPredicate.nest(r: RouterFunctionDsl.() -> Unit) { fun RequestPredicate.nest(r: RouterFunctionDsl.() -> Unit) {
@ -305,7 +305,8 @@ open class RouterFunctionDsl {
* @param headersPredicate a predicate that tests against the request headers * @param headersPredicate a predicate that tests against the request headers
* @return a predicate that tests against the given header predicate * @return a predicate that tests against the given header predicate
*/ */
fun headers(headersPredicate: (ServerRequest.Headers) -> Boolean): RequestPredicate = RequestPredicates.headers(headersPredicate) fun headers(headersPredicate: (ServerRequest.Headers) -> Boolean): RequestPredicate =
RequestPredicates.headers(headersPredicate)
/** /**
* Route to the given handler function if the given method predicate applies. * Route to the given handler function if the given method predicate applies.
@ -364,7 +365,8 @@ open class RouterFunctionDsl {
* predicate. * predicate.
* @see RequestPredicates.pathExtension * @see RequestPredicates.pathExtension
*/ */
fun pathExtension(predicate: (String) -> Boolean): RequestPredicate = RequestPredicates.pathExtension(predicate) fun pathExtension(predicate: (String) -> Boolean): RequestPredicate =
RequestPredicates.pathExtension(predicate)
/** /**
* Route to the given handler function if the given queryParam predicate applies. * Route to the given handler function if the given queryParam predicate applies.
@ -382,7 +384,8 @@ open class RouterFunctionDsl {
* @return a predicate that matches the given predicate against the query parameter of the given name * @return a predicate that matches the given predicate against the query parameter of the given name
* @see ServerRequest#queryParam(String) * @see ServerRequest#queryParam(String)
*/ */
fun queryParam(name: String, predicate: (String) -> Boolean): RequestPredicate = RequestPredicates.queryParam(name, predicate) fun queryParam(name: String, predicate: (String) -> Boolean): RequestPredicate =
RequestPredicates.queryParam(name, predicate)
/** /**
* Route to the given handler function if the given request predicate applies. * Route to the given handler function if the given request predicate applies.

1
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt

@ -20,7 +20,6 @@ import org.springframework.core.ParameterizedTypeReference
import reactor.core.publisher.Flux import reactor.core.publisher.Flux
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
/** /**
* Extension for [ServerRequest.bodyToMono] providing a `bodyToMono<Foo>()` variant * Extension for [ServerRequest.bodyToMono] providing a `bodyToMono<Foo>()` variant
* leveraging Kotlin reified type parameters. * leveraging Kotlin reified type parameters.

2
spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensionsTests.kt

@ -26,7 +26,7 @@ import org.mockito.junit.MockitoJUnitRunner
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
/** /**
* Mock object based tests for [ClientResponse] Kotlin extensions * Mock object based tests for [ClientResponse] Kotlin extensions.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */

8
spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt

@ -28,7 +28,7 @@ import reactor.test.StepVerifier
import java.net.URI import java.net.URI
/** /**
* Tests for [RouterFunction] Kotlin DSL * Tests for [RouterFunction] Kotlin DSL.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
@ -52,7 +52,11 @@ class RouterFunctionDslTests {
@Test @Test
fun acceptAndPOST() { fun acceptAndPOST() {
val request = builder().method(POST).uri(URI("/api/foo/")).header(ACCEPT, APPLICATION_JSON_VALUE).build() val request = builder()
.method(POST)
.uri(URI("/api/foo/"))
.header(ACCEPT, APPLICATION_JSON_VALUE)
.build()
StepVerifier.create(sampleRouter().route(request)) StepVerifier.create(sampleRouter().route(request))
.expectNextCount(1) .expectNextCount(1)
.verifyComplete() .verifyComplete()

2
spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt

@ -28,7 +28,7 @@ import org.springframework.web.reactive.function.server.bodyToFlux
import org.springframework.web.reactive.function.server.bodyToMono import org.springframework.web.reactive.function.server.bodyToMono
/** /**
* Mock object based tests for [ServerRequest] Kotlin extensions * Mock object based tests for [ServerRequest] Kotlin extensions.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */

Loading…
Cancel
Save