Skip to content

Commit

Permalink
Fix spring-projects-experimental#55 - Code style not in line with Kot…
Browse files Browse the repository at this point in the history
…lin Coding Conventions
  • Loading branch information
AlexCzar authored and sdeleuze committed Jul 5, 2018
1 parent f667aff commit 56a38f7
Show file tree
Hide file tree
Showing 60 changed files with 672 additions and 515 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ The project can be built from the root directory using the standard Gradle comma
$ ./gradlew build
----

==== Source code style
With small exceptions described below Spring Fu uses official https://kotlinlang.org/docs/reference/coding-conventions.html[Kotlin Coding Conventions] (aka Kotlin Style Guide). Description and instructions on how to set it are provided at the link above.

After following the instructions at the link above open Settings → Editor → Code style → Kotlin and on 'Tabls and Indents' tab check the 'Use tab character' checkbocks. Indentation in Spring projects is universally done with TAB character. Smart tabs must be disabled.


==== Documentation

Documentation can be built via the following Gradle command:
Expand Down
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ allprojects {
username = repoUsername
password = repoPassword
}
url = uri(if (version.toString().endsWith(".BUILD-SNAPSHOT")) "https://repo.spring.io/libs-snapshot-local/" else "https://repo.spring.io/libs-release-local/")
url = uri(
if (version.toString().endsWith(".BUILD-SNAPSHOT")) "https://repo.spring.io/libs-snapshot-local/"
else "https://repo.spring.io/libs-release-local/"
)

} else {
url = uri("$buildDir/repo")
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/kotlin/org/springframework/fu/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package org.springframework.fu
import org.springframework.context.support.GenericApplicationContext
import java.util.function.Supplier

open class ConfigurationModule<T : Any>(private val init: ConfigurationModule<T>.() -> T, private val clazz: Class<T>): AbstractModule() {
open class ConfigurationModule<T : Any>(
private val init: ConfigurationModule<T>.() -> T, private val clazz: Class<T>
) : AbstractModule() {

override fun initialize(context: GenericApplicationContext) {
this.context = context
Expand All @@ -12,4 +14,5 @@ open class ConfigurationModule<T : Any>(private val init: ConfigurationModule<T>
}
}

inline fun <reified T : Any> configuration(noinline init: ConfigurationModule<*>.() -> T) = ConfigurationModule(init, T::class.java)
inline fun <reified T : Any> configuration(noinline init: ConfigurationModule<*>.() -> T) =
ConfigurationModule(init, T::class.java)
10 changes: 5 additions & 5 deletions core/src/main/kotlin/org/springframework/fu/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import org.springframework.core.env.Environment
annotation class ModuleMarker

@ModuleMarker
interface Module: ApplicationContextInitializer<GenericApplicationContext> {
interface Module : ApplicationContextInitializer<GenericApplicationContext> {

var context: GenericApplicationContext

val env : Environment
val env: Environment
get() = context.environment

val profiles : Array<String>
val profiles: Array<String>
get() = env.activeProfiles
}

Expand All @@ -26,12 +26,12 @@ interface Module: ApplicationContextInitializer<GenericApplicationContext> {
* @param name the name of the bean to retrieve
* @param T type the bean must match, can be an interface or superclass
*/
inline fun <reified T : Any> Module.ref(name: String? = null) : T = when (name) {
inline fun <reified T : Any> Module.ref(name: String? = null): T = when (name) {
null -> context.getBean(T::class.java)
else -> context.getBean(name, T::class.java)
}

abstract class AbstractModule: Module {
abstract class AbstractModule : Module {

override lateinit var context: GenericApplicationContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ApplicationDslTests {
class Foo

data class TestConfiguration(
val name: String
val name: String
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import javax.script.ScriptEngineManager
*/
class DynamicConfigurationModule(private val filename: String) : AbstractModule() {

override fun initialize(context : GenericApplicationContext) {
override fun initialize(context: GenericApplicationContext) {
if (!context.containsBean("kotlinScriptEngine")) {
context.registerBean("kotlinScriptEngine") {
ScriptEngineManager(context.classLoader).getEngineByName("kotlin")
Expand All @@ -44,7 +44,7 @@ class DynamicConfigurationModule(private val filename: String) : AbstractModule(
}
}

fun ApplicationDsl.configuration(filename: String = "application.kts") : DynamicConfigurationModule {
fun ApplicationDsl.configuration(filename: String = "application.kts"): DynamicConfigurationModule {
val configuration = DynamicConfigurationModule(filename)
initializers.add(configuration)
return configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ class DynamicConfigurationModuleTests {
}

data class TestConfiguration(
val name: String
val name: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ inline fun <reified T> LoggingDsl.level(level: LogLevel) {
}

data class LoggingConfiguration(
var level: LogLevel = LogLevel.INFO,
var packagesLevels: MutableList<Pair<String, LogLevel>> = mutableListOf()
var level: LogLevel = LogLevel.INFO,
var packagesLevels: MutableList<Pair<String, LogLevel>> = mutableListOf()
)

fun ApplicationDsl.logging(init: LoggingDsl.() -> Unit): LoggingDsl =
LoggingDsl(init)
LoggingDsl(init)
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ internal class LoggingDslTest {

assertEquals(INFO, log.configuration.level)
assertEquals(
listOf("org.springframework" to DEBUG),
log.configuration.packagesLevels)
listOf("org.springframework" to DEBUG),
log.configuration.packagesLevels
)
}

@Test
Expand All @@ -91,7 +92,8 @@ internal class LoggingDslTest {

assertEquals(INFO, log.configuration.level)
assertEquals(
listOf("org.springframework.beans.factory.support.DefaultListableBeanFactory" to DEBUG),
log.configuration.packagesLevels)
listOf("org.springframework.beans.factory.support.DefaultListableBeanFactory" to DEBUG),
log.configuration.packagesLevels
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import com.mongodb.reactivestreams.client.MongoCollection
* See [MongoCollection]
*/
interface CoroutineMongoCollection<TDocument> {
val mongoCollection: MongoCollection<TDocument>
val mongoCollection: MongoCollection<TDocument>
}

data class DefaultCoroutineMongoCollection<TDocument>(
override val mongoCollection: MongoCollection<TDocument>
): CoroutineMongoCollection<TDocument>
override val mongoCollection: MongoCollection<TDocument>
) : CoroutineMongoCollection<TDocument>

internal fun <T> MongoCollection<T>.asCoroutineMongoCollection(): CoroutineMongoCollection<T> =
DefaultCoroutineMongoCollection(this)
DefaultCoroutineMongoCollection(this)
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class CoroutineMongoModule : AbstractModule() {
val registry = (beanFactory as BeanDefinitionRegistry) //TODO: fix this hack

registry.beanDefinitionNames
.filter { it.startsWith("coroutine_") }
.map { it.substringAfter("coroutine_") }
.forEach {
registry.removeBeanDefinition(it)
registry.registerAlias("coroutine_$it", it)
}
.filter { it.startsWith("coroutine_") }
.map { it.substringAfter("coroutine_") }
.forEach {
registry.removeBeanDefinition(it)
registry.registerAlias("coroutine_$it", it)
}
}

}
}
}

fun MongoModule.coroutine() : CoroutineMongoModule {
fun MongoModule.coroutine(): CoroutineMongoModule {
val coroutineModule = CoroutineMongoModule()
initializers.add(coroutineModule)
return coroutineModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import org.springframework.fu.module.data.mongodb.coroutine.data.mongodb.core.Co
import org.springframework.data.mongodb.core.query.Query

suspend inline fun <reified T : Any> CoroutineMongoTemplate.findById(id: Any) =
findById(id, T::class.java)
findById(id, T::class.java)

suspend inline fun <reified T : Any> CoroutineMongoTemplate.find(query: Query = Query()) =
find(query, T::class.java)
find(query, T::class.java)

suspend inline fun <reified T : Any> CoroutineMongoTemplate.findAll() =
findAll(T::class.java)
findAll(T::class.java)

suspend inline fun <reified T : Any> CoroutineMongoTemplate.count(query: Query = Query()) =
count(query, T::class.java)
count(query, T::class.java)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
suspend inline fun <reified T : Any> CoroutineMongoTemplate.remove(query: Query = Query()) =
remove(query, T::class.java)
remove(query, T::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.bson.Document
import org.springframework.data.mongodb.core.ReactiveCollectionCallback

interface CoroutineCollectionCallback<T> {
val reactiveCollectionCallback: ReactiveCollectionCallback<T>
val reactiveCollectionCallback: ReactiveCollectionCallback<T>

suspend fun doInCollection(collection: CoroutineMongoCollection<Document>): List<T>
suspend fun doInCollection(collection: CoroutineMongoCollection<Document>): List<T>
}
Loading

0 comments on commit 56a38f7

Please sign in to comment.