Skip to content

Commit

Permalink
Merge branch '1.4.0' into empty-package-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kibettheophilus authored Oct 15, 2024
2 parents c4ae781 + 2ae4175 commit 3b1a9b5
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/reference/koin-annotations/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The Koin compiler offers some options to configure. Following the official doc,

### Compile Safety - check your Koin config at compile time (since 1.3.0)

Koin Annotations allows the compiler plugin to verify yout Koin configuration at compile time. This can be activated with the following Ksp options, to add to your Gradle module:
Koin Annotations allows the compiler plugin to verify your Koin configuration at compile time. This can be activated with the following Ksp options, to add to your Gradle module:

```groovy
// in build.gradle or build.gradle.kts
Expand All @@ -78,7 +78,7 @@ class MyPresenter(@Provided val provided : MyProvidedComponent)

### Disabling Default Module (since 1.3.0)

By default, the Koibn compiler detect any definition not bound to a module and put it in a "default mmodule", a Koin module generated at the root of your project. You can disable the use and generation of default module with the following option:
By default, the Koin compiler detect any definition not bound to a module and put it in a "default module", a Koin module generated at the root of your project. You can disable the use and generation of default module with the following option:

```groovy
// in build.gradle or build.gradle.kts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.koin.sample.androidx

import RootModule
import it.example.component.ExampleSingleton
import org.junit.Test
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
Expand Down Expand Up @@ -38,6 +39,9 @@ class AndroidModuleTest {
assert(koin.getOrNull<DataConsumer>() != null)
assert(koin.getOrNull<MyDataConsumer>() != null)

assert(koin.getOrNull<ExampleSingleton>() != null)


stopKoin()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.example.component

import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module
import org.koin.core.annotation.Single

@Module
@ComponentScan
class ExampleModule

@Single
class ExampleSingleton
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.koin.sample.android.library

import it.example.component.ExampleModule
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module

@Module
@Module(includes = [ExampleModule::class])
@ComponentScan
class CommonModule
2 changes: 1 addition & 1 deletion examples/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Core
kotlin = "1.9.24"
koin = "3.5.6"
koinAnnotations = "1.4.0-RC4"
koinAnnotations = "1.4.0"
ksp = "1.9.24-1.0.20"
junit = "4.13.2"
# Android
Expand Down
2 changes: 1 addition & 1 deletion projects/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.parallel=true
#Kotlin
kotlin.code.style=official
#Koin
koinAnnotationsVersion=1.4.0-RC4
koinAnnotationsVersion=1.4.0
#Android
android.useAndroidX=true
androidMinSDK=14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ class BuilderProcessor(
//TODO Use Koin 4.0 ViewModel DSL
@Deprecated("use isKoinComposeViewModelActive")
private fun isComposeViewModelActive(): Boolean {
logger.warn("[Deprecated] 'USE_COMPOSE_VIEWMODEL' arg is deprecated. Please use 'KOIN_USE_COMPOSE_VIEWMODEL'")
return options.getOrDefault(USE_COMPOSE_VIEWMODEL.name, "false") == true.toString()
val option = options.getOrDefault(USE_COMPOSE_VIEWMODEL.name, "false") == true.toString()
if (option) logger.warn("[Deprecated] 'USE_COMPOSE_VIEWMODEL' arg is deprecated. Please use 'KOIN_USE_COMPOSE_VIEWMODEL'")
return option
}

private fun isKoinComposeViewModelActive(): Boolean {
logger.warn("Activate Compose ViewModel for @KoinViewModel generation")
return options.getOrDefault(KOIN_USE_COMPOSE_VIEWMODEL.name, "false") == true.toString()
val option =
options.getOrDefault(KOIN_USE_COMPOSE_VIEWMODEL.name, "false") == true.toString()
if (option) logger.warn("Activate Compose ViewModel for @KoinViewModel generation")
return option
}

//TODO turn KOIN_DEFAULT_MODULE to false by default - Next Major version (breaking)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DefinitionWriter(
}

private fun List<KoinMetaData.DefinitionParameter>.generateParamFunction(): String {
return if (any { it is KoinMetaData.DefinitionParameter.ParameterInject }) "params -> " else ""
return if (any { it is KoinMetaData.DefinitionParameter.ParameterInject }) "params -> " else "_ -> "
}

private fun String?.generateQualifier(): String = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class KoinCodeGenerator(

if (defaultModule.alreadyGenerated == false && hasDefaultDefinitions){
defaultModule.setCurrentDefinitionsToExternals()
DefaultModuleWriter(codeGenerator, resolver, defaultModule, generateDefaultModule).writeModule()
DefaultModuleWriter(codeGenerator, resolver, defaultModule, generateDefaultModule).writeModule(isComposeViewModelActive)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class ModuleWriter(
private val generatedField = "${module.packageName("_")}_${module.name}"

//TODO Remove isComposeViewModelActive with Koin 4
fun writeModule(isComposeViewModelActive: Boolean = false) {
fun writeModule(isComposeViewModelActive: Boolean) {
fileStream = createFileStream()
definitionFactory = DefinitionWriterFactory(resolver, fileStream!!)

Expand Down Expand Up @@ -88,11 +88,11 @@ abstract class ModuleWriter(
}

open fun writeHeader() {
write(MODULE_HEADER)
writeln(MODULE_HEADER)
}

open fun writeHeaderImports(isComposeViewModelActive: Boolean) {
write(generateImports(module.definitions, isComposeViewModelActive))
writeln(generateImports(module.definitions, isComposeViewModelActive))
}

private fun generateImports(
Expand All @@ -108,7 +108,7 @@ abstract class ModuleWriter(
keyword.import?.let { "import $it" }
}
}
.joinToString(separator = "\n", postfix = "\n")
.joinToString(separator = "\n")
}

open fun writeExternalDefinitions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal fun List<KSValueArgument>.getValueArgument(): String? {

fun KSClassDeclaration.getPackageName() : String = packageName.asString()

val forbiddenKeywords = listOf("interface","it")
val forbiddenKeywords = listOf("in","interface")
fun String.filterForbiddenKeywords() : String{
return split(".").joinToString(".") {
if (it in forbiddenKeywords) "`$it`" else it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class KoinTagWriter(val codeGenerator: CodeGenerator, val logger: KSPLogger) {
fileStream: OutputStream,
alreadyDeclared: java.util.ArrayList<String>
) {
LOGGER.logging("tag: $tagName")
// LOGGER.logging("tag: $tagName")
val tag = "public class $tagPrefix$tagName"
fileStream.appendText("\n$tag")
alreadyDeclared.add(tagName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ internal val typeWhiteList = listOf(
"androidx.appcompat.app.AppCompatActivity",
"androidx.appcompat.app.AppCompatActivity",
"androidx.fragment.app.Fragment",
"androidx.lifecycle.SavedStateHandle"
"androidx.lifecycle.SavedStateHandle",
"androidx.lifecycle.ViewModel"
)

0 comments on commit 3b1a9b5

Please sign in to comment.