### Koin Application Setup and Module Loading Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/qualifier_dotted_name.fir.ir.txt Initializes a Koin application and loads specified modules. This example demonstrates setting up data and UI modules. ```kotlin VAR name:koin type:org.koin.core.Koin [val] CALL 'public final fun (): org.koin.core.Koin declared in org.koin.core.KoinApplication' type=org.koin.core.Koin origin=GET_PROPERTY ARG : CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun modules (vararg modules: org.koin.core.module.Module): org.koin.core.KoinApplication declared in org.koin.core.KoinApplication' type=org.koin.core.KoinApplication origin=null ARG : GET_VAR '$this$koinApplication: org.koin.core.KoinApplication declared in .box.' type=org.koin.core.KoinApplication origin=IMPLICIT_ARGUMENT ARG modules: VARARG type=kotlin.Array varargElementType=org.koin.core.module.Module CALL 'public final fun module (: .DataModule): org.koin.core.module.Module declared in ' type=org.koin.core.module.Module origin=null ARG : CONSTRUCTOR_CALL 'public constructor () declared in .DataModule' type=.DataModule origin=null CALL 'public final fun module (: .UiModule): org.koin.core.module.Module declared in ' type=org.koin.core.module.Module origin=null ARG : CONSTRUCTOR_CALL 'public constructor () declared in .UiModule' type=.UiModule origin=null ``` -------------------------------- ### Koin Application Setup and Get Greeter Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/injected_param_dual_definition_single_hint.fir.txt Sets up a Koin application with 'FirstModule' and 'SecondModule', then retrieves an instance of 'Greeter' providing a 'World' string parameter. This demonstrates how to configure and use Koin with injected parameters. ```kotlin public final fun box(): R|kotlin/String| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(vararg(R|/FirstModule.FirstModule|().R|/module|(), R|/SecondModule.SecondModule|().R|/module|())) } ).R|org/koin/core/KoinApplication.koin| lval greeter: R|Greeter| = R|/koin|.R|org/koin/core/Koin.get|( = get@fun (): R|org/koin/core/parameter/ParametersHolder| { ^ R|org/koin/core/parameter/parametersOf|(vararg(String(World))) } ) ^box when () { ==(R|/greeter|.R|/Greeter.name|, String(World)) -> { String(OK) } else -> { String(FAIL: @InjectedParam not working) } } } ``` -------------------------------- ### Koin Application Setup and Service Retrieval (Kotlin) Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/startkoin/startkoin_basic.fir.txt This snippet demonstrates how to set up Koin, define a module, and retrieve a service. It includes starting and stopping Koin, and verifying service availability. Dependencies include Koin core annotations and context functions. ```kotlin import org.koin.core.context.startKoin import org.koin.core.context.stopKoin import org.koin.core.Koin import org.koin.core.annotation.ComponentScan import org.koin.core.annotation.Module import org.koin.core.annotation.Singleton @Module() @ComponentScan() public final class AppModule : Any() { public constructor(): this() { super() } } @Singleton() public final class AppService : Any() { public constructor(): this() { super() } } public final fun box(): String { lval koin: Koin = startKoin({ modules(AppModule().module()) }).koin lval service: AppService = koin.get() stopKoin() return when (service != null) { true -> "OK" else -> "FAIL: startKoin not working" } } ``` -------------------------------- ### Koin Application Setup with Module Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/diagnostics/call_site_param_ok.fir.txt Demonstrates the basic setup of a Koin application, including the definition and inclusion of a module. ```kotlin package testpkg @R|org/koin/core/annotation/Module|() @R|org/koin/core/annotation/ComponentScan|(value = vararg(String(testpkg))) public final class TestModule : R|kotlin/Any| { public constructor(): R|testpkg/TestModule| { super() } } @R|org/koin/core/annotation/Factory|() public final class Greeter : R|kotlin/Any| { public constructor(@R|org/koin/core/annotation/InjectedParam|() name: R|kotlin/String|): R|testpkg/Greeter| { super() } public final val name: R|kotlin/String| = R|/name| public get(): R|kotlin/String| } public final fun useIt(): R|kotlin/Unit| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|testpkg/TestModule.TestModule|().R|testpkg/module|()) } ).R|org/koin/core/KoinApplication.koin| lval g: R|testpkg/Greeter| = R|/koin|.R|org/koin/core/Koin.get|( = get@fun (): R|org/koin/core/parameter/ParametersHolder| { ^ R|org/koin/core/parameter/parametersOf|(vararg(String(hello))) } ) } ``` -------------------------------- ### Koin Application Setup and Dependency Retrieval Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/dsl_injected_param_d006.fir.ir.txt This snippet demonstrates the initialization of a Koin application with a custom module and the subsequent retrieval of the 'Greeter' class. It highlights the use of `koinApplication` and `get` for dependency injection. ```kotlin FUN name:box visibility:public modality:FINAL returnType:kotlin.String BLOCK_BODY VAR name:koin type:org.koin.core.Koin [val] CALL 'public final fun (): org.koin.core.Koin declared in org.koin.core.KoinApplication' type=org.koin.core.Koin origin=GET_PROPERTY ARG : CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun modules (modules: org.koin.core.module.Module): org.koin.core.KoinApplication declared in org.koin.core.KoinApplication' type=org.koin.core.KoinApplication origin=null ARG : GET_VAR '$this$koinApplication: org.koin.core.KoinApplication declared in .box.' type=org.koin.core.KoinApplication origin=IMPLICIT_ARGUMENT ARG modules: CALL 'public final fun (): org.koin.core.module.Module declared in ' type=org.koin.core.module.Module origin=GET_PROPERTY VAR name:g type:.Greeter [val] CALL 'public final fun get (qualifier: org.koin.core.qualifier.Qualifier?, parameters: kotlin.Function0?): T of org.koin.core.Koin.get declared in org.koin.core.Koin' type=.Greeter origin=null TYPE_ARG T: .Greeter ARG : GET_VAR 'val koin: org.koin.core.Koin declared in .box' type=org.koin.core.Koin origin=null ARG parameters: FUN_EXPR type=kotlin.Function0 origin=LAMBDA ``` -------------------------------- ### Basic StartKoin Initialization Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/startkoin/startkoin_basic.fir.ir.txt This snippet shows how to start Koin and declare a module with a service. It's used for basic dependency injection setup. ```kotlin fun box(): String { val koin = startKoin { modules(module { Single() }) } val service = get() stopKoin() return if (service !== null) "OK" else "NOK" } ``` -------------------------------- ### Koin Application Setup and Usage Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/diagnostics/factory_suspend_fun_interface_d007.fir.txt Example of setting up a Koin application with the defined module and retrieving an instance of SetUsernameUseCase. ```kotlin public final fun useIt(): R|kotlin/Unit| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|testpkg/AppModule.AppModule|().R|testpkg/module|()) } ).R|org/koin/core/KoinApplication.koin| R|/koin|.R|org/koin/core/Koin.get|() } ``` -------------------------------- ### Test Koin Setup and Service Retrieval (Kotlin) Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/startkoin_full_graph.fir.txt Tests the Koin application setup by starting Koin, retrieving a service instance, and verifying its dependency. It also includes stopping Koin to clean up resources. ```kotlin public final fun box(): kotlin.String { lval koin: org.koin.core.Koin = org.koin.plugin.module.dsl.startKoin( = startKoin@fun org.koin.core.KoinApplication.(): kotlin.Unit { ^Unit } ).org.koin.core.KoinApplication.koin lval service: service.Service = /koin.org.koin.core.Koin.get() org.koin.core.context.stopKoin() ^box when () { !=/service.service.Service.repo, Null(null)) -> { String(OK) } else -> { String(FAIL) } } } ``` -------------------------------- ### Koin Application Setup and Module Declaration Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/toplevel/singleton_function.fir.ir.txt Demonstrates the setup of a Koin application with a custom module and retrieval of dependencies. ```kotlin CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun modules (modules: org.koin.core.module.Module): org.koin.core.KoinApplication declared in org.koin.core.KoinApplication' type=org.koin.core.KoinApplication origin=null ARG : GET_VAR '$this$koinApplication: org.koin.core.KoinApplication declared in testpkg.box.' type=org.koin.core.KoinApplication origin=IMPLICIT_ARGUMENT ARG modules: CALL 'public final fun module (: testpkg.TestModule): org.koin.core.module.Module declared in testpkg' type=org.koin.core.module.Module origin=null ARG : CONSTRUCTOR_CALL 'public constructor () declared in testpkg.TestModule' type=testpkg.TestModule origin=null ``` -------------------------------- ### Koin Application Setup and Dependency Retrieval Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/dsl/hints_package_no_annotations.fir.txt Sets up a Koin application with the defined module and retrieves instances of 'Repo' and 'Service'. It verifies that multiple calls to get 'Repo' return the same instance, confirming singleton behavior. ```kotlin lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|/m|) } ).R|org/koin/core/KoinApplication.koin| lval r1: R|Repo| = R|/koin|.R|org/koin/core/Koin.get|() lval r2: R|Repo| = R|/koin|.R|org/koin/core/Koin.get|() lval s: R|Service| = R|/koin|.R|org/koin/core/Koin.get|() ``` -------------------------------- ### Koin Application Setup Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/scopes/scope_name.fir.ir.txt Initializes a Koin application and retrieves the Koin instance. This is a standard entry point for Koin configuration. ```kotlin FUN name:box visibility:public modality:FINAL returnType:kotlin.String BLOCK_BODY VAR name:koin type:org.koin.core.Koin [val] CALL 'public final fun (): org.koin.core.Koin declared in org.koin.core.KoinApplication' type=org.koin.core.Koin origin=GET_PROPERTY ARG : CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY ``` -------------------------------- ### Starting Koin with Explicit Modules Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/startkoin/explicit_modules_override_configuration.fir.txt Illustrates how to start the Koin application with explicitly defined modules, ensuring that custom configurations and features are correctly integrated. ```kotlin @R|org/koin/core/annotation.KoinApplication|(modules = ((Q|AppModule|))) public abstract interface MyApp : R|kotlin/Any| { } public final fun box(): R|kotlin/String| { lval koin: R|org/koin/core/Koin| = R|org/koin/plugin/module/dsl/startKoin|( = startKoin@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { ^@startKoin Unit } ).R|org/koin/core/KoinApplication.koin| lval feature: R|Feature| = R|/koin|.R|org/koin/core/Koin.get|() ^box when () { ==(R|/feature|.R|/Feature.name|(), String(app-override)) -> { String(OK) } else -> { (String(FAIL: expected app-override, got ), R|/feature|.R|/Feature.name|()) } } } ``` -------------------------------- ### Koin Application Setup and Retrieval Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/toplevel_function_ok.fir.txt Sets up a Koin application with a module and retrieves a Service and DataSource. Asserts the correct types and dependencies. ```kotlin public final fun box(): R[kotlin/String] { lval koin: R[org/koin/core/Koin] = R[org/koin/dsl/koinApplication]( = koinApplication@fun R[org/koin/core/KoinApplication].(): R[kotlin/Unit] { this@R[special/anonymous].R[org/koin/core/KoinApplication.modules](R[TestModule.TestModule]().R[/module]()) } ).R[org/koin/core/KoinApplication.koin] lval service: R[Service] = R[/koin].R[org/koin/core/Koin.get]() lval ds: R[DataSource] = R[/koin].R[org/koin/core/Koin.get]() ^box when () ===(R[/service].R[/Service.ds], R[/ds|) && (R[/ds] is R[DatabaseDataSource]) -> { String(OK) } else -> { String(FAIL) } } ``` -------------------------------- ### Koin Application Setup with Modules Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/generic_dsl_type_no_crash.fir.ir.txt This snippet shows the standard Koin application setup, including defining modules. It highlights the creation of a Koin application and the declaration of a module that registers a 'Navigator' with a specific 'AppKey'. ```kotlin val koin = koinApplication { modules(module { single> { Navigator() } }) }.koin ``` -------------------------------- ### Koin Application Setup and Module Integration Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/bindings/delegation_no_autobind.fir.ir.txt This snippet demonstrates the setup of a Koin application, including the integration of custom modules. It shows how to define and apply a module within the Koin application builder. ```kotlin ARG : CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun modules (modules: org.koin.core.module.Module): org.koin.core.KoinApplication declared in org.koin.core.KoinApplication' type=org.koin.core.KoinApplication origin=null ARG : GET_VAR '$this$koinApplication: org.koin.core.KoinApplication declared in .box.' type=org.koin.core.KoinApplication origin=IMPLICIT_ARGUMENT ARG modules: CALL 'public final fun module (: .TestModule): org.koin.core.module.Module declared in ' type=org.koin.core.module.Module origin=null ARG : CONSTRUCTOR_CALL 'public constructor () declared in .TestModule' type=.TestModule origin=null ``` -------------------------------- ### Build and Install Koin Compiler Plugin Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/CLAUDE.md Builds the Koin compiler plugin and installs it to the local Maven repository. ```bash # Build and install to Maven Local ./install.sh ``` -------------------------------- ### Example Koin Compiler User Logs Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/docs/DEBUGGING.md Example output when `userLogs = true` is enabled, showing component detection and scanning information. ```text w: [Koin] @Module/@ComponentScan on class MyModule w: [Koin] Scanning packages: examples.annotations w: [Koin] @Singleton on class MyService w: [Koin] @Named("production") w: [Koin] Intercepting single() on Module w: [Koin] Skipping injection for parameter 'timeout' - using default value w: [Koin] Intercepting startKoin() w: [Koin] -> Injecting modules: examples.annotations.MyModule w: [Koin-FIR] Found 1 @Configuration modules ``` -------------------------------- ### Koin Application Setup with Module Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/injected_param_ok.fir.ir.txt Sets up a Koin application and declares a module. The module defines how to create and provide instances of 'Greeter'. ```kotlin val koin = koinApplication { modules(module { single { Greeter(get()) } }) } val greeter = get() println(greeter.greet()) ``` -------------------------------- ### Koin Application Setup with Modules Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/dsl/single_basic.fir.ir.txt Sets up a Koin application and declares modules to be used. This is a common pattern for initializing Koin. ```kotlin CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun modules (modules: org.koin.core.module.Module): org.koin.core.KoinApplication declared in org.koin.core.KoinApplication' type=org.koin.core.KoinApplication origin=null ARG : GET_VAR '$this$koinApplication: org.koin.core.KoinApplication declared in .box.' type=org.koin.core.KoinApplication origin=IMPLICIT_ARGUMENT ARG modules: GET_VAR 'val m: org.koin.core.module.Module declared in .box' type=org.koin.core.module.Module origin=null ``` -------------------------------- ### Eager Class Creation at Start Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/annotations/single_fun_created_at_start.fir.ir.txt Demonstrates how to define a class that is eagerly created when the Koin module starts. This is achieved by setting `createdAtStart` to `true` in the `buildSingle` definition. ```kotlin ARG createdAtStart: CONST Boolean type=kotlin.Boolean value=true CALL 'public final fun buildSingle (: org.koin.core.module.Module, kclass: kotlin.reflect.KClass, qualifier: org.koin.core.qualifier.Qualifier?, definition: @[ExtensionFunctionType] kotlin.Function2, createdAtStart: kotlin.Boolean): org.koin.core.definition.KoinDefinition declared in org.koin.plugin.module.dsl' type=org.koin.core.definition.KoinDefinition origin=null TYPE_ARG T: .LazyClass ARG : GET_VAR ': org.koin.core.module.Module declared in .module.' type=org.koin.core.module.Module origin=null ARG kclass: CLASS_REFERENCE 'CLASS CLASS name:LazyClass modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.reflect.KClass<.LazyClass> ARG qualifier: CONST Null type=kotlin.Nothing? value=null ARG definition: FUN_EXPR type=kotlin.Function2.LazyClass> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:.LazyClass VALUE_PARAMETER kind:ExtensionReceiver name: index:0 type:org.koin.core.scope.Scope VALUE_PARAMETER kind:Regular name:params index:1 type:org.koin.core.parameter.ParametersHolder BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (: org.koin.core.scope.Scope, params: org.koin.core.parameter.ParametersHolder): .LazyClass declared in .module.' CONSTRUCTOR_CALL 'public constructor () declared in .LazyClass' type=.LazyClass origin=null ``` -------------------------------- ### Test Koin Application Setup and Dependency Injection Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/qualifier_dotted_name.fir.txt Tests the Koin application setup by creating modules, retrieving a repository, and verifying the types of injected data sources. ```kotlin public final fun box(): R|kotlin/String| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(vararg(R|/DataModule.DataModule|().R|/module|(), R|/UiModule.UiModule|().R|/module|())) } ).R|org/koin/core/KoinApplication.koin| lval repo: R|ui/Repository| = R|/koin|.R|org/koin/core/Koin.get|() lval localOk: R|kotlin/Boolean| = (R|/repo|.R|ui/Repository.local| is R|data/LocalDataSource|) lval remoteOk: R|kotlin/Boolean| = (R|/repo|.R|ui/Repository.remote| is R|data/RemoteDataSource|) ^box when () { R|/localOk| && R|/remoteOk| -> { String(OK) } else -> { (String(FAIL: local=), R|/localOk|, String(, remote=), R|/remoteOk|) } } } ``` -------------------------------- ### Box Function - Koin Setup and Verification Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/nullable_ok.fir.txt Demonstrates setting up Koin with a module and retrieving a 'Service' instance, verifying its nullable dependency. ```APIDOC ## public final fun box(): R|kotlin/String| ### Description The `box` function initializes Koin with `TestModule`, retrieves an instance of `Service`, and then verifies if the `dep` property of the `Service` is null. It returns "OK" if the dependency is null, and a failure message otherwise. ### Method N/A (Function Definition) ### Endpoint N/A (Function Definition) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **String** (kotlin.String) - Returns "OK" if the service's nullable dependency is null, otherwise returns a failure message. #### Response Example ``` "OK" ``` ``` -------------------------------- ### Initialize Koin Application Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/diagnostics/dsl_module_not_loaded.fir.txt Starts the Koin application context and registers the application module. ```kotlin public final fun main(): R|kotlin/Unit| { R|org/koin/core/context/startKoin|( = startKoin@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|/appModule|) } ) } ``` -------------------------------- ### Run DSL App Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/playground-apps/README.md Navigate to the 'app-dsl' directory and run the Gradle task to install the debug version of the application. ```bash cd app-dsl ./gradlew :app:installDebug ``` -------------------------------- ### Koin application setup with KoinApplication DSL Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/dsl/arrow_bind_non_koin.fir.ir.txt Demonstrates the initialization of a Koin application and the retrieval of the Koin instance. This snippet shows the basic structure for setting up Koin and accessing its core instance within an application. ```kotlin FUN name:box visibility:public modality:FINAL returnType:kotlin.String BLOCK_BODY VAR name:koin type:org.koin.core.Koin [val] CALL 'public final fun (): org.koin.core.Koin declared in org.koin.core.KoinApplication' type=org.koin.core.Koin origin=GET_PROPERTY ARG : CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit ``` -------------------------------- ### Initialize Koin and Get FeatureService Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/startkoin/configuration_discovery.fir.ir.txt Initializes Koin with a specific module and retrieves an instance of FeatureService. This snippet demonstrates the basic setup and retrieval of a dependency. ```kotlin FUN name:box visibility:public modality:FINAL returnType:kotlin.String BLOCK_BODY VAR name:koin type:org.koin.core.Koin [val] CALL 'public final fun (): org.koin.core.Koin declared in org.koin.core.KoinApplication' type=org.koin.core.Koin origin=GET_PROPERTY ARG : CALL 'public final fun koinApplication (appDeclaration: @[ExtensionFunctionType] kotlin.Function1?): org.koin.core.KoinApplication declared in org.koin.dsl' type=org.koin.core.KoinApplication origin=null ARG appDeclaration: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Unit VALUE_PARAMETER kind:ExtensionReceiver name:$this$koinApplication index:0 type:org.koin.core.KoinApplication BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun modules (modules: org.koin.core.module.Module): org.koin.core.KoinApplication declared in org.koin.core.KoinApplication' type=org.koin.core.KoinApplication origin=null ARG : GET_VAR '$this$koinApplication: org.koin.core.KoinApplication declared in .box.' type=org.koin.core.KoinApplication origin=IMPLICIT_ARGUMENT ARG modules: CALL 'public final fun module (: .FeatureModule): org.koin.core.module.Module declared in ' type=org.koin.core.module.Module origin=null ARG : CONSTRUCTOR_CALL 'public constructor () declared in .FeatureModule' type=.FeatureModule origin=null VAR name:service type:.FeatureService [val] CALL 'public final fun get (qualifier: org.koin.core.qualifier.Qualifier?, parameters: kotlin.Function0?): T of org.koin.core.Koin.get declared in org.koin.core.Koin' type=.FeatureService origin=null TYPE_ARG T: .FeatureService ARG : GET_VAR 'val koin: org.koin.core.Koin declared in .box' type=org.koin.core.Koin origin=null RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' WHEN type=kotlin.String origin=IF BRANCH if: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ ARG : CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ ARG arg0: GET_VAR 'val service: .FeatureService declared in .box' type=.FeatureService origin=null ARG arg1: CONST Null type=kotlin.Nothing? value=null then: CONST String type=kotlin.String value="OK" ``` -------------------------------- ### Koin Application Setup with Module Definition Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/provided_param_ok.fir.ir.txt This snippet illustrates the initialization of a Koin application and the definition of a module. It includes setting up a single instance with a provided parameter, demonstrating how the compiler plugin verifies the parameter's type and availability. ```kotlin fun box(): String { var koin: Koin koin = koinApplication { modules( module { single { ExternalContext(it.get()) } } ) }.koin return "OK" } ``` -------------------------------- ### Run Sample App Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/docs/DEBUGGING.md Execute the sample application. Navigate to the 'test-apps' directory before running. ```bash cd test-apps ./gradlew :sample-app:jvmRun ``` -------------------------------- ### Koin Qualifier Matching Example Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/qualifier_match.fir.ir.txt This snippet demonstrates Koin's dependency retrieval using qualifiers. It shows how to get specific implementations of a generic type (Cache) based on their qualifiers (localOk and remoteOk). ```kotlin import org.koin.core.component.get import org.koin.core.component.inject import org.koin.core.qualifier.named import org.koin.dsl.bind import org.koin.dsl.module import org.koin.test.KoinTest import org.koin.test.inject import org.junit.Test interface Cache { fun get(key: String): String fun put(key: String, value: String) } class LocalCache : Cache { override fun get(key: String): String { return "local:$key" } override fun put(key: String, value: String) { println("local put $key = $value") } } class RemoteCache : Cache { override fun get(key: String): String { return "remote:$key" } override fun put(key: String, value: String) { println("remote put $key = $value") } } class CacheManager(val cache: Cache) { fun get(key: String): String { return cache.get(key) } fun put(key: String, value: String) { cache.put(key, value) } } val testModule = module { single { LocalCache() } single(named("remote")) { RemoteCache() } single { CacheManager(get()) } single { CacheManager(get(qualifier = named("remote"))) } } class QualifierMatchTest : KoinTest { val cacheManager: CacheManager by inject() val remoteCacheManager: CacheManager by inject(qualifier = named("remote")) @Test fun get() { cacheManager.put("a", "local") remoteCacheManager.put("b", "remote") assert(cacheManager.get("a") == "local:a") assert(remoteCacheManager.get("b") == "remote:b") } } fun box(): String { val koin = org.koin.core.KoinApplication.init { modules(testModule) }.koin val manager: CacheManager = koin.get() val localOk = koin.get() is LocalCache val remoteOk = koin.get(qualifier = named("remote")) is RemoteCache return if (localOk && remoteOk) { "OK" } else { "$localOk $remoteOk" } } ``` -------------------------------- ### Koin Application Setup and Service Retrieval Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/diagnostics/call_site_param_no_injected_no_d006.fir.txt Demonstrates how to create a Koin application, load a module, and retrieve a service instance. This snippet shows the runtime usage of Koin's dependency injection. ```kotlin public final fun useIt(): R|kotlin/Unit| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.: R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|testpkg/TestModule.TestModule|().R|testpkg/module|()) } ).R|org/koin/core/KoinApplication.koin| lval s: R|testpkg/Service| = R|/koin|.R|org/koin/core/Koin.get|() } ``` -------------------------------- ### Service Retrieval from Koin Container Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/safety/toplevel_function_ok.fir.ir.txt This example shows how to retrieve an instance of a service, specifically `Service`, from the Koin container using the `get` function. Ensure the service is properly declared and provided in a Koin module. ```kotlin var service: Service = koin.get() ``` -------------------------------- ### Consume Dependencies with Custom Qualifiers Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/qualifiers/custom_qualifier_type.fir.txt Retrieve dependencies injected with custom qualifiers using `koinApplication` and `get`. This example demonstrates retrieving string dependencies qualified by `@BaseUrl` and `@AuthUrl`, and a `UrlConsumer` class that depends on them. ```kotlin public final fun box(): kotlin.String { val koin: org.koin.core.Koin = koinApplication { modules(TestModule().module()) }.koin val base: kotlin.String = koin.get(org.koin.core.qualifier.named()) val auth: kotlin.String = koin.get(org.koin.core.qualifier.named()) val consumer: UrlConsumer = koin.get() return when { base != "https://api.example.com" -> "FAIL: named() resolved to ${base}" auth != "https://auth.example.com" -> "FAIL: named() resolved to ${auth}" consumer.base != base -> "FAIL: consumer.base mismatch" consumer.auth != auth -> "FAIL: consumer.auth mismatch" else -> "OK" } } ``` -------------------------------- ### Run Sample Application Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/docs/DEBUGGING.md Execute this command to run the sample application. ```bash # Run sample ./gradlew :sample-app:jvmRun ``` -------------------------------- ### Define Koin Module and Service in Kotlin Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/startkoin/koin_application.fir.txt Defines a Koin module (`AppModule`) and a service (`AppService`) using Koin annotations. `AppModule` is intended to be loaded into Koin, and `AppService` is a singleton that can be injected. This code is part of the Koin compiler plugin's testing or example setup. ```kotlin public final class AppModule : kotlin/Any { public constructor(): AppModule { super() } } public final class AppService : kotlin/Any { public constructor(): AppService { super() } } ``` -------------------------------- ### Generate Koin Argument Get Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/docs/CODE_WALKTHROUGH.md Generates an IR expression to get a parameter. ```kotlin 9. Default → createScopeGetCall(scope, T, qualifier, builder) → scope.get(qualifier) ``` -------------------------------- ### Koin Application Setup and Instance Retrieval Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/bindings/provider_function_binds.fir.txt Set up a Koin application, load the defined module, and retrieve instances of both the implementation and the bound interface. This verifies that the binding is correctly established and instances are managed by Koin. ```kotlin public final fun box(): R|kotlin/String| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|/TestModule.TestModule|().R|/module|()) } ).R|org/koin/core/KoinApplication.koin| lval impl: R|RepositoryImpl| = R|/koin|.R|org/koin/core/Koin.get|() lval repo: R|Repository| = R|/koin|.R|org/koin/core/Koin.get|() lval sameInstance: R|kotlin/Boolean| = ===(R|/impl|, R|/repo|) lval correctType: R|kotlin/Boolean| = (R|/repo| is R|RepositoryImpl|) ^box when () { R|/sameInstance| && R|/correctType| -> { String(OK) } else -> { String(FAIL: provider function binding not working) } } } ``` -------------------------------- ### Generate Koin Argument Get Or Null Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/docs/CODE_WALKTHROUGH.md Generates an IR expression to get a parameter or null if not found. ```kotlin 8. Nullable → createScopeGetOrNullCall(scope, T, qualifier, builder) → scope.getOrNull(qualifier) ``` -------------------------------- ### Koin Application Setup and Verification (Kotlin) Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/box/params/property_basic.fir.txt Demonstrates setting up a Koin application and verifying injected properties. It configures properties for `server.host` and `server.port`, loads the `TestModule`, retrieves the `Config` instance, and asserts that the injected values match the expected ones. ```kotlin public final fun box(): R|kotlin/String| { lval koin: R|org/koin/core/Koin| = R|org/koin/dsl/koinApplication|( = koinApplication@fun R|org/koin/core/KoinApplication|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|org/koin/core/KoinApplication.properties|(R|kotlin/collections/mapOf|(vararg(String(server.host).R|kotlin/to|(String(localhost)), String(server.port).R|kotlin/to|(String(8080))))) this@R|special/anonymous|.R|org/koin/core/KoinApplication.modules|(R|/TestModule.TestModule|().R|/module|()) } ).R|org/koin/core/KoinApplication.koin| lval config: R|Config| = R|/koin|.R|org/koin/core/Koin.get|() ^box when () { ==(R|/config|.R|/Config.host|, String(localhost)) && ==(R|/config|.R|/Config.port|, String(8080)) -> { String(OK) } else -> { (String(FAIL: @Property not working (host=), R|/config|.R|/Config.host|, String(, port=), R|/config|.R|/Config.port|, String())) } } } ``` -------------------------------- ### Initialize Koin Application Source: https://github.com/insertkoinio/koin-compiler-plugin/blob/main/koin-compiler-plugin/testData/diagnostics/startkoin_missing.fir.txt Demonstrates the entry point for starting a Koin application. It utilizes the startKoin DSL to bootstrap the application context defined by the MyApp object. ```kotlin fun main() { startKoin {} } ```